Skip to content

Commit

Permalink
perf: optimize hydration to use less loops
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Jul 20, 2017
1 parent e0690f4 commit 5c66f8c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 35 deletions.
30 changes: 13 additions & 17 deletions dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,28 +788,24 @@
var i = 0;
var currentChildNode = node.firstChild;
var vchild = length !== 0 ? children[0] : null;
var nextSibling = null;

while(vchild !== null || currentChildNode !== null) {
if(vchild === null) {
var nextSibling = null;
do {
nextSibling = currentChildNode.nextSibling;
nextSibling = null;

if(currentChildNode === null) {
appendChild(createNodeFromVNode(vchild), vchild, node);
} else {
nextSibling = currentChildNode.nextSibling;
if(vchild === null) {
removeChild(currentChildNode, node);
currentChildNode = nextSibling;
} while(currentChildNode !== null);
currentChildNode = null;
} else if(currentChildNode === null) {
for(; i < children.length; i++) {
vchild = children[i];
appendChild(createNodeFromVNode(vchild), vchild, node);
} else {
hydrate(currentChildNode, vchild, node);
}
vchild = null;
} else {
var next = currentChildNode.nextSibling;
hydrate(currentChildNode, vchild, node);
vchild = ++i < length ? children[i] : null;
currentChildNode = next;
}

vchild = ++i < length ? children[i] : null;
currentChildNode = nextSibling;
}
}
return node;
Expand Down
Loading

0 comments on commit 5c66f8c

Please sign in to comment.