From 900d332c2111f172a756989c1fc4a72d2fc19b22 Mon Sep 17 00:00:00 2001 From: Matt Esch Date: Sun, 21 Dec 2014 07:20:44 -0800 Subject: [PATCH] refactor virtual hyperscript --- package.json | 4 +- virtual-hyperscript/README.md | 20 +- virtual-hyperscript/hooks/attribute-hook.js | 9 +- virtual-hyperscript/hooks/data-set-hook.js | 18 -- virtual-hyperscript/hooks/ev-hook.js | 28 +-- virtual-hyperscript/hooks/focus-hook.js | 16 +- virtual-hyperscript/hooks/soft-set-hook.js | 2 + virtual-hyperscript/index.js | 133 ++++++------- virtual-hyperscript/is-svg-attribute.js | 165 ++++++++++++++++ virtual-hyperscript/parse-tag.js | 47 +++-- virtual-hyperscript/svg.js | 204 +++----------------- virtual-hyperscript/test/ev-hook.js | 6 +- virtual-hyperscript/test/h.js | 39 ++-- 13 files changed, 345 insertions(+), 346 deletions(-) delete mode 100644 virtual-hyperscript/hooks/data-set-hook.js create mode 100644 virtual-hyperscript/is-svg-attribute.js diff --git a/package.json b/package.json index 4f7f70fe..2b640df5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "virtual-dom", "version": "0.0.24", "description": "A batched diff-based DOM rendering strategy", - "keywords": [], + "keywords": ["virtual", "dom", "vdom", "vtree", "diff", "patch", "browser"], "author": "Matt-Esch ", "repository": "git://github.com/Matt-Esch/virtual-dom.git", "main": "index", @@ -18,8 +18,8 @@ }, "dependencies": { "browser-split": "0.0.1", - "data-set": "^3.1.0", "error": "^4.3.0", + "ev-store": "^7.0.0", "global": "^4.3.0", "is-object": "^1.0.1", "next-tick": "^0.2.2", diff --git a/virtual-hyperscript/README.md b/virtual-hyperscript/README.md index 1b13062c..cb55e61a 100644 --- a/virtual-hyperscript/README.md +++ b/virtual-hyperscript/README.md @@ -27,7 +27,7 @@ var tree = h('div.foo#some-id', [ See [hyperscript](https://github.com/dominictarr/hyperscript) which has the same interface. - + Except `virtual-hyperscript` returns a virtual DOM tree instead of a DOM element. @@ -35,14 +35,14 @@ Except `virtual-hyperscript` returns a virtual DOM tree instead of a DOM `h()` takes a selector, an optional properties object and an optional array of children or a child that is a string. - + If you pass it a selector like `span.foo.bar#some-id` it will parse the selector and change the `id` and `className` properties of the `properties` object. - + If you pass it an array of `children` it will have child nodes, normally ou want to create children with `h()`. - + If you pass it a string it will create an array containing a single child node that is a text element. @@ -64,17 +64,6 @@ If you call `h` with `h('div', { namespace: "http://www.w3.org/2000/svg" })` `namespace` is not a normal DOM property, instead it will cause `vdom` to create a DOM element with a namespace. -#### `data-*` - -If you call `h` with `h('div', { data-foo: "bar" })` it will - set `data-foo` to be a `VHook` that set's a `DataSet` property - named `foo` with the value `"bar"` on the actual dom element. - -It will not set a property `data-foo` on the dom element. - -This means that somewhere else in your code you can use - `DataSet(elem).foo` to read this property. - #### `ev-*` If you call `h` with `h('div', { ev-click: function (ev) { } })` it @@ -92,6 +81,7 @@ This means that `dom-delegator` will recognise the event handler ## Contributors - Raynos + - Matt Esch ## MIT Licenced diff --git a/virtual-hyperscript/hooks/attribute-hook.js b/virtual-hyperscript/hooks/attribute-hook.js index 9d86133f..667f66ce 100644 --- a/virtual-hyperscript/hooks/attribute-hook.js +++ b/virtual-hyperscript/hooks/attribute-hook.js @@ -1,10 +1,13 @@ +'use strict'; + module.exports = AttributeHook; -function AttributeHook(value) { +function AttributeHook(namespace, value) { if (!(this instanceof AttributeHook)) { return new AttributeHook(value); } + this.namespace = namespace; this.value = value; } @@ -13,5 +16,5 @@ AttributeHook.prototype.hook = function (node, prop, prev) { return; } - node.setAttributeNS(null, prop, this.value) -} + node.setAttributeNS(this.namespace, prop, this.value); +}; diff --git a/virtual-hyperscript/hooks/data-set-hook.js b/virtual-hyperscript/hooks/data-set-hook.js deleted file mode 100644 index 32e3331e..00000000 --- a/virtual-hyperscript/hooks/data-set-hook.js +++ /dev/null @@ -1,18 +0,0 @@ -var DataSet = require("data-set") - -module.exports = DataSetHook; - -function DataSetHook(value) { - if (!(this instanceof DataSetHook)) { - return new DataSetHook(value); - } - - this.value = value; -} - -DataSetHook.prototype.hook = function (node, propertyName) { - var ds = DataSet(node) - var propName = propertyName.substr(5) - - ds[propName] = this.value; -}; diff --git a/virtual-hyperscript/hooks/ev-hook.js b/virtual-hyperscript/hooks/ev-hook.js index eda7b5da..e3e17f4b 100644 --- a/virtual-hyperscript/hooks/ev-hook.js +++ b/virtual-hyperscript/hooks/ev-hook.js @@ -1,25 +1,27 @@ -var DataSet = require("data-set") +'use strict'; -module.exports = DataSetHook; +var EvStore = require('ev-store'); -function DataSetHook(value) { - if (!(this instanceof DataSetHook)) { - return new DataSetHook(value); +module.exports = EvHook; + +function EvHook(value) { + if (!(this instanceof EvHook)) { + return new EvHook(value); } this.value = value; } -DataSetHook.prototype.hook = function (node, propertyName) { - var ds = DataSet(node) - var propName = propertyName.substr(3) +EvHook.prototype.hook = function (node, propertyName) { + var es = EvStore(node); + var propName = propertyName.substr(3); - ds[propName] = this.value; + es[propName] = this.value; }; -DataSetHook.prototype.unhook = function(node, propertyName) { - var ds = DataSet(node); +EvHook.prototype.unhook = function(node, propertyName) { + var es = EvStore(node); var propName = propertyName.substr(3); - ds[propName] = undefined; -} + es[propName] = undefined; +}; diff --git a/virtual-hyperscript/hooks/focus-hook.js b/virtual-hyperscript/hooks/focus-hook.js index a425d050..ed5c33cf 100644 --- a/virtual-hyperscript/hooks/focus-hook.js +++ b/virtual-hyperscript/hooks/focus-hook.js @@ -1,18 +1,20 @@ -var document = require("global/document") -var nextTick = require("next-tick") +'use strict'; -module.exports = MutableFocusHook +var document = require("global/document"); +var nextTick = require("next-tick"); + +module.exports = MutableFocusHook; function MutableFocusHook() { if (!(this instanceof MutableFocusHook)) { - return new MutableFocusHook() + return new MutableFocusHook(); } } -MutableFocusHook.prototype.hook = function (node, property) { +MutableFocusHook.prototype.hook = function (node) { nextTick(function () { if (document.activeElement !== node) { node.focus(); } - }) -} + }); +}; diff --git a/virtual-hyperscript/hooks/soft-set-hook.js b/virtual-hyperscript/hooks/soft-set-hook.js index a9e15b36..7a902a92 100644 --- a/virtual-hyperscript/hooks/soft-set-hook.js +++ b/virtual-hyperscript/hooks/soft-set-hook.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = SoftSetHook; function SoftSetHook(value) { diff --git a/virtual-hyperscript/index.js b/virtual-hyperscript/index.js index 44703295..c5877950 100644 --- a/virtual-hyperscript/index.js +++ b/virtual-hyperscript/index.js @@ -1,130 +1,125 @@ -var TypedError = require("error/typed") - -var VNode = require("../vnode/vnode.js") -var VText = require("../vnode/vtext.js") -var isVNode = require("../vnode/is-vnode") -var isVText = require("../vnode/is-vtext") -var isWidget = require("../vnode/is-widget") -var isHook = require("../vnode/is-vhook") -var isVThunk = require("../vnode/is-thunk") - -var parseTag = require("./parse-tag.js") -var softSetHook = require("./hooks/soft-set-hook.js") -var dataSetHook = require("./hooks/data-set-hook.js") -var evHook = require("./hooks/ev-hook.js") - -var UnexpectedVirtualElement = TypedError({ - type: "virtual-hyperscript.unexpected.virtual-element", - message: "Unexpected virtual child passed to h().\n" + - "Expected a VNode / Vthunk / VWidget / string but:\n" + - "got a {foreignObjectStr}.\n" + - "The parent vnode is {parentVnodeStr}.\n" + - "Suggested fix: change your `h(..., [ ... ])` callsite.", - foreignObjectStr: null, - parentVnodeStr: null, - foreignObject: null, - parentVnode: null -}) - -module.exports = h +'use strict'; + +var isArray = require('x-is-array'); + +var VNode = require('../vnode/vnode.js'); +var VText = require('../vnode/vtext.js'); +var isVNode = require('../vnode/is-vnode'); +var isVText = require('../vnode/is-vtext'); +var isWidget = require('../vnode/is-widget'); +var isHook = require('../vnode/is-vhook'); +var isVThunk = require('../vnode/is-thunk'); + +var parseTag = require('./parse-tag.js'); +var softSetHook = require('./hooks/soft-set-hook.js'); +var evHook = require('./hooks/ev-hook.js'); + +module.exports = h; function h(tagName, properties, children) { - var childNodes = [] - var tag, props, key, namespace + var childNodes = []; + var tag, props, key, namespace; if (!children && isChildren(properties)) { - children = properties - props = {} + children = properties; + props = {}; } - props = props || properties || {} - tag = parseTag(tagName, props) + props = props || properties || {}; + tag = parseTag(tagName, props); // support keys - if (props.hasOwnProperty("key")) { - key = props.key - props.key = undefined + if (props.hasOwnProperty('key')) { + key = props.key; + props.key = undefined; } // support namespace - if (props.hasOwnProperty("namespace")) { - namespace = props.namespace - props.namespace = undefined + if (props.hasOwnProperty('namespace')) { + namespace = props.namespace; + props.namespace = undefined; } // fix cursor bug - if (tag === "INPUT" && + if (tag === 'INPUT' && !props.namespace && - props.hasOwnProperty("value") && + props.hasOwnProperty('value') && props.value !== undefined && !isHook(props.value) ) { - props.value = softSetHook(props.value) + props.value = softSetHook(props.value); } - transformProperties(props) + transformProperties(props); if (children !== undefined && children !== null) { - addChild(children, childNodes, tag, props) + addChild(children, childNodes, tag, props); } - var node = new VNode(tag, props, childNodes, key, namespace) + var node = new VNode(tag, props, childNodes, key, namespace); - return node + return node; } function addChild(c, childNodes, tag, props) { - if (typeof c === "string") { - childNodes.push(new VText(c)) + if (typeof c === 'string') { + childNodes.push(new VText(c)); } else if (isChild(c)) { - childNodes.push(c) - } else if (Array.isArray(c)) { + childNodes.push(c); + } else if (isArray(c)) { for (var i = 0; i < c.length; i++) { - addChild(c[i], childNodes, tag, props) + addChild(c[i], childNodes, tag, props); } } else if (c === null || c === undefined) { - return + return; } else { throw UnexpectedVirtualElement({ - foreignObjectStr: JSON.stringify(c), foreignObject: c, - parentVnodeStr: JSON.stringify({ - tagName: tag, - properties: props - }), parentVnode: { tagName: tag, properties: props } - }) + }); } } function transformProperties(props) { for (var propName in props) { if (props.hasOwnProperty(propName)) { - var value = props[propName] + var value = props[propName]; if (isHook(value)) { - continue + continue; } - if (propName.substr(0, 5) === "data-") { - // add data-foo support - props[propName] = dataSetHook(value) - } else if (propName.substr(0, 3) === "ev-") { + if (propName.substr(0, 3) === 'ev-') { // add ev-foo support - props[propName] = evHook(value) + props[propName] = evHook(value); } } } } function isChild(x) { - return isVNode(x) || isVText(x) || isWidget(x) || isVThunk(x) + return isVNode(x) || isVText(x) || isWidget(x) || isVThunk(x); } function isChildren(x) { - return typeof x === "string" || Array.isArray(x) || isChild(x) + return typeof x === 'string' || isArray(x) || isChild(x); +} + +function UnexpectedVirtualElement(data) { + var err = new Error(); + + err.type = 'virtual-hyperscript.unexpected.virtual-element'; + err.message = 'Unexpected virtual child passed to h().\n' + + 'Expected a VNode / Vthunk / VWidget / string but:\n' + + 'got a {foreignObjectStr}.\n' + + 'The parent vnode is {parentVnodeStr}.\n' + + 'Suggested fix: change your `h(..., [ ... ])` callsite.'; + err.foreignObject = data.foreignObject; + err.parentVnode = data.parentVnode; + + return err; } diff --git a/virtual-hyperscript/is-svg-attribute.js b/virtual-hyperscript/is-svg-attribute.js new file mode 100644 index 00000000..b3799125 --- /dev/null +++ b/virtual-hyperscript/is-svg-attribute.js @@ -0,0 +1,165 @@ +'use strict'; + +// http://www.w3.org/TR/SVGTiny12/attributeTable.html +var SVG_PROPERTIES = { + 'about': true, + 'accent-height': true, + 'accumulate': true, + 'additive': true, + 'alphabetic': true, + 'arabic-form': true, + 'ascent': true, + 'attributeName': true, + 'attributeType': true, + 'bandwidth': true, + 'baseProfile': true, + 'bbox': true, + 'begin': true, + 'by': true, + 'calcMode': true, + 'cap-height': true, + 'class': true, + 'content': true, + 'contentScriptType': true, + 'cx': true, + 'cy': true, + 'd': true, + 'datatype': true, + 'defaultAction': true, + 'descent': true, + 'dur': true, + 'editable': true, + 'end': true, + 'ev:event': true, + 'event': true, + 'externalResourcesRequired': true, + 'fill': true, + 'focusHighlight': true, + 'focusable': true, + 'font-family': true, + 'font-stretch': true, + 'font-style': true, + 'font-variant': true, + 'font-weight': true, + 'from': true, + 'g1': true, + 'g2': true, + 'glyph-name': true, + 'gradientUnits': true, + 'handler': true, + 'hanging': true, + 'height': true, + 'horiz-adv-x': true, + 'horiz-origin-x': true, + 'id': true, + 'ideographic': true, + 'initialVisibility': true, + 'k': true, + 'keyPoints': true, + 'keySplines': true, + 'keyTimes': true, + 'lang': true, + 'mathematical': true, + 'max': true, + 'mediaCharacterEncoding': true, + 'mediaContentEncodings': true, + 'mediaSize': true, + 'mediaTime': true, + 'min': true, + 'nav-down': true, + 'nav-down-left': true, + 'nav-down-right': true, + 'nav-left': true, + 'nav-next': true, + 'nav-prev': true, + 'nav-right': true, + 'nav-up': true, + 'nav-up-left': true, + 'nav-up-right': true, + 'observer': true, + 'offset': true, + 'origin': true, + 'overlay': true, + 'overline-position': true, + 'overline-thickness': true, + 'panose-1': true, + 'path': true, + 'pathLength': true, + 'phase': true, + 'playbackOrder': true, + 'points': true, + 'preserveAspectRatio': true, + 'propagate': true, + 'property': true, + 'r': true, + 'rel': true, + 'repeatCount': true, + 'repeatDur': true, + 'requiredExtensions': true, + 'requiredFeatures': true, + 'requiredFonts': true, + 'requiredFormats': true, + 'resource': true, + 'restart': true, + 'rev': true, + 'role': true, + 'rotate': true, + 'rx': true, + 'ry': true, + 'slope': true, + 'snapshotTime': true, + 'stemh': true, + 'stemv': true, + 'strikethrough-position': true, + 'strikethrough-thickness': true, + 'syncBehavior': true, + 'syncBehaviorDefault': true, + 'syncMaster': true, + 'syncTolerance': true, + 'syncToleranceDefault': true, + 'systemLanguage': true, + 'target': true, + 'timelineBegin': true, + 'to': true, + 'transform': true, + 'transformBehavior': true, + 'type': true, + 'typeof': true, + 'u1': true, + 'u2': true, + 'underline-position': true, + 'underline-thickness': true, + 'unicode': true, + 'unicode-range': true, + 'units-per-em': true, + 'values': true, + 'version': true, + 'viewBox': true, + 'width': true, + 'widths': true, + 'x': true, + 'x-height': true, + 'x1': true, + 'x2': true, + 'xlink:actuate': true, + 'xlink:arcrole': true, + 'xlink:href': true, + 'xlink:role': true, + 'xlink:show': true, + 'xlink:title': true, + 'xlink:type': true, + 'xml:base': true, + 'xml:id': true, + 'xml:lang': true, + 'xml:space': true, + 'y': true, + 'y1': true, + 'y2': true, + 'zoomAndPan': true +}; + +module.exports = isSVGAttribute; + +function isSVGAttribute(value) { + return SVG_PROPERTIES[value] === true; +} diff --git a/virtual-hyperscript/parse-tag.js b/virtual-hyperscript/parse-tag.js index 3887226f..25a4dcf0 100644 --- a/virtual-hyperscript/parse-tag.js +++ b/virtual-hyperscript/parse-tag.js @@ -1,49 +1,54 @@ -var classIdSplit = /([\.#]?[a-zA-Z0-9_:-]+)/ -var notClassId = /^\.|#/ +'use strict'; -module.exports = parseTag +var split = require('browser-split'); + +var classIdSplit = /([\.#]?[a-zA-Z0-9_:-]+)/; +var notClassId = /^\.|#/; + +module.exports = parseTag; function parseTag(tag, props) { if (!tag) { - return "DIV" + return 'DIV'; } - var noId = !("id" in props) + var noId = !(props.hasOwnProperty('id')); - var tagParts = tag.split(classIdSplit) - var tagName = null + var tagParts = split(tag, classIdSplit); + var tagName = null; if (notClassId.test(tagParts[1])) { - tagName = "DIV" + tagName = 'DIV'; } - var classes, part, type, i + var classes, part, type, i; + for (i = 0; i < tagParts.length; i++) { - part = tagParts[i] + part = tagParts[i]; if (!part) { - continue + continue; } - type = part.charAt(0) + type = part.charAt(0); if (!tagName) { - tagName = part - } else if (type === ".") { - classes = classes || [] - classes.push(part.substring(1, part.length)) - } else if (type === "#" && noId) { - props.id = part.substring(1, part.length) + tagName = part; + } else if (type === '.') { + classes = classes || []; + classes.push(part.substring(1, part.length)); + } else if (type === '#' && noId) { + props.id = part.substring(1, part.length); } } if (classes) { if (props.className) { - classes.push(props.className) + classes.push(props.className); } - props.className = classes.join(" ") + props.className = classes.join(' '); } - return props.namespace ? tagName : tagName.toUpperCase() + return props.namespace ? tagName : tagName.toUpperCase(); } diff --git a/virtual-hyperscript/svg.js b/virtual-hyperscript/svg.js index 5cb9c9ab..0ca30b6e 100644 --- a/virtual-hyperscript/svg.js +++ b/virtual-hyperscript/svg.js @@ -1,203 +1,53 @@ -var h = require("./index.js") - -// http://www.w3.org/TR/SVGTiny12/attributeTable.html -var svgAttributes = { - "about": true, - "accent-height": true, - "accumulate": true, - "additive": true, - "alphabetic": true, - "arabic-form": true, - "ascent": true, - "attributeName": true, - "attributeType": true, - "bandwidth": true, - "baseProfile": true, - "bbox": true, - "begin": true, - "by": true, - "calcMode": true, - "cap-height": true, - "class": true, - "content": true, - "contentScriptType": true, - "cx": true, - "cy": true, - "d": true, - "datatype": true, - "defaultAction": true, - "descent": true, - "dur": true, - "editable": true, - "end": true, - "ev:event": true, - "event": true, - "externalResourcesRequired": true, - "fill": true, - "focusHighlight": true, - "focusable": true, - "font-family": true, - "font-stretch": true, - "font-style": true, - "font-variant": true, - "font-weight": true, - "from": true, - "g1": true, - "g2": true, - "glyph-name": true, - "gradientUnits": true, - "handler": true, - "hanging": true, - "height": true, - "horiz-adv-x": true, - "horiz-origin-x": true, - "id": true, - "ideographic": true, - "initialVisibility": true, - "k": true, - "keyPoints": true, - "keySplines": true, - "keyTimes": true, - "lang": true, - "mathematical": true, - "max": true, - "mediaCharacterEncoding": true, - "mediaContentEncodings": true, - "mediaSize": true, - "mediaTime": true, - "min": true, - "nav-down": true, - "nav-down-left": true, - "nav-down-right": true, - "nav-left": true, - "nav-next": true, - "nav-prev": true, - "nav-right": true, - "nav-up": true, - "nav-up-left": true, - "nav-up-right": true, - "observer": true, - "offset": true, - "origin": true, - "overlay": true, - "overline-position": true, - "overline-thickness": true, - "panose-1": true, - "path": true, - "pathLength": true, - "phase": true, - "playbackOrder": true, - "points": true, - "preserveAspectRatio": true, - "propagate": true, - "property": true, - "r": true, - "rel": true, - "repeatCount": true, - "repeatDur": true, - "requiredExtensions": true, - "requiredFeatures": true, - "requiredFonts": true, - "requiredFormats": true, - "resource": true, - "restart": true, - "rev": true, - "role": true, - "rotate": true, - "rx": true, - "ry": true, - "slope": true, - "snapshotTime": true, - "stemh": true, - "stemv": true, - "strikethrough-position": true, - "strikethrough-thickness": true, - "syncBehavior": true, - "syncBehaviorDefault": true, - "syncMaster": true, - "syncTolerance": true, - "syncToleranceDefault": true, - "systemLanguage": true, - "target": true, - "timelineBegin": true, - "to": true, - "transform": true, - "transformBehavior": true, - "type": true, - "typeof": true, - "u1": true, - "u2": true, - "underline-position": true, - "underline-thickness": true, - "unicode": true, - "unicode-range": true, - "units-per-em": true, - "values": true, - "version": true, - "viewBox": true, - "width": true, - "widths": true, - "x": true, - "x-height": true, - "x1": true, - "x2": true, - "xlink:actuate": true, - "xlink:arcrole": true, - "xlink:href": true, - "xlink:role": true, - "xlink:show": true, - "xlink:title": true, - "xlink:type": true, - "xml:base": true, - "xml:id": true, - "xml:lang": true, - "xml:space": true, - "y": true, - "y1": true, - "y2": true, - "zoomAndPan": true -} +'use strict'; + +var isArray = require('x-is-array'); + +var h = require('./index.js'); -var SVG_NAMESPACE = "http://www.w3.org/2000/svg" -module.exports = svg +var isSVGAttribute = require('./is-svg-attribute'); + +var SVG_NAMESPACE = 'http://www.w3.org/2000/svg'; + +module.exports = svg; function svg(tagName, properties, children) { if (!children && isChildren(properties)) { - children = properties - properties = {} + children = properties; + properties = {}; } - properties = properties || {} + properties = properties || {}; // set namespace for svg - properties.namespace = SVG_NAMESPACE + properties.namespace = SVG_NAMESPACE; - var attributes = properties.attributes || (properties.attributes = {}) + var attributes = properties.attributes || (properties.attributes = {}); for (var key in properties) { if (!properties.hasOwnProperty(key)) { - continue + continue; } - if (svgAttributes[key] !== true) { - continue + if (!isSVGAttribute(key)) { + continue; } - var value = properties[key] - if (typeof value !== "string" && - typeof value !== "number" && - typeof value !== "boolean" + var value = properties[key]; + + if (typeof value !== 'string' && + typeof value !== 'number' && + typeof value !== 'boolean' ) { - continue + continue; } - attributes[key] = value + attributes[key] = value; } - return h(tagName, properties, children) + return h(tagName, properties, children); } function isChildren(x) { - return typeof x === "string" || Array.isArray(x) + return typeof x === 'string' || isArray(x); } diff --git a/virtual-hyperscript/test/ev-hook.js b/virtual-hyperscript/test/ev-hook.js index 6802aa5c..19d2ed10 100644 --- a/virtual-hyperscript/test/ev-hook.js +++ b/virtual-hyperscript/test/ev-hook.js @@ -1,5 +1,5 @@ var test = require("tape") -var DataSet = require("data-set") +var EvStore = require("ev-store") var h = require("../index.js") var createElement = require("../../vdom/create-element") @@ -17,7 +17,7 @@ test("h with events", function (assert) { var elem = createElement(left) - var ds1 = DataSet(elem) + var ds1 = EvStore(elem) assert.ok(ds1) assert.equal(ds1.click, one) @@ -25,7 +25,7 @@ test("h with events", function (assert) { patch(elem, patches) - var ds2 = DataSet(elem) + var ds2 = EvStore(elem) assert.ok(ds2) assert.equal(ds1, ds2) assert.equal(ds2.click, undefined) diff --git a/virtual-hyperscript/test/h.js b/virtual-hyperscript/test/h.js index bfc7c860..d37dca01 100644 --- a/virtual-hyperscript/test/h.js +++ b/virtual-hyperscript/test/h.js @@ -1,5 +1,5 @@ var test = require("tape") -var DataSet = require("data-set") +var EvStore = require('ev-store') var h = require("../index") @@ -49,18 +49,6 @@ test("h with key", function (assert) { assert.end() }) -test("h with data-", function (assert) { - var node = h("div", { "data-foo": "bar" }) - - assert.ok(node.properties["data-foo"]) - - var hook = node.properties["data-foo"] - var elem = {} - hook.hook(elem, "data-foo") - assert.equal(DataSet(elem).foo, "bar") - - assert.end() -}) test("h with ev-", function (assert) { var node = h("div", { "ev-foo": "bar" }) @@ -70,7 +58,7 @@ test("h with ev-", function (assert) { var hook = node.properties["ev-foo"] var elem = {} hook.hook(elem, "ev-foo") - assert.equal(DataSet(elem).foo, "bar") + assert.equal(EvStore(elem).foo, "bar") assert.end() }) @@ -124,12 +112,27 @@ test("h with undefined", function (assert) { }) test("h with foreign object", function (assert) { - assert.throws(function () { + var errorSingleChild + + try { h("div", null, { foreign: "object" }) - }, /Unexpected virtual child/) - assert.throws(function () { + } catch (e) { + errorSingleChild = e + } + + var errorChildren + + try { h("div", [{ foreign: "object" }]) - }, /Unexpected virtual child/) + } catch (e) { + errorChildren = e + } + + assert.ok(errorSingleChild); + assert.ok(/Unexpected virtual child/.test(errorSingleChild.message)) + + assert.ok(errorChildren); + assert.ok(/Unexpected virtual child/.test(errorChildren.message)) assert.end() })