Skip to content

Commit

Permalink
first part of implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Jan 23, 2017
1 parent 102b1a7 commit f3f8f45
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,38 @@ function updateChildren (newNode, oldNode) {
var oldLength = oldNode.childNodes.length
var length = Math.max(oldLength, newLength)

var iNew = 0
var iOld = 0
for (var i = 0; i < length; i++, iNew++, iOld++) {
for (var i = 0, iNew = 0, iOld = 0; i < length; i++, iNew++, iOld++) {
var newChildNode = newNode.childNodes[iNew]
var oldChildNode = oldNode.childNodes[iOld]
var retChildNode = walk(newChildNode, oldChildNode)
if (!retChildNode) {
if (oldChildNode) {
oldNode.removeChild(oldChildNode)
iOld--
}
} else if (!oldChildNode) {
if (retChildNode) {
oldNode.appendChild(retChildNode)

if (newChildNode) {
var newAttrs = newChildNode.attributes
if (newAttrs) var newKey = newAttrs['data-key']
}

if (oldChildNode) {
var oldAttrs = oldChildNode.attributes
if (oldAttrs) var oldKey = oldAttrs['data-key']
}

if (newKey || oldKey) {
console.log(newKey, oldKey)
} else {
var morphedNode = walk(newChildNode, oldChildNode)
if (!morphedNode) {
if (oldChildNode) {
oldNode.removeChild(oldChildNode)
iOld--
}
} else if (!oldChildNode) {
if (morphedNode) {
oldNode.appendChild(morphedNode)
iNew--
}
} else if (morphedNode !== oldChildNode) {
oldNode.replaceChild(morphedNode, oldChildNode)
iNew--
}
} else if (retChildNode !== oldChildNode) {
oldNode.replaceChild(retChildNode, oldChildNode)
iNew--
}
}
}

0 comments on commit f3f8f45

Please sign in to comment.