From ee6d991e5155ce1fc30ab1f37e08b7b79eb06598 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Gerardy Date: Thu, 19 Jan 2017 15:23:48 +0100 Subject: [PATCH 01/16] [ospec:docs] Document the fact that ospec doesn't work when installed globally --- ospec/README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ospec/README.md b/ospec/README.md index 676be219..8b9c2a79 100644 --- a/ospec/README.md +++ b/ospec/README.md @@ -278,12 +278,20 @@ ospec will automatically evaluate all `*.js` files in any folder named `/tests`. $ npm test ``` -#### Installing ospec globally +#### Direct use from the command line -While it's recommended to install ospec locally to maintain reproducible environments, sometimes it may be deemed appropriate to install it globally. To do so, run this command: +Ospec doesn't work when installed globally. Using global scripts is generally a bad idea since you can end up with different, incompatible versions of the same package installed locally and globally. + +To work around this limitation, you can use [`npm-run`](https://www.npmjs.com/package/npm-run) which enables one to run the binaries of locally installed packages. ``` -npm install ospec -g +npm install npm-run -g +``` + +Then, from a project that has ospec installed as a (dev) dependency: + +``` +npm-run ospec ``` --- From f6e627a8916ac923eb2778a92c07031025ed493f Mon Sep 17 00:00:00 2001 From: Gampol T Date: Thu, 23 Feb 2017 17:45:25 +0700 Subject: [PATCH 02/16] fix state.update not destroy when edit text blank if (state.editing.title === "") should call state.destroy() instead of destroy() --- examples/todomvc/todomvc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/todomvc/todomvc.js b/examples/todomvc/todomvc.js index 1f1f257a..59099cf5 100644 --- a/examples/todomvc/todomvc.js +++ b/examples/todomvc/todomvc.js @@ -38,7 +38,7 @@ var state = { update: function(title) { if (state.editing != null) { state.editing.title = title.trim() - if (state.editing.title === "") destroy(state.editing) + if (state.editing.title === "") state.destroy(state.editing) state.editing = null } }, From 450570d4c9f2bc6da646d357d4fa59bd934f347f Mon Sep 17 00:00:00 2001 From: Gampol T Date: Thu, 23 Feb 2017 17:48:13 +0700 Subject: [PATCH 03/16] fix ui.save not detect escape key change event from onkeypress to onkeyup because onkeypress cannot detect escape key press if (e.keyCode === 27) --- examples/todomvc/todomvc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/todomvc/todomvc.js b/examples/todomvc/todomvc.js index 59099cf5..83d2a822 100644 --- a/examples/todomvc/todomvc.js +++ b/examples/todomvc/todomvc.js @@ -104,7 +104,7 @@ var Todos = { m("label", {ondblclick: function() {state.dispatch("edit", [todo])}}, todo.title), m("button.destroy", {onclick: function() {state.dispatch("destroy", [todo])}}), ]), - m("input.edit", {onupdate: function(vnode) {ui.focus(vnode, todo)}, onkeypress: ui.save, onblur: ui.save}) + m("input.edit", {onupdate: function(vnode) {ui.focus(vnode, todo)}, onkeyup: ui.save, onblur: ui.save}) ]) }), ]), From b34c3eaf82e625a52f7303bba0f338ed080594e0 Mon Sep 17 00:00:00 2001 From: Isiah Meadows Date: Thu, 2 Mar 2017 06:34:01 -0500 Subject: [PATCH 04/16] Optimize memory for selector cache --- render/hyperscript.js | 129 ++++++++++++++++++++++++++---------------- 1 file changed, 80 insertions(+), 49 deletions(-) diff --git a/render/hyperscript.js b/render/hyperscript.js index 1630afce..24151431 100644 --- a/render/hyperscript.js +++ b/render/hyperscript.js @@ -4,66 +4,97 @@ var Vnode = require("../render/vnode") var selectorParser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g var selectorCache = {} +var hasOwn = {}.hasOwnProperty + +function compileSelector(selector) { + var match, tag = "div", classes = [], attrs = {} + while (match = selectorParser.exec(selector)) { + var type = match[1], value = match[2] + if (type === "" && value !== "") tag = value + else if (type === "#") attrs.id = value + else if (type === ".") classes.push(value) + else if (match[3][0] === "[") { + var attrValue = match[6] + if (attrValue) attrValue = attrValue.replace(/\\(["'])/g, "$1").replace(/\\\\/g, "\\") + if (match[4] === "class") classes.push(attrValue) + else attrs[match[4]] = attrValue || true + } + } + if (classes.length > 0) attrs.className = classes.join(" ") + return selectorCache[selector] = {tag: tag, attrs: attrs} +} + +function execSelector(state, attrs, children) { + var hasAttrs = false, childList, text + var className = attrs.className || attrs.class + + for (var key in state.attrs) { + if (hasOwn.call(state.attrs, key)) { + attrs[key] = state.attrs[key] + } + } + + if (className != null) { + if (attrs.class != null) { + attrs.class = undefined + attrs.className = className + } + + if (state.attrs.className != null) { + attrs.className = state.attrs.className + " " + className + } + } + + for (var key in attrs) { + if (hasOwn.call(attrs, key) && key !== "key") { + hasAttrs = true + break + } + } + + if (Array.isArray(children) && children.length === 1 && children[0] != null && children[0].tag === "#") { + text = children[0].children + } else { + childList = children + } + + return Vnode(state.tag, attrs.key, hasAttrs ? attrs : undefined, childList, text) +} + function hyperscript(selector) { + // Because sloppy mode sucks + var attrs = arguments[1], start = 2, children + if (selector == null || typeof selector !== "string" && typeof selector !== "function" && typeof selector.view !== "function") { throw Error("The selector must be either a string or a component."); } - if (typeof selector === "string" && selectorCache[selector] === undefined) { - var match, tag, classes = [], attributes = {} - while (match = selectorParser.exec(selector)) { - var type = match[1], value = match[2] - if (type === "" && value !== "") tag = value - else if (type === "#") attributes.id = value - else if (type === ".") classes.push(value) - else if (match[3][0] === "[") { - var attrValue = match[6] - if (attrValue) attrValue = attrValue.replace(/\\(["'])/g, "$1").replace(/\\\\/g, "\\") - if (match[4] === "class") classes.push(attrValue) - else attributes[match[4]] = attrValue || true - } - } - if (classes.length > 0) attributes.className = classes.join(" ") - selectorCache[selector] = function(attrs, children) { - var hasAttrs = false, childList, text - var className = attrs.className || attrs.class - for (var key in attributes) attrs[key] = attributes[key] - if (className !== undefined) { - if (attrs.class !== undefined) { - attrs.class = undefined - attrs.className = className - } - if (attributes.className !== undefined) attrs.className = attributes.className + " " + className - } - for (var key in attrs) { - if (key !== "key") { - hasAttrs = true - break - } - } - if (Array.isArray(children) && children.length == 1 && children[0] != null && children[0].tag === "#") text = children[0].children - else childList = children + if (typeof selector === "string") { + var cached = selectorCache[selector] || compileSelector(selector) + } - return Vnode(tag || "div", attrs.key, hasAttrs ? attrs : undefined, childList, text, undefined) - } + if (!attrs) { + attrs = {} + } else if (typeof attrs !== "object" || attrs.tag != null || Array.isArray(attrs)) { + attrs = {} + start = 1 } - var attrs, children, childrenIndex - if (arguments[1] == null || typeof arguments[1] === "object" && arguments[1].tag === undefined && !Array.isArray(arguments[1])) { - attrs = arguments[1] - childrenIndex = 2 - } - else childrenIndex = 1 - if (arguments.length === childrenIndex + 1) { - children = Array.isArray(arguments[childrenIndex]) ? arguments[childrenIndex] : [arguments[childrenIndex]] - } - else { + + if (arguments.length === start + 1) { + children = arguments[start] + if (!Array.isArray(children)) children = [children] + } else { children = [] - for (var i = childrenIndex; i < arguments.length; i++) children.push(arguments[i]) + while (start < arguments.length) children.push(arguments[start++]) } - if (typeof selector === "string") return selectorCache[selector](attrs || {}, Vnode.normalizeChildren(children)) + var normalized = Vnode.normalizeChildren(children) - return Vnode(selector, attrs && attrs.key, attrs || {}, Vnode.normalizeChildren(children), undefined, undefined) + if (typeof selector === "string") { + return execSelector(cached, attrs, normalized) + } else { + return Vnode(selector, attrs.key, attrs, normalized) + } } module.exports = hyperscript From 23e4a571146b979eee66b3eb0e402b829f4fa7f8 Mon Sep 17 00:00:00 2001 From: RobertAKARobin Date: Fri, 3 Mar 2017 20:41:29 -0600 Subject: [PATCH 05/16] Put Stream in IIFE so variables aren't global ...when imported into the browser via +``` + +When loaded directly with a ` ``` -When loaded directly with a `