Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

can.Observe.List.prototype.replace - keep the same values from removing and re-adding

$
0
0
  1. var list = new can.Observe.List([2, 3, 4]);
  2. list.bind('change', function(ev, index, how, newVals, oldVals) {
  3.     console.log(index + ', ' + how + ', ' + newVals + ', ' + oldVals);
  4. });
  5. list.replace([2, 5, 7]);
which prints
  1. 0, remove, undefined, 2,3,4
  2. 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.

Viewing all articles
Browse latest Browse all 3491

Trending Articles