Closed cervengoc closed 9 years ago
@cervengoc My first thought is that that mucking with the array change subscriptions will cause the arrayChange
events to not fire correctly.
What happens if you clear the array and push the elements without keeping the array silent?
Wooh I think I've found the issue, and it came with my code. It looks like ko is sending the same arrayChange items to every subscriber, so when I manipulate it to create a batch addition, then I manipulate the same instance at every binding. I'm gonna fix it soon, and I'll try to put together a test for this use case, at most tomorrow.
@cervengoc – Are you up for putting a PR in for this?
I've actually already done it. I even wondered why you didn't react. Probably I missed something, I'll check later today when I'm at computer. Please see my fork till then.
See this fiddle: http://jsfiddle.net/48hrb9cj/5/
I implemented a method called
refill
for observable arrays. This method clears the array and pushes all the given elements into it while keeping the array silent (valueWillMutate/valueHasMutated).Consider the following circumstances:
In this scenario something goes crazy, I can see that always the last number which I pushed to the array (number 2 in example) gets repeated, and number or repetitions = number of usages of fastforEach binding on the same data (3 times in the example).
Hope you can find it out, I was looking at the code for half an hour without any idea.
(I copied the latest source code for simplicity.)