Closed albertogasparin closed 8 years ago
Hi Alberto,
When you do arrayA.splice(0, 1)
you are updating the array in the freezer state and a new array is created inside freezer for that update, but arrayA
is immutable, it doesn't change at all. After calling the first splice
, arrayA
is not in freezer anymore, so the second splice
doesn't modify it.
You need to update the reference to the array in the freezer store:
arrayA = arrayA.splice(0, 1);
arrayA.splice(1, 0, firstA);
Thanks for the quick reply. By better reading the docs I've found the statement where you explain this behaviour. I forgot that the methods, despite having the same name, behave differently from native ones. Cheers :+1:
It looks like if you are manipulating an array with
splice()
, you might get the wrong result. Here I'm trying to move one item from position 0 to 1I've also created a demo to replicate the issue. The code works as expected with native
splice()
.