- var list = new can.Observe.List([2, 3, 4]);
- list.bind('change', function(ev, index, how, newVals, oldVals) {
- console.log(index + ', ' + how + ', ' + newVals + ', ' + oldVals);
- });
- list.replace([2, 5, 7]);
which prints
- 0, remove, undefined, 2,3,4
- 0, add, 2,5,7, 2,3,4
What is the reason to remove "2" from the list and add it again? Wouldn't it be more efficient to keep it?
Background: I use can.Observe.List for storing google maps markers which are visible in current viewport. When user moves the map, I want to remove markers which aren't in viewport and I want to add new visible markers to the list. Most of the markers stay in the viewport and only a few are removed and a few new are added. Most of the markers stay the same. With current replace function, I can see that markers are removed from the map and then re-created again.