Skip to content

Commit

Permalink
specific cases for slight perf boost in hydration
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Apr 4, 2017
1 parent 48395ed commit c05a0bc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,13 +609,13 @@
var hydrate = function (node, vnode, parent, instance) {
var nodeName = node ? node.nodeName.toLowerCase() : null;

if (!node) {
if (node === null) {
// No node, create one
var newNode = createNodeFromVNode(vnode, instance);
appendChild(newNode, vnode, parent);

return newNode;
} else if (!vnode) {
} else if (vnode === undefined) {
removeChild(node, parent);

return null;
Expand All @@ -624,7 +624,7 @@
replaceChild(node, newNode, vnode, parent);
return newNode;
} else if (vnode.type === "#text") {
if (node && nodeName === "#text") {
if (node !== null && nodeName === "#text") {
// Both are textnodes, update the node
if (node.textContent !== vnode.val) {
node.textContent = vnode.val;
Expand All @@ -643,7 +643,7 @@
vnode.meta.el = node;

// Check for Component
if (vnode.meta.component) {
if (vnode.meta.component !== undefined) {
// Diff the Component
diffComponent(node, vnode);

Expand All @@ -658,15 +658,15 @@
addEventListeners(node, vnode, instance);

// Check if innerHTML was changed, and don't diff children if so
if (vnode.props.dom && vnode.props.dom.innerHTML) {
if (vnode.props.dom !== undefined && vnode.props.dom.innerHTML !== undefined) {
return node;
}

// Hydrate Children
var i = 0;
var currentChildNode = node.firstChild;
var vchild = vnode.children[i];
while (vchild || currentChildNode) {
while (vchild !== undefined || currentChildNode !== null) {
hydrate(currentChildNode, vchild, node, instance);
vchild = vnode.children[++i];
currentChildNode = currentChildNode ? currentChildNode.nextSibling : null;
Expand Down
Loading

0 comments on commit c05a0bc

Please sign in to comment.