virtual-dom
Advanced tools
Comparing version 0.0.6 to 0.0.7
{ | ||
"name": "virtual-dom", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "A batched diff-based DOM rendering strategy", | ||
@@ -21,3 +21,3 @@ "keywords": [], | ||
"browser-split": "0.0.1", | ||
"global": "^3.0.1", | ||
"global": "^3.0.2", | ||
"is-object": "^0.1.2", | ||
@@ -28,3 +28,3 @@ "x-is-array": "^0.1.0", | ||
"devDependencies": { | ||
"min-document": "^2.3.0", | ||
"min-document": "^2.6.1", | ||
"run-browser": "git://github.com/Raynos/run-browser", | ||
@@ -31,0 +31,0 @@ "tap-dot": "^0.2.1", |
@@ -60,3 +60,3 @@ var test = require("tape") | ||
test("mix keys without keys", function (assert) { | ||
var leftNode = h("div", [ | ||
var leftNode = h("div", [ | ||
h("div", { key: 1 }), | ||
@@ -84,8 +84,4 @@ h("div"), | ||
var rootNode = render(leftNode) | ||
var childNodes = childNodesArray(rootNode) | ||
var childNodes = [] | ||
for (var i = 0; i < rootNode.childNodes.length; i++) { | ||
childNodes.push(rootNode.childNodes[i]) | ||
} | ||
var patches = diff(leftNode, rightNode) | ||
@@ -112,3 +108,3 @@ assert.equal(patchCount(patches), 1) | ||
test("missing key gets replaced", function (assert) { | ||
var leftNode = h("div", [ | ||
var leftNode = h("div", [ | ||
h("div", { key: 1 }), | ||
@@ -190,9 +186,5 @@ h("div"), | ||
var rootNode = render(leftNode) | ||
var childNodes = childNodesArray(rootNode) | ||
var childNodes = [] | ||
for (var i = 0; i < rootNode.childNodes.length; i++) { | ||
childNodes.push(rootNode.childNodes[i]) | ||
} | ||
var patches = diff(leftNode, rightNode) | ||
@@ -211,1 +203,38 @@ assert.equal(patchCount(patches), 4) // 1 reorder and 3 update patches | ||
}) | ||
test("delete key at the start", function (assert) { | ||
var leftNode = h("div", [ | ||
h("div", { key: "a" }, "a"), | ||
h("div", { key: "b" }, "b"), | ||
h("div", { key: "c" }, "c") | ||
]) | ||
var rightNode = h("div", [ | ||
h("div", { key: "b" }, "b"), | ||
h("div", { key: "c" }, "c") | ||
]) | ||
var rootNode = render(leftNode) | ||
var childNodes = childNodesArray(rootNode) | ||
var patches = diff(leftNode, rightNode) | ||
assert.equal(patchCount(patches), 2) | ||
var newRoot = patch(rootNode, patches) | ||
assert.equal(newRoot, rootNode) | ||
assert.equal(newRoot.childNodes.length, 2) | ||
assert.equal(newRoot.childNodes[0], childNodes[1]) | ||
assert.equal(newRoot.childNodes[1], childNodes[2]) | ||
assert.end() | ||
}) | ||
function childNodesArray(node) { | ||
var childNodes = [] | ||
for (var i = 0; i < node.childNodes.length; i++) { | ||
childNodes.push(node.childNodes[i]) | ||
} | ||
return childNodes | ||
} |
@@ -130,3 +130,2 @@ var applyProperties = require("./apply-properties") | ||
var node = children[move] | ||
domNode.removeChild(node) | ||
domNode.insertBefore(node, childNodes[i]) | ||
@@ -133,0 +132,0 @@ } |
@@ -128,3 +128,3 @@ var isArray = require("x-is-array") | ||
aChildren = reorder(aChildren, bChildren, len) | ||
bChildren = reorder(aChildren, bChildren, len) | ||
@@ -156,5 +156,5 @@ for (var i = 0; i < len; i++) { | ||
if (aChildren.moves) { | ||
if (bChildren.moves) { | ||
// Reorder nodes last | ||
apply = appendPatch(apply, new VPatch(VPatch.ORDER, a, aChildren.moves)) | ||
apply = appendPatch(apply, new VPatch(VPatch.ORDER, a, bChildren.moves)) | ||
} | ||
@@ -214,49 +214,49 @@ | ||
function reorder(aChildren, bChildren, len) { | ||
var bKeys = keyIndex(bChildren) | ||
if (!bKeys) { | ||
return bChildren | ||
} | ||
var aKeys = keyIndex(aChildren) | ||
if (!aKeys) { | ||
return aChildren | ||
return bChildren | ||
} | ||
var bKeys = keyIndex(bChildren) | ||
var bMatch = {}, aMatch = {} | ||
if (!bKeys) { | ||
return aChildren | ||
for (var key in bKeys) { | ||
bMatch[bKeys[key]] = aKeys[key] | ||
} | ||
var aMatch, bMatch | ||
for (var key in aKeys) { | ||
if (key in bKeys) { | ||
if (!aMatch) { | ||
aMatch = {} | ||
bMatch = {} | ||
} | ||
var aIndex = aKeys[key] | ||
var bIndex = bKeys[key] | ||
aMatch[aIndex] = bIndex | ||
bMatch[bIndex] = aIndex | ||
} | ||
aMatch[aKeys[key]] = bKeys[key] | ||
} | ||
if (!aMatch) { | ||
return bChildren | ||
} | ||
var shuffle = [] | ||
var freeIndex = 0 | ||
var i = 0 | ||
var moveIndex = 0 | ||
var moves = shuffle.moves = {} | ||
shuffle.moves = bMatch | ||
for (var i = 0; i < len; i++) { | ||
var move = bMatch[i] | ||
while (freeIndex < len) { | ||
var move = aMatch[i] | ||
if (move !== undefined) { | ||
shuffle[i] = aChildren[move] | ||
shuffle[i] = bChildren[move] | ||
moves[move] = moveIndex++ | ||
} else if (i in aMatch) { | ||
shuffle[i] = undefined | ||
} else { | ||
while (freeIndex in aMatch) { | ||
while (freeIndex in bMatch) { | ||
freeIndex++ | ||
} | ||
shuffle[i] = aChildren[freeIndex++] | ||
if (freeIndex < len) { | ||
moves[freeIndex] = moveIndex++ | ||
shuffle[i] = bChildren[freeIndex] | ||
freeIndex++ | ||
} | ||
} | ||
i++ | ||
} | ||
@@ -263,0 +263,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77987
2080
Updatedglobal@^3.0.2