virtual-dom
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -21,2 +21,4 @@ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.virtualDom=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var create = require("./create-element.js") | ||
var VNode = require('./vnode/vnode.js') | ||
var VText = require('./vnode/vtext.js') | ||
@@ -27,6 +29,8 @@ module.exports = { | ||
h: h, | ||
create: create | ||
create: create, | ||
VNode: VNode, | ||
VText: VText | ||
} | ||
},{"./create-element.js":1,"./diff.js":2,"./h.js":3,"./patch.js":13}],5:[function(require,module,exports){ | ||
},{"./create-element.js":1,"./diff.js":2,"./h.js":3,"./patch.js":13,"./vnode/vnode.js":31,"./vnode/vtext.js":33}],5:[function(require,module,exports){ | ||
/*! | ||
@@ -491,3 +495,2 @@ * Cross-Browser Split 1.1.1 | ||
var render = require("./create-element") | ||
var updateWidget = require("./update-widget") | ||
@@ -540,3 +543,3 @@ | ||
function insertNode(parentNode, vNode, renderOptions) { | ||
var newNode = render(vNode, renderOptions) | ||
var newNode = renderOptions.render(vNode, renderOptions) | ||
@@ -558,5 +561,5 @@ if (parentNode) { | ||
var parentNode = domNode.parentNode | ||
newNode = render(vText, renderOptions) | ||
newNode = renderOptions.render(vText, renderOptions) | ||
if (parentNode) { | ||
if (parentNode && newNode !== domNode) { | ||
parentNode.replaceChild(newNode, domNode) | ||
@@ -576,3 +579,3 @@ } | ||
} else { | ||
newNode = render(widget, renderOptions) | ||
newNode = renderOptions.render(widget, renderOptions) | ||
} | ||
@@ -595,5 +598,5 @@ | ||
var parentNode = domNode.parentNode | ||
var newNode = render(vNode, renderOptions) | ||
var newNode = renderOptions.render(vNode, renderOptions) | ||
if (parentNode) { | ||
if (parentNode && newNode !== domNode) { | ||
parentNode.replaceChild(newNode, domNode) | ||
@@ -611,54 +614,24 @@ } | ||
function reorderChildren(domNode, bIndex) { | ||
var children = [] | ||
function reorderChildren(domNode, moves) { | ||
var childNodes = domNode.childNodes | ||
var len = childNodes.length | ||
var i | ||
var reverseIndex = bIndex.reverse | ||
for (i = 0; i < len; i++) { | ||
children.push(domNode.childNodes[i]) | ||
} | ||
var insertOffset = 0 | ||
var move | ||
var keyMap = {} | ||
var node | ||
var insertNode | ||
var chainLength | ||
var insertedLength | ||
var nextSibling | ||
for (i = 0; i < len;) { | ||
move = bIndex[i] | ||
chainLength = 1 | ||
if (move !== undefined && move !== i) { | ||
// try to bring forward as long of a chain as possible | ||
while (bIndex[i + chainLength] === move + chainLength) { | ||
chainLength++; | ||
} | ||
var remove | ||
var insert | ||
// the element currently at this index will be moved later so increase the insert offset | ||
if (reverseIndex[i] > i + chainLength) { | ||
insertOffset++ | ||
} | ||
node = children[move] | ||
insertNode = childNodes[i + insertOffset] || null | ||
insertedLength = 0 | ||
while (node !== insertNode && insertedLength++ < chainLength) { | ||
domNode.insertBefore(node, insertNode); | ||
node = children[move + insertedLength]; | ||
} | ||
// the moved element came from the front of the array so reduce the insert offset | ||
if (move + chainLength < i) { | ||
insertOffset-- | ||
} | ||
for (var i = 0; i < moves.removes.length; i++) { | ||
remove = moves.removes[i] | ||
node = childNodes[remove.from] | ||
if (remove.key) { | ||
keyMap[remove.key] = node | ||
} | ||
domNode.removeChild(node) | ||
} | ||
// element at this index is scheduled to be removed so increase insert offset | ||
if (i in bIndex.removes) { | ||
insertOffset++ | ||
} | ||
i += chainLength | ||
var length = childNodes.length | ||
for (var j = 0; j < moves.inserts.length; j++) { | ||
insert = moves.inserts[j] | ||
node = keyMap[insert.key] | ||
// this is the weirdest bug i've ever seen in webkit | ||
domNode.insertBefore(node, insert.to >= length++ ? null : childNodes[insert.to]) | ||
} | ||
@@ -669,3 +642,2 @@ } | ||
if (oldRoot && newRoot && oldRoot !== newRoot && oldRoot.parentNode) { | ||
console.log(oldRoot) | ||
oldRoot.parentNode.replaceChild(newRoot, oldRoot) | ||
@@ -677,6 +649,7 @@ } | ||
},{"../vnode/is-widget.js":29,"../vnode/vpatch.js":32,"./apply-properties":14,"./create-element":15,"./update-widget":19}],18:[function(require,module,exports){ | ||
},{"../vnode/is-widget.js":29,"../vnode/vpatch.js":32,"./apply-properties":14,"./update-widget":19}],18:[function(require,module,exports){ | ||
var document = require("global/document") | ||
var isArray = require("x-is-array") | ||
var render = require("./create-element") | ||
var domIndex = require("./dom-index") | ||
@@ -686,4 +659,8 @@ var patchOp = require("./patch-op") | ||
function patch(rootNode, patches) { | ||
return patchRecursive(rootNode, patches) | ||
function patch(rootNode, patches, renderOptions) { | ||
renderOptions = renderOptions || {} | ||
renderOptions.patch = renderOptions.patch || patchRecursive | ||
renderOptions.render = renderOptions.render || render | ||
return renderOptions.patch(rootNode, patches, renderOptions) | ||
} | ||
@@ -701,7 +678,4 @@ | ||
if (!renderOptions) { | ||
renderOptions = { patch: patchRecursive } | ||
if (ownerDocument !== document) { | ||
renderOptions.document = ownerDocument | ||
} | ||
if (!renderOptions.document && ownerDocument !== document) { | ||
renderOptions.document = ownerDocument | ||
} | ||
@@ -758,3 +732,3 @@ | ||
},{"./dom-index":16,"./patch-op":17,"global/document":10,"x-is-array":12}],19:[function(require,module,exports){ | ||
},{"./create-element":15,"./dom-index":16,"./patch-op":17,"global/document":10,"x-is-array":12}],19:[function(require,module,exports){ | ||
var isWidget = require("../vnode/is-widget.js") | ||
@@ -890,2 +864,4 @@ | ||
childNodes.push(new VText(c)); | ||
} else if (typeof c === 'number') { | ||
childNodes.push(new VText(String(c))); | ||
} else if (isChild(c)) { | ||
@@ -967,3 +943,3 @@ childNodes.push(c); | ||
var classIdSplit = /([\.#]?[a-zA-Z0-9_:-]+)/; | ||
var classIdSplit = /([\.#]?[a-zA-Z0-9\u007F-\uFFFF_:-]+)/; | ||
var notClassId = /^\.|#/; | ||
@@ -1103,3 +1079,3 @@ | ||
},{}],30:[function(require,module,exports){ | ||
module.exports = "1" | ||
module.exports = "2" | ||
@@ -1345,3 +1321,3 @@ },{}],31:[function(require,module,exports){ | ||
if (!isWidget(a)) { | ||
applyClear = true; | ||
applyClear = true | ||
} | ||
@@ -1363,3 +1339,4 @@ | ||
var aChildren = a.children | ||
var bChildren = reorder(aChildren, b.children) | ||
var orderedSet = reorder(aChildren, b.children) | ||
var bChildren = orderedSet.children | ||
@@ -1390,5 +1367,9 @@ var aLen = aChildren.length | ||
if (bChildren.moves) { | ||
if (orderedSet.moves) { | ||
// Reorder nodes last | ||
apply = appendPatch(apply, new VPatch(VPatch.ORDER, a, bChildren.moves)) | ||
apply = appendPatch(apply, new VPatch( | ||
VPatch.ORDER, | ||
a, | ||
orderedSet.moves | ||
)) | ||
} | ||
@@ -1435,3 +1416,3 @@ | ||
function thunks(a, b, patch, index) { | ||
var nodes = handleThunk(a, b); | ||
var nodes = handleThunk(a, b) | ||
var thunkPatch = diff(nodes.a, nodes.b) | ||
@@ -1446,7 +1427,7 @@ if (hasPatches(thunkPatch)) { | ||
if (index !== "a") { | ||
return true; | ||
return true | ||
} | ||
} | ||
return false; | ||
return false | ||
} | ||
@@ -1499,93 +1480,192 @@ | ||
function reorder(aChildren, bChildren) { | ||
// O(M) time, O(M) memory | ||
var bChildIndex = keyIndex(bChildren) | ||
var bKeys = bChildIndex.keys | ||
var bFree = bChildIndex.free | ||
var bKeys = keyIndex(bChildren) | ||
if (!bKeys) { | ||
return bChildren | ||
if (bFree.length === bChildren.length) { | ||
return { | ||
children: bChildren, | ||
moves: null | ||
} | ||
} | ||
var aKeys = keyIndex(aChildren) | ||
// O(N) time, O(N) memory | ||
var aChildIndex = keyIndex(aChildren) | ||
var aKeys = aChildIndex.keys | ||
var aFree = aChildIndex.free | ||
if (!aKeys) { | ||
return bChildren | ||
if (aFree.length === aChildren.length) { | ||
return { | ||
children: bChildren, | ||
moves: null | ||
} | ||
} | ||
var bMatch = {}, aMatch = {} | ||
// O(MAX(N, M)) memory | ||
var newChildren = [] | ||
for (var aKey in bKeys) { | ||
bMatch[bKeys[aKey]] = aKeys[aKey] | ||
} | ||
var freeIndex = 0 | ||
var freeCount = bFree.length | ||
var deletedItems = 0 | ||
for (var bKey in aKeys) { | ||
aMatch[aKeys[bKey]] = bKeys[bKey] | ||
} | ||
// Iterate through a and match a node in b | ||
// O(N) time, | ||
for (var i = 0 ; i < aChildren.length; i++) { | ||
var aItem = aChildren[i] | ||
var itemIndex | ||
var aLen = aChildren.length | ||
var bLen = bChildren.length | ||
var len = aLen > bLen ? aLen : bLen | ||
var shuffle = [] | ||
var freeIndex = 0 | ||
var i = 0 | ||
var moveIndex = 0 | ||
var moves = {} | ||
var removes = moves.removes = {} | ||
var reverse = moves.reverse = {} | ||
var hasMoves = false | ||
if (aItem.key) { | ||
if (bKeys.hasOwnProperty(aItem.key)) { | ||
// Match up the old keys | ||
itemIndex = bKeys[aItem.key] | ||
newChildren.push(bChildren[itemIndex]) | ||
while (freeIndex < len) { | ||
var move = aMatch[i] | ||
if (move !== undefined) { | ||
shuffle[i] = bChildren[move] | ||
if (move !== moveIndex) { | ||
moves[move] = moveIndex | ||
reverse[moveIndex] = move | ||
hasMoves = true | ||
} else { | ||
// Remove old keyed items | ||
itemIndex = i - deletedItems++ | ||
newChildren.push(null) | ||
} | ||
moveIndex++ | ||
} else if (i in aMatch) { | ||
shuffle[i] = undefined | ||
removes[i] = moveIndex++ | ||
hasMoves = true | ||
} else { | ||
while (bMatch[freeIndex] !== undefined) { | ||
freeIndex++ | ||
// Match the item in a with the next free item in b | ||
if (freeIndex < freeCount) { | ||
itemIndex = bFree[freeIndex++] | ||
newChildren.push(bChildren[itemIndex]) | ||
} else { | ||
// There are no free items in b to match with | ||
// the free items in a, so the extra free nodes | ||
// are deleted. | ||
itemIndex = i - deletedItems++ | ||
newChildren.push(null) | ||
} | ||
} | ||
} | ||
if (freeIndex < len) { | ||
var freeChild = bChildren[freeIndex] | ||
if (freeChild) { | ||
shuffle[i] = freeChild | ||
if (freeIndex !== moveIndex) { | ||
hasMoves = true | ||
moves[freeIndex] = moveIndex | ||
reverse[moveIndex] = freeIndex | ||
var lastFreeIndex = freeIndex >= bFree.length ? | ||
bChildren.length : | ||
bFree[freeIndex] | ||
// Iterate through b and append any new keys | ||
// O(M) time | ||
for (var j = 0; j < bChildren.length; j++) { | ||
var newItem = bChildren[j] | ||
if (newItem.key) { | ||
if (!aKeys.hasOwnProperty(newItem.key)) { | ||
// Add any new keyed items | ||
// We are adding new items to the end and then sorting them | ||
// in place. In future we should insert new items in place. | ||
newChildren.push(newItem) | ||
} | ||
} else if (j >= lastFreeIndex) { | ||
// Add any leftover non-keyed items | ||
newChildren.push(newItem) | ||
} | ||
} | ||
var simulate = newChildren.slice() | ||
var simulateIndex = 0 | ||
var removes = [] | ||
var inserts = [] | ||
var simulateItem | ||
for (var k = 0; k < bChildren.length;) { | ||
var wantedItem = bChildren[k] | ||
simulateItem = simulate[simulateIndex] | ||
// remove items | ||
while (simulateItem === null && simulate.length) { | ||
removes.push(remove(simulate, simulateIndex, null)) | ||
simulateItem = simulate[simulateIndex] | ||
} | ||
if (!simulateItem || simulateItem.key !== wantedItem.key) { | ||
// if we need a key in this position... | ||
if (wantedItem.key) { | ||
if (simulateItem && simulateItem.key) { | ||
// if an insert doesn't put this key in place, it needs to move | ||
if (bKeys[simulateItem.key] !== k + 1) { | ||
removes.push(remove(simulate, simulateIndex, simulateItem.key)) | ||
simulateItem = simulate[simulateIndex] | ||
// if the remove didn't put the wanted item in place, we need to insert it | ||
if (!simulateItem || simulateItem.key !== wantedItem.key) { | ||
inserts.push({key: wantedItem.key, to: k}) | ||
} | ||
// items are matching, so skip ahead | ||
else { | ||
simulateIndex++ | ||
} | ||
} | ||
moveIndex++ | ||
else { | ||
inserts.push({key: wantedItem.key, to: k}) | ||
} | ||
} | ||
freeIndex++ | ||
else { | ||
inserts.push({key: wantedItem.key, to: k}) | ||
} | ||
k++ | ||
} | ||
// a key in simulate has no matching wanted key, remove it | ||
else if (simulateItem && simulateItem.key) { | ||
removes.push(remove(simulate, simulateIndex, simulateItem.key)) | ||
} | ||
} | ||
i++ | ||
else { | ||
simulateIndex++ | ||
k++ | ||
} | ||
} | ||
if (hasMoves) { | ||
shuffle.moves = moves | ||
// remove all the remaining nodes from simulate | ||
while(simulateIndex < simulate.length) { | ||
simulateItem = simulate[simulateIndex] | ||
removes.push(remove(simulate, simulateIndex, simulateItem && simulateItem.key)) | ||
} | ||
return shuffle | ||
// If the only moves we have are deletes then we can just | ||
// let the delete patch remove these items. | ||
if (removes.length === deletedItems && !inserts.length) { | ||
return { | ||
children: newChildren, | ||
moves: null | ||
} | ||
} | ||
return { | ||
children: newChildren, | ||
moves: { | ||
removes: removes, | ||
inserts: inserts | ||
} | ||
} | ||
} | ||
function remove(arr, index, key) { | ||
arr.splice(index, 1) | ||
return { | ||
from: index, | ||
key: key | ||
} | ||
} | ||
function keyIndex(children) { | ||
var i, keys | ||
var keys = {} | ||
var free = [] | ||
var length = children.length | ||
for (i = 0; i < children.length; i++) { | ||
for (var i = 0; i < length; i++) { | ||
var child = children[i] | ||
if (child.key !== undefined) { | ||
keys = keys || {} | ||
if (child.key) { | ||
keys[child.key] = i | ||
} else { | ||
free.push(i) | ||
} | ||
} | ||
return keys | ||
return { | ||
keys: keys, // A hash of key name to index | ||
free: free // An array of unkeyed item indices | ||
} | ||
} | ||
@@ -1592,0 +1672,0 @@ |
@@ -1,2 +0,3 @@ | ||
Based on a discusison in ( https://github.com/Matt-Esch/virtual-dom/issues/104#issuecomment-68611995 ) question. | ||
# CSS animations | ||
Based on a discusison in [question](https://github.com/Matt-Esch/virtual-dom/issues/104#issuecomment-68611995). | ||
@@ -3,0 +4,0 @@ You should be activating the CSS transitions using hooks and nextTick. Here is a basic example of inserting an element through transition: |
@@ -26,1 +26,3 @@ # virtual-dom documentation | ||
[Widget](widget.md) - The mechanism for taking control of node patching: DOM Element creation, updating, and removal. | ||
[CSS animations](css-animations.md) |
{ | ||
"name": "virtual-dom", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "A batched diff-based DOM rendering strategy", | ||
@@ -38,18 +38,13 @@ "keywords": [ | ||
"devDependencies": { | ||
"browserify": "^8.1.0", | ||
"istanbul": "^0.3.4", | ||
"min-document": "^2.13.0", | ||
"opn": "^1.0.0", | ||
"run-browser": "git://github.com/Raynos/run-browser", | ||
"tap-dot": "^0.2.1", | ||
"tap-spec": "^2.1.1", | ||
"tape": "^3.0.3", | ||
"zuul": "^1.10.0" | ||
"browserify": "^9.0.7", | ||
"istanbul": "^0.3.13", | ||
"min-document": "^2.14.0", | ||
"opn": "^1.0.1", | ||
"run-browser": "^2.0.2", | ||
"tap-dot": "^1.0.0", | ||
"tap-spec": "^3.0.0", | ||
"tape": "^4.0.0", | ||
"zuul": "^2.1.1" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://github.com/Matt-Esch/virtual-dom/raw/master/LICENSE" | ||
} | ||
], | ||
"license": "MIT", | ||
"scripts": { | ||
@@ -56,0 +51,0 @@ "test": "node ./test/index.js | tap-spec", |
@@ -84,3 +84,3 @@ # virtual-dom | ||
var VNode = require('virtual-dom/vnode/vnode'); | ||
var VText = require('virtual-dom/vnode/vtext') | ||
var VText = require('virtual-dom/vnode/vtext'); | ||
@@ -91,3 +91,3 @@ function render(data) { | ||
}, [ | ||
new VText("Hello " + String(data.name)); | ||
new VText("Hello " + String(data.name)) | ||
]); | ||
@@ -131,3 +131,3 @@ } | ||
The primary motivation behind virtual-dom is to allow us to write code indepentent of previous state. So when our application state changes we will generate a new `VTree`. The `diff` function creates a set of DOM patches that, based on the difference between the previous `VTree` and the current `VTree`, will update the previous DOM tree to match the new `VTree`. | ||
The primary motivation behind virtual-dom is to allow us to write code independent of previous state. So when our application state changes we will generate a new `VTree`. The `diff` function creates a set of DOM patches that, based on the difference between the previous `VTree` and the current `VTree`, will update the previous DOM tree to match the new `VTree`. | ||
@@ -151,2 +151,3 @@ ## Patch operations | ||
* [html2hscript.herokuapp.com](http://html2hscript.herokuapp.com/) - Online Tool that converts html snippets to hyperscript | ||
* [html2hyperscript](https://github.com/unframework/html2hyperscript) - Original commandline utility to convert legacy HTML markup into hyperscript | ||
@@ -153,0 +154,0 @@ |
@@ -129,37 +129,38 @@ var test = require("tape") | ||
test("hooks are called with DOM node, property name, and previous/next value", function (assert) { | ||
var hookArgs = []; | ||
var unhookArgs = []; | ||
function Hook() {} | ||
function Hook(name) { | ||
this.name = name | ||
this.hookArgs = [] | ||
this.unhookArgs = [] | ||
} | ||
Hook.prototype.hook = function() { | ||
hookArgs.push([].slice.call(arguments, 0)) | ||
this.hookArgs.push([].slice.call(arguments, 0)) | ||
} | ||
Hook.prototype.unhook = function() { | ||
unhookArgs.push([].slice.call(arguments, 0)) | ||
this.unhookArgs.push([].slice.call(arguments, 0)) | ||
} | ||
var hook1 = new Hook() | ||
var hook2 = new Hook() | ||
var hook1 = new Hook('hook1') | ||
var hook2 = new Hook('hook2') | ||
var first = h("div", {hook: hook1}) | ||
var second = h("div", {hook: hook2}) | ||
var first = h("div", { id: 'first', hook: hook1 }) | ||
var second = h("div", { id: 'second', hook: hook2 }) | ||
var third = h("div") | ||
var elem = create(first) | ||
assert.equal(hookArgs.length, 1) | ||
assert.deepEqual(hookArgs[0], [elem, 'hook', undefined]) | ||
assert.equal(unhookArgs.length, 0) | ||
assert.equal(hook1.hookArgs.length, 1) | ||
assert.deepEqual(hook1.hookArgs[0], [elem, 'hook', undefined]) | ||
assert.equal(hook1.unhookArgs.length, 0) | ||
var patches = diff(first, second) | ||
elem = patch(elem, patches) | ||
assert.equal(hookArgs.length, 2) | ||
assert.deepEqual(hookArgs[1], [elem, 'hook', hook1]) | ||
assert.equal(unhookArgs.length, 1) | ||
assert.deepEqual(unhookArgs[0], [elem, 'hook', hook2]) | ||
assert.equal(hook2.hookArgs.length, 1) | ||
assert.deepEqual(hook2.hookArgs[0], [elem, 'hook', hook1]) | ||
assert.equal(hook1.unhookArgs.length, 1) | ||
assert.deepEqual(hook1.unhookArgs[0], [elem, 'hook', hook2]) | ||
patches = diff(second, third) | ||
elem = patch(elem, patches) | ||
assert.equal(hookArgs.length, 2) | ||
assert.equal(unhookArgs.length, 2) | ||
assert.deepEqual(unhookArgs[1], [elem, 'hook', undefined]) | ||
assert.equal(hook2.hookArgs.length, 1) | ||
assert.equal(hook2.unhookArgs.length, 1) | ||
assert.deepEqual(hook2.unhookArgs[0], [elem, 'hook', undefined]) | ||
@@ -166,0 +167,0 @@ assert.end() |
@@ -9,2 +9,3 @@ require("./main.js") | ||
require("./attributes") | ||
require("./non-string.js") | ||
@@ -11,0 +12,0 @@ require("../vdom/test/") |
@@ -25,2 +25,4 @@ module.exports = assertEqualDom | ||
key !== "innerHTML" && | ||
key !== "spellcheck" && | ||
key !== "bind" && | ||
"" + parseInt(key, 10) !== key | ||
@@ -27,0 +29,0 @@ ) { |
@@ -57,2 +57,8 @@ var test = require("tape") | ||
test("can use non-ascii class selector", function (assert) { | ||
var node = h("div.ΑΒΓΔΕΖ") | ||
assertNode(assert, node, "DIV", { className: "ΑΒΓΔΕΖ" }) | ||
assert.end() | ||
}) | ||
test("class selectors combine with className property", function (assert) { | ||
@@ -65,7 +71,13 @@ var node = h("div.very", { className: "pretty" }) | ||
test("can use id selector", function (assert) { | ||
var node = h("div.pretty") | ||
assertNode(assert, node, "DIV", { className: "pretty" }) | ||
var node = h("div#important") | ||
assertNode(assert, node, "DIV", { id: "important" }) | ||
assert.end() | ||
}) | ||
test("can use non-ascii id selector", function (assert) { | ||
var node = h("div#ΑΒΓΔΕΖ") | ||
assertNode(assert, node, "DIV", { id: "ΑΒΓΔΕΖ" }) | ||
assert.end() | ||
}) | ||
test("properties id overrides selector id", function (assert) { | ||
@@ -72,0 +84,0 @@ var node = h("div#very", { id: "important" }) |
@@ -6,3 +6,2 @@ var applyProperties = require("./apply-properties") | ||
var render = require("./create-element") | ||
var updateWidget = require("./update-widget") | ||
@@ -55,3 +54,3 @@ | ||
function insertNode(parentNode, vNode, renderOptions) { | ||
var newNode = render(vNode, renderOptions) | ||
var newNode = renderOptions.render(vNode, renderOptions) | ||
@@ -73,3 +72,3 @@ if (parentNode) { | ||
var parentNode = domNode.parentNode | ||
newNode = render(vText, renderOptions) | ||
newNode = renderOptions.render(vText, renderOptions) | ||
@@ -91,3 +90,3 @@ if (parentNode && newNode !== domNode) { | ||
} else { | ||
newNode = render(widget, renderOptions) | ||
newNode = renderOptions.render(widget, renderOptions) | ||
} | ||
@@ -110,3 +109,3 @@ | ||
var parentNode = domNode.parentNode | ||
var newNode = render(vNode, renderOptions) | ||
var newNode = renderOptions.render(vNode, renderOptions) | ||
@@ -113,0 +112,0 @@ if (parentNode && newNode !== domNode) { |
var document = require("global/document") | ||
var isArray = require("x-is-array") | ||
var render = require("./create-element") | ||
var domIndex = require("./dom-index") | ||
@@ -8,4 +9,8 @@ var patchOp = require("./patch-op") | ||
function patch(rootNode, patches) { | ||
return patchRecursive(rootNode, patches) | ||
function patch(rootNode, patches, renderOptions) { | ||
renderOptions = renderOptions || {} | ||
renderOptions.patch = renderOptions.patch || patchRecursive | ||
renderOptions.render = renderOptions.render || render | ||
return renderOptions.patch(rootNode, patches, renderOptions) | ||
} | ||
@@ -23,7 +28,4 @@ | ||
if (!renderOptions) { | ||
renderOptions = { patch: patchRecursive } | ||
if (ownerDocument !== document) { | ||
renderOptions.document = ownerDocument | ||
} | ||
if (!renderOptions.document && ownerDocument !== document) { | ||
renderOptions.document = ownerDocument | ||
} | ||
@@ -30,0 +32,0 @@ |
require("./dom-index") | ||
require("./patch-index") | ||
require("./patch-op-index") |
@@ -66,2 +66,4 @@ 'use strict'; | ||
childNodes.push(new VText(c)); | ||
} else if (typeof c === 'number') { | ||
childNodes.push(new VText(String(c))); | ||
} else if (isChild(c)) { | ||
@@ -68,0 +70,0 @@ childNodes.push(c); |
@@ -5,3 +5,3 @@ 'use strict'; | ||
var classIdSplit = /([\.#]?[a-zA-Z0-9_:-]+)/; | ||
var classIdSplit = /([\.#]?[a-zA-Z0-9\u007F-\uFFFF_:-]+)/; | ||
var notClassId = /^\.|#/; | ||
@@ -8,0 +8,0 @@ |
# virtual-hyperscript | ||
<!-- | ||
[![build status][1]][2] | ||
[![NPM version][3]][4] | ||
[![Coverage Status][5]][6] | ||
[![gemnasium Dependency Status][7]][8] | ||
[![Davis Dependency status][9]][10] | ||
--> | ||
<!-- [![browser support][11]][12] --> | ||
A DSL for creating virtual trees | ||
@@ -89,14 +79,1 @@ | ||
## MIT Licenced | ||
[1]: https://secure.travis-ci.org/Raynos/virtual-hyperscript.png | ||
[2]: https://travis-ci.org/Raynos/virtual-hyperscript | ||
[3]: https://badge.fury.io/js/virtual-hyperscript.png | ||
[4]: https://badge.fury.io/js/virtual-hyperscript | ||
[5]: https://coveralls.io/repos/Raynos/virtual-hyperscript/badge.png | ||
[6]: https://coveralls.io/r/Raynos/virtual-hyperscript | ||
[7]: https://gemnasium.com/Raynos/virtual-hyperscript.png | ||
[8]: https://gemnasium.com/Raynos/virtual-hyperscript | ||
[9]: https://david-dm.org/Raynos/virtual-hyperscript.png | ||
[10]: https://david-dm.org/Raynos/virtual-hyperscript | ||
[11]: https://ci.testling.com/Raynos/virtual-hyperscript.png | ||
[12]: https://ci.testling.com/Raynos/virtual-hyperscript |
@@ -411,3 +411,3 @@ var isArray = require("x-is-array") | ||
keys: keys, // A hash of key name to index | ||
free: free, // An array of unkeyed item indices | ||
free: free // An array of unkeyed item indices | ||
} | ||
@@ -414,0 +414,0 @@ } |
Sorry, the diff of this file is not supported yet
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
250667
80
6015
159