virtual-dom
Advanced tools
Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "virtual-dom", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A batched diff-based DOM rendering strategy", | ||
@@ -38,4 +38,5 @@ "keywords": [ | ||
"devDependencies": { | ||
"browserify": "^8.1.0", | ||
"istanbul": "^0.3.4", | ||
"min-document": "^2.6.1", | ||
"min-document": "^2.13.0", | ||
"opn": "^1.0.0", | ||
@@ -42,0 +43,0 @@ "run-browser": "git://github.com/Raynos/run-browser", |
@@ -155,3 +155,3 @@ var test = require("tape") | ||
assert.equal(elem.propA, undefined) | ||
assert.equal(elem.propB, undefined) | ||
assert.equal(elem.propB, null) | ||
assert.equal(counters.a, 1) | ||
@@ -232,2 +232,38 @@ assert.equal(counters.b, 1) | ||
test("property-replacing diff calls unhook", function (assert) { | ||
unhookCallCount = 0 | ||
function zhook(x) { | ||
this.x = x | ||
} | ||
zhook.prototype.hook = function () { | ||
return null | ||
} | ||
zhook.prototype.unhook = function () { | ||
unhookCallCount += 1 | ||
} | ||
hooker = new zhook('ONE') | ||
hooker2 = new zhook('TWO') | ||
var firstTree = h("div", {roothook: hooker}) | ||
var secondTree = h("div", {roothook: hooker2}) | ||
var thirdTree = h("span") | ||
var rootNode = create(firstTree) | ||
var firstPatches = diff(firstTree, secondTree) | ||
rootNode = patch(rootNode, firstPatches) | ||
var secondPatches = diff(secondTree, thirdTree) | ||
rootNode = patch(rootNode, secondPatches) | ||
assert.strictEqual(unhookCallCount, 2, "Missing unhook calls") | ||
assert.end() | ||
}) | ||
test("all hooks are unhooked", function (assert) { | ||
@@ -234,0 +270,0 @@ var hookCounts = {} |
@@ -13,2 +13,3 @@ var isObject = require("is-object") | ||
} else if (isHook(propValue)) { | ||
removeProperty(node, props, previous, propName) | ||
propValue.hook(node, | ||
@@ -15,0 +16,0 @@ propName, |
@@ -7,3 +7,3 @@ 'use strict'; | ||
if (!(this instanceof AttributeHook)) { | ||
return new AttributeHook(value); | ||
return new AttributeHook(namespace, value); | ||
} | ||
@@ -22,1 +22,7 @@ | ||
}; | ||
AttributeHook.prototype.unhook = function (node, prop) { | ||
var colonPosition = prop.indexOf(':') | ||
var localName = colonPosition > -1 ? prop.substr(colonPosition + 1) : prop | ||
node.removeAttributeNS(this.namespace, localName); | ||
}; |
@@ -69,2 +69,4 @@ # virtual-hyperscript | ||
**Note:** You must create an instance of `dom-delegator` for `ev-*` to work. | ||
If you call `h` with `h('div', { ev-click: function (ev) { } })` it | ||
@@ -71,0 +73,0 @@ will store the event handler on the dom element. It will not |
@@ -8,3 +8,4 @@ 'use strict'; | ||
var isSVGAttribute = require('./is-svg-attribute'); | ||
var SVGAttributeNamespace = require('./svg-attribute-namespace'); | ||
var attributeHook = require('./hooks/attribute-hook'); | ||
@@ -33,3 +34,5 @@ var SVG_NAMESPACE = 'http://www.w3.org/2000/svg'; | ||
if (!isSVGAttribute(key)) { | ||
var namespace = SVGAttributeNamespace(key); | ||
if (namespace === undefined) { // not a svg attribute | ||
continue; | ||
@@ -47,2 +50,7 @@ } | ||
if (namespace !== null) { // namespaced attribute | ||
properties[key] = attributeHook(namespace, value); | ||
continue; | ||
} | ||
attributes[key] = value | ||
@@ -49,0 +57,0 @@ properties[key] = undefined |
require("./h.js") | ||
require("./svg.js") | ||
require("./ev-hook.js") | ||
require("./attribute-hook.js") |
@@ -5,2 +5,3 @@ var test = require("tape") | ||
var svg = require("../svg") | ||
var attributeHook = require("../hooks/attribute-hook") | ||
@@ -48,2 +49,21 @@ test("svg returns a vnode", function (assert) { | ||
test("namespaced attributes are set with correct namespace", function(assert) { | ||
var node = svg("image", { | ||
"xlink:href": "http://example.com/image.png", | ||
"xml:space": "preserve", | ||
}) | ||
assert.strictEqual(node.properties.attributes["xlink:href"], undefined) | ||
assert.strictEqual(node.hooks["xlink:href"].constructor, attributeHook) | ||
assert.strictEqual(node.hooks["xlink:href"].value, "http://example.com/image.png") | ||
assert.strictEqual(node.hooks["xlink:href"].namespace, "http://www.w3.org/1999/xlink") | ||
assert.strictEqual(node.properties.attributes["xml:space"], undefined) | ||
assert.strictEqual(node.hooks["xml:space"].constructor, attributeHook) | ||
assert.strictEqual(node.hooks["xml:space"].value, "preserve") | ||
assert.strictEqual(node.hooks["xml:space"].namespace, "http://www.w3.org/XML/1998/namespace") | ||
assert.end() | ||
}) | ||
function safeStyle(property, value) { | ||
@@ -50,0 +70,0 @@ var div = doc.createElement("div") |
module.exports = isHook | ||
function isHook(hook) { | ||
return hook && typeof hook.hook === "function" && | ||
!hook.hasOwnProperty("hook") | ||
return hook && | ||
(typeof hook.hook === "function" && !hook.hasOwnProperty("hook") || | ||
typeof hook.unhook === "function" && !hook.hasOwnProperty("unhook")) | ||
} |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
194568
65
5131
9
3