-
Notifications
You must be signed in to change notification settings - Fork 21
Description
This is by design, so not an actual bug. But it's probably worth mentioning in the docs since it's unexpected:
If you splice an item out of an Array, the diff won't actually do the same thing. Rather, it will modify every element after the removed one in place, and then pop items off the end of the Array to get the length right.
So if you do:
[1,2,3,4,5] -> [1,3,4,5]
It'll actually do the diff as:
[1,2,3,4,5] -> [1, 2->3, 3->4, 4->5, 5].pop()
That's cool, since it makes implementation a lot easier, but it's unexpected. So if your element contains things like DOM references that aren't completely visible to the diff, you may spend some time wondering why everything comes out scrambled until you dig in and see what's going on.
In my case, I added a bunch of extra information to the visitorCallback method, and ensured it fired for deletions as well as updates, so that I could nudge the process along. As in:
visitorCallback("beforedelete", val, path, keys[i], "delete");
Anyway, great little library. Does what it says on the tin in 250 lines. Thanks for saving me a couple days of work!