Skip to content

Commit

Permalink
⚡ perf boost: handle case when there are no children and remove all o…
Browse files Browse the repository at this point in the history
…f them
  • Loading branch information
kbrsh committed Mar 29, 2017
1 parent 339cabe commit 577fe98
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
18 changes: 14 additions & 4 deletions dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,10 +767,20 @@
newText.meta.el = node.firstChild;
}
} else {
// Just Iterate through All Children
var totalLen = newLength > oldLength ? newLength : oldLength;
for (var i = 0; i < totalLen; i++) {
diff(oldVNode.children[i], vnode.children[i], node, instance);
if (newLength === 0) {
// No Children, Remove all Children if not Already Removed
if (oldLength !== 0) {
var firstChild = null;
while (firstChild = node.firstChild) {
removeChild(firstChild, node);
}
}
} else {
// Traverse and Diff Children
var totalLen = newLength > oldLength ? newLength : oldLength;
for (var i = 0; i < totalLen; i++) {
diff(oldVNode.children[i], vnode.children[i], node, instance);
}
}
}

Expand Down
Loading

0 comments on commit 577fe98

Please sign in to comment.