Skip to content

Commit

Permalink
correctly diff removing children by using a seperate counter for old …
Browse files Browse the repository at this point in the history
…children
  • Loading branch information
kbrsh committed May 3, 2017
1 parent abd312d commit 4b919af
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,8 @@
} else {
// Traverse and Diff Children
var totalLen = newLength > oldLength ? newLength : oldLength;
for (var i = 0; i < totalLen; i++) {
var oldChild = i < oldLength ? oldChildren[i] : null;
for (var i = 0, j = 0; i < totalLen; i++, j++) {
var oldChild = j < oldLength ? oldChildren[j] : null;
var child = i < newLength ? children[i] : null;

var action = diff(oldChild, child, _node, instance);
Expand All @@ -884,11 +884,11 @@
oldChildren[oldLength++] = child;
break;
case PATCH.REMOVE:
oldChildren.splice(i, 1);
oldChildren.splice(j--, 1);
oldLength--;
break;
case PATCH.REPLACE:
oldChildren[i] = children[i];
oldChildren[j] = children[i];
break;
case PATCH.TEXT:
oldChild.val = child.val;
Expand Down
Loading

0 comments on commit 4b919af

Please sign in to comment.