CanJS 2.2.4 can.List.replace() incorrect behavior #1606

Closed
Origami30 opened this Issue Apr 6, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@Origami30

CanJS Version: 2.2.4
JQuery 2.1.1
Short description: When you replace existing can.List with new one and if this new array is equal to the existing can.List from the beginning to the end of new array then can.List will not be replaced.
Example (copy-paste from Chrome console):

var ll = new can.List(["aa","bb","cc"]);
undefined
ll
["aa", "bb", "cc"]
ll.replace(["aa","bb"]);
["aa", "bb", "cc"] // ??? shouldn't it be ["aa", "bb"]?
ll
["aa", "bb", "cc"] // check once again
ll.replace(["aa","bb","cc","dd"]); // take the same array with one extra element
["aa", "bb", "cc", "dd"] // OK
ll
["aa", "bb", "cc", "dd"] // Re-check
ll.replace(["aa","bb"]);
["aa", "bb", "cc", "dd"] // ??? shouldn't it be ["aa", "bb"]?
ll
["aa", "bb", "cc", "dd"]
ll.replace(["aa","xx"]);
["aa", "xx"]
ll
["aa", "xx"]
ll.replace([]); // With empty array it works
[]
ll
[]

PS! CanJS 2.1.4 was not affected by this issue

@daffl daffl added the bug label Apr 7, 2015

@daffl

This comment has been minimized.

Show comment
Hide comment
@daffl

daffl Apr 7, 2015

Contributor

That is odd since .replace just runs this.splice.apply(this, [0, this.length].concat(can.makeArray(newList || []))); (see https://github.com/bitovi/canjs/blob/master/list/list.js#L1096).
It seems to not detect the changes properly. If I do ll.replace(["aa", "something"]) it works as expected.

Contributor

daffl commented Apr 7, 2015

That is odd since .replace just runs this.splice.apply(this, [0, this.length].concat(can.makeArray(newList || []))); (see https://github.com/bitovi/canjs/blob/master/list/list.js#L1096).
It seems to not detect the changes properly. If I do ll.replace(["aa", "something"]) it works as expected.

@daffl daffl added this to the 2.2.5 milestone Apr 10, 2015

daffl added a commit that referenced this issue Apr 21, 2015

Test and fix for issue with can.List.prototype.splice assuming added …
…items are the same even if the length is different (#1606).

daffl added a commit that referenced this issue Apr 21, 2015

Test and fix for issue with can.List.prototype.splice assuming added …
…items are the same even if the length is different (#1606).

@daffl daffl closed this in #1635 Apr 21, 2015

daffl added a commit that referenced this issue May 1, 2015

Test and fix for issue with can.List.prototype.splice assuming added …
…items are the same even if the length is different (#1606).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment