Skip to content

Commit

Permalink
Change setDomNodeChildrenFromArrayMapping to remove nodes before doin…
Browse files Browse the repository at this point in the history
…g add/reorder to match 2.1.0 behavior.
  • Loading branch information
mbest committed Oct 9, 2012
1 parent c96b99e commit e8b6663
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/binding/editDetection/arrayToDomNodeChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@
// Call beforeMove first before any changes have been made to the DOM
callCallback(options['beforeMove'], itemsForMoveCallbacks);

// Next remove nodes for deleted items (or just clean if there's a beforeRemove callback)
ko.utils.arrayForEach(nodesToDelete, options['beforeRemove'] ? ko.cleanNode : ko.removeNode);

// Next add/reorder the remaining items (will include deleted items if there's a beforeRemove callback)
for (var i = 0, nextNode = ko.virtualElements.firstChild(domNode), lastNode, node; mapData = itemsToProcess[i]; i++) {
// Get nodes for newly added items
Expand All @@ -174,8 +177,11 @@
}
}

// Next remove nodes for deleted items; or call beforeRemove, which will remove them
ko.utils.arrayForEach(nodesToDelete, options['beforeRemove'] ? ko.cleanNode : ko.removeNode);
// If there's a beforeRemove callback, call it after reordering.
// Note that we assume that the beforeRemove callback will usually be used to remove the nodes using
// some sort of animation, which is why we first reorder the nodes that will be removed. If the
// callback instead removes the nodes right away, it would be more efficient to skip reordering them.
// Perhaps we'll make that change in the future if this scenario becomes more common.
callCallback(options['beforeRemove'], itemsForBeforeRemoveCallbacks);

// Finally call afterMove and afterAdd callbacks
Expand Down

0 comments on commit e8b6663

Please sign in to comment.