Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

virtual-dom

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

virtual-dom - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

test/thunk.js

4

package.json
{
"name": "virtual-dom",
"version": "0.0.8",
"version": "0.0.9",
"description": "A batched diff-based DOM rendering strategy",

@@ -21,3 +21,3 @@ "keywords": [],

"browser-split": "0.0.1",
"global": "^3.0.2",
"global": "^4.2.1",
"is-object": "^0.1.2",

@@ -24,0 +24,0 @@ "x-is-array": "^0.1.0",

@@ -17,2 +17,3 @@ var test = require("tape")

require("./keys.js")
require("./thunk.js")

@@ -463,3 +464,4 @@ // VirtualNode tests

initCount = 1000000
}
},
type: "Widget"
}

@@ -484,3 +486,4 @@

initCount = 1000000
}
},
type: "Widget"
}

@@ -532,2 +535,4 @@

Widget.prototype.type = "Widget"
var leftTree = new Widget(leftState)

@@ -584,2 +589,4 @@ var rightTree = new Widget(rightState)

Widget.prototype.type = "Widget"
var leftWidget = new Widget(leftState)

@@ -628,3 +635,4 @@ var rightWidget = new Widget(rightState)

update: function () {},
destroy: function () {}
destroy: function () {},
type: "Widget"
}

@@ -634,3 +642,4 @@

init: function () {},
update: function () {}
update: function () {},
type: "Widget"
}

@@ -653,3 +662,4 @@

count++
}
},
type: "Widget"
}

@@ -670,3 +680,4 @@

count++
}
},
type: "Widget"
}

@@ -679,7 +690,9 @@

count = 10000000
}
},
type: "Widget"
}
var rootNode = render(h("div"))
patch(rootNode, diff(statefulWidget, newWidget))
var patches = diff(statefulWidget, newWidget)
patch(rootNode, patches)
assert.equal(count, 1)

@@ -696,3 +709,4 @@ assert.end()

count++
}
},
type: "Widget"
}

@@ -702,3 +716,4 @@

init: function () {},
update: function () {}
update: function () {},
type: "Widget"
}

@@ -719,3 +734,4 @@

count++
}
},
type: "Widget"
}

@@ -742,3 +758,4 @@

count++
}
},
type: "Widget"
}

@@ -745,0 +762,0 @@

@@ -170,2 +170,4 @@ var test = require("tape")

DivWidget.prototype.type = "Widget"
var leftNode = h("div", [

@@ -271,3 +273,3 @@ new DivWidget("1", "a"),

var childNodes = childNodesArray(rootNode)
debugger;
var patches = diff(leftNode, rightNode)

@@ -314,2 +316,34 @@ assert.equal(patchCount(patches), 2)

test("add to end and delete from center & reverse", function (assert) {
var leftNode = h("div", [
h("div", { key: "a" }, "a"),
h("div", { key: "b" }, "b"),
h("div", { key: "c" }, "c"),
h("div", { key: "d" }, "d"),
])
var rightNode = h("div", [
h("div", { key: "e" }, "e"),
h("div", { key: "d" }, "d"),
h("div", { key: "c" }, "c"),
h("div", { key: "a" }, "a")
])
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, 4)
assert.equal(newRoot.childNodes[1], childNodes[3])
assert.equal(newRoot.childNodes[2], childNodes[2])
assert.equal(newRoot.childNodes[3], childNodes[0])
assert.end()
})
test("adding multiple widgets", function (assert) {

@@ -331,2 +365,4 @@ function FooWidget(foo) {

FooWidget.prototype.type = "Widget"
var firstTree = h("div", [])

@@ -333,0 +369,0 @@ var rootNode = render(firstTree)

@@ -7,4 +7,4 @@ var isWidget = require("../vtree/is-widget")

if (isWidget(a) && isWidget(b)) {
if ("type" in a && "type" in b) {
return a.type === b.type
if ("name" in a && "name" in b) {
return a.id === b.id
} else {

@@ -11,0 +11,0 @@ return a.init === b.init

@@ -8,2 +8,3 @@ var isArray = require("x-is-array")

var isWidget = require("./is-widget")
var isThunk = require("./is-thunk")

@@ -19,2 +20,11 @@ module.exports = diff

function walk(a, b, patch, index) {
if (isThunk(b)) {
if (isThunk(a)) {
b = b.vnode = b.render(a)
a = a.vnode
} else {
b = b.vnode = b.render(null)
}
}
if (a === b) {

@@ -27,15 +37,5 @@ hooks(b, patch, index)

if (isWidget(b)) {
apply = appendPatch(apply, new VPatch(VPatch.WIDGET, a, b))
if (!isWidget(a)) {
destroyWidgets(a, patch, index)
}
} else if (isVText(b)) {
if (!isVText(a)) {
apply = appendPatch(apply, new VPatch(VPatch.VTEXT, a, b))
destroyWidgets(a, patch, index)
} else if (a.text !== b.text) {
apply = appendPatch(apply, new VPatch(VPatch.VTEXT, a, b))
}
if (b == null) {
apply = appendPatch(apply, new VPatch(VPatch.REMOVE, a, b))
destroyWidgets(a, patch, index)
} else if (isVNode(b)) {

@@ -61,5 +61,15 @@ if (isVNode(a)) {

}
} else if (b == null) {
apply = appendPatch(apply, new VPatch(VPatch.REMOVE, a, b))
destroyWidgets(a, patch, index)
} else if (isVText(b)) {
if (!isVText(a)) {
apply = appendPatch(apply, new VPatch(VPatch.VTEXT, a, b))
destroyWidgets(a, patch, index)
} else if (a.text !== b.text) {
apply = appendPatch(apply, new VPatch(VPatch.VTEXT, a, b))
}
} else if (isWidget(b)) {
apply = appendPatch(apply, new VPatch(VPatch.WIDGET, a, b))
if (!isWidget(a)) {
destroyWidgets(a, patch, index)
}
}

@@ -254,2 +264,3 @@

shuffle[i] = undefined
moves[move] = moveIndex++
} else {

@@ -261,4 +272,7 @@ while (bMatch[freeIndex] !== undefined) {

if (freeIndex < len) {
moves[freeIndex] = moveIndex++
shuffle[i] = bChildren[freeIndex]
var freeChild = bChildren[freeIndex]
if (freeChild) {
moves[freeIndex] = moveIndex++
shuffle[i] = freeChild
}
freeIndex++

@@ -265,0 +279,0 @@ }

@@ -6,7 +6,3 @@ var version = require("./version")

function isVirtualNode(x) {
if (!x) {
return false;
}
return x.type === "VirtualNode" && x.version === version
return x && x.type === "VirtualNode" && x.version === version
}

@@ -6,7 +6,3 @@ var version = require("./version")

function isVirtualText(x) {
if (!x) {
return false;
}
return x.type === "VirtualText" && x.version === version
return x && x.type === "VirtualText" && x.version === version
}
module.exports = isWidget
function isWidget(w) {
return w && typeof w.init === "function" && typeof w.update === "function"
return w && w.type === "Widget"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc