Comparing version 0.0.14 to 0.0.15
34
diff.js
@@ -20,8 +20,8 @@ var isArray = require("x-is-array") | ||
function walk(a, b, patch, index) { | ||
var nodes = handleThunk(a, b); | ||
a = nodes.a | ||
b = nodes.b | ||
if (a === b) { | ||
hooks(b, patch, index) | ||
if (isThunk(a) || isThunk(b)) { | ||
thunks(a, b, patch, index) | ||
} else { | ||
hooks(b, patch, index) | ||
} | ||
return | ||
@@ -35,2 +35,4 @@ } | ||
destroyWidgets(a, patch, index) | ||
} else if (isThunk(a) || isThunk(b)) { | ||
thunks(a, b, patch, index) | ||
} else if (isVNode(b)) { | ||
@@ -146,3 +148,4 @@ if (isVNode(a)) { | ||
// Excess nodes in b need to be added | ||
apply = appendPatch(apply, new VPatch(VPatch.INSERT, null, rightNode)) | ||
apply = appendPatch(apply, | ||
new VPatch(VPatch.INSERT, null, rightNode)) | ||
} | ||
@@ -195,2 +198,21 @@ } else if (!rightNode) { | ||
// Create a sub-patch for thunks | ||
function thunks(a, b, patch, index) { | ||
var nodes = handleThunk(a, b); | ||
var thunkPatch = diff(nodes.a, nodes.b) | ||
if (hasPatches(thunkPatch)) { | ||
patch[index] = new VPatch(VPatch.THUNK, null, thunkPatch) | ||
} | ||
} | ||
function hasPatches(patch) { | ||
for (var index in patch) { | ||
if (index !== "a") { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
// Execute hooks when two nodes are identical | ||
@@ -197,0 +219,0 @@ function hooks(vNode, patch, index) { |
@@ -1,5 +0,5 @@ | ||
var isVNode = require('./is-vnode') | ||
var isVText = require('./is-vtext') | ||
var isWidget = require('./is-widget') | ||
var isThunk = require('./is-thunk') | ||
var isVNode = require("./is-vnode") | ||
var isVText = require("./is-vtext") | ||
var isWidget = require("./is-widget") | ||
var isThunk = require("./is-thunk") | ||
@@ -6,0 +6,0 @@ module.exports = handleThunk |
{ | ||
"name": "vtree", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "a realtime tree diffing algorithm", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -11,2 +11,3 @@ var version = require("./version") | ||
VirtualPatch.REMOVE = 7 | ||
VirtualPatch.THUNK = 8 | ||
@@ -13,0 +14,0 @@ module.exports = VirtualPatch |
20176
554