From 1dec7eb3f6e4e30445031c74b0ac9dd2fd2f37d5 Mon Sep 17 00:00:00 2001 From: Bryce Gibson Date: Tue, 3 Jan 2017 19:04:01 +1100 Subject: [PATCH 01/12] Use process.nextTick if available to reduce stack size. --- ospec/ospec.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ospec/ospec.js b/ospec/ospec.js index 56111b66..3f9e5ec4 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -1,7 +1,7 @@ "use strict" module.exports = new function init() { - var spec = {}, subjects = [], results = [], only = null, ctx = spec, start, stack = 0, hasProcess = typeof process === "object" + var spec = {}, subjects = [], results = [], only = null, ctx = spec, start, stack = 0, nextTickish, hasProcess = typeof process === "object" function o(subject, predicate) { ctx[subject] = predicate @@ -67,7 +67,6 @@ module.exports = new function init() { next() function next() { - stack++ if (cursor === fns.length) return var fn = fns[cursor++] @@ -104,8 +103,7 @@ module.exports = new function init() { } else { fn() - if (stack < 5000) next() - else (hasProcess ? process.nextTick : setTimeout)(next, stack = 0) + nextTickish(next) } } } @@ -211,5 +209,14 @@ module.exports = new function init() { if (hasProcess && status === 1) process.exit(1) } + if(hasProcess) { + nextTickish = process.nextTick + } else { + nextTickish = function fakeFastNextTick(fn) { + if (stack++ < 5000) next() + else setTimeout(next, stack = 0) + } + } + return o } From f13561e200c3565398b395b3c0a06c62b96f24df Mon Sep 17 00:00:00 2001 From: Pierre-Yves Gerardy Date: Sun, 8 Jan 2017 21:06:35 +0100 Subject: [PATCH 02/12] [ospec] Improve the dupe detection code --- ospec/ospec.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/ospec/ospec.js b/ospec/ospec.js index 96a09ebe..d7ea1f2f 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -4,9 +4,8 @@ module.exports = new function init() { var spec = {}, subjects = [], results = [], only = null, ctx = spec, start, stack = 0, hasProcess = typeof process === "object" function o(subject, predicate) { - subject = unique(subject, predicate) - ctx[subject] = predicate if (predicate === undefined) return new Assert(subject) + ctx[unique(subject)] = predicate } o.before = hook("__before") o.after = hook("__after") @@ -15,8 +14,7 @@ module.exports = new function init() { o.new = init o.spec = function(subject, predicate) { var parent = ctx - subject = unique(subject, predicate) - ctx = ctx[subject] = {} + ctx = ctx[unique(subject)] = {} predicate() ctx = parent } @@ -77,7 +75,7 @@ module.exports = new function init() { var timeout = 0, delay = 200, s = new Date var isDone = false var body = fn.toString() - var arg = (body.match(/\(([\w_$]+)/) || body.match(/([\w_$]+)\s*=>/) || []).pop() + var arg = (body.match(/\(([\w$]+)/) || body.match(/([\w$]+)\s*=>/) || []).pop() if (body.indexOf(arg) === body.lastIndexOf(arg)) throw new Error("`" + arg + "()` should be called at least once") try { fn(function done() { @@ -112,12 +110,15 @@ module.exports = new function init() { } } } - function unique(subject, predicate) { - if (ctx.hasOwnProperty(subject) && predicate) { - console.warn("A test named `" + subject + "` was already defined") - subject = subject + "*" + var dedupeCounter = 0 + function unique(subject) { + var res = subject + if (ctx.hasOwnProperty(subject)) { + console.warn("A test or a spec named `" + subject + "` was already defined") + while (ctx.hasOwnProperty(res)) res = subject + ' (' + ++dedupeCounter + ')' + dedupeCounter = 0 } - return subject + return res } function hook(name) { return function(predicate) { From a7ea060a6402cca9704ae4cb04342fff1609bc93 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Gerardy Date: Mon, 9 Jan 2017 10:16:53 +0100 Subject: [PATCH 03/12] [ospec] Add `hasOwn` shortcut --- ospec/ospec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ospec/ospec.js b/ospec/ospec.js index d7ea1f2f..eb11629c 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -1,7 +1,7 @@ "use strict" module.exports = new function init() { - var spec = {}, subjects = [], results = [], only = null, ctx = spec, start, stack = 0, hasProcess = typeof process === "object" + var spec = {}, subjects = [], results = [], only = null, ctx = spec, start, stack = 0, hasProcess = typeof process === "object", hasOwn = ({}).hasOwnProperty function o(subject, predicate) { if (predicate === undefined) return new Assert(subject) @@ -156,7 +156,7 @@ module.exports = new function init() { var aKeys = Object.getOwnPropertyNames(a), bKeys = Object.getOwnPropertyNames(b) if (aKeys.length !== bKeys.length) return false for (var i = 0; i < aKeys.length; i++) { - if (!b.hasOwnProperty(aKeys[i]) || !deepEqual(a[aKeys[i]], b[aKeys[i]])) return false + if (!hasOwn.call(b, aKeys[i]) || !deepEqual(a[aKeys[i]], b[aKeys[i]])) return false } return true } From 396a7ff4e4b84a6909ab090c9bfe5ab2829eaf9d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Gerardy Date: Mon, 9 Jan 2017 10:17:38 +0100 Subject: [PATCH 04/12] [ospec] Simplify the dupe checker --- ospec/ospec.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ospec/ospec.js b/ospec/ospec.js index eb11629c..05b64f98 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -110,15 +110,12 @@ module.exports = new function init() { } } } - var dedupeCounter = 0 function unique(subject) { - var res = subject - if (ctx.hasOwnProperty(subject)) { + if (hasOwn.call(ctx, subject)) { console.warn("A test or a spec named `" + subject + "` was already defined") - while (ctx.hasOwnProperty(res)) res = subject + ' (' + ++dedupeCounter + ')' - dedupeCounter = 0 + while (hasOwn.call(ctx, subject)) subject += '*' } - return res + return subject } function hook(name) { return function(predicate) { From 506f0b61a6a5aa4294644b3b9ec775bb19437e7a Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Mon, 9 Jan 2017 08:14:03 -0500 Subject: [PATCH 05/12] improve docs on redraw semantics --- docs/redraw.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/redraw.md b/docs/redraw.md index 9fe72feb..be215e18 100644 --- a/docs/redraw.md +++ b/docs/redraw.md @@ -14,7 +14,7 @@ You DON'T need to call it if data is modified within the execution context of an You DO need to call it in `setTimeout`/`setInterval`/`requestAnimationFrame` callbacks, or callbacks from 3rd party libraries. -Typically, `m.redraw` triggers an asynchronous redraws, but it may trigger synchronously if Mithril detects it's possible to improves performance by doing so. You should write code assuming that it always redraws asynchronously. +Typically, `m.redraw` triggers an asynchronous redraws, but it may trigger synchronously if Mithril detects it's possible to improves performance by doing so (i.e. if no redraw was requested within the last animation frame). You should write code assuming that it always redraws asynchronously. --- From 7980cbe0a03a38f913113f3c466dc9de7d23e8da Mon Sep 17 00:00:00 2001 From: Barney Carroll Date: Mon, 9 Jan 2017 13:30:29 +0000 Subject: [PATCH 06/12] Specify JSON code blocks in ES6 documentation --- docs/es6.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/es6.md b/docs/es6.md index 3ab05040..2f629223 100644 --- a/docs/es6.md +++ b/docs/es6.md @@ -29,7 +29,7 @@ npm install babel-cli babel-preset-es2015 babel-plugin-transform-react-jsx --sav Create a `.babelrc` file: -``` +```json { "presets": ["es2015"], "plugins": [ @@ -56,7 +56,7 @@ npm install babel-core babel-loader babel-preset-es2015 babel-plugin-transform-r Create a `.babelrc` file: -``` +```json { "presets": ["es2015"], "plugins": [ @@ -90,7 +90,7 @@ This configuration assumes the source code file for the application entry point To run the bundler, setup an npm script. Open `package.json` and add this entry under `"scripts"`: -``` +```json { "name": "my-project", "scripts": { @@ -109,7 +109,7 @@ npm start To generate a minified file, open `package.json` and add a new npm script called `build`: -``` +```json { "name": "my-project", "scripts": { @@ -121,7 +121,7 @@ To generate a minified file, open `package.json` and add a new npm script called You can use hooks in your production environment to run the production build script automatically. Here's an example for [Heroku](https://www.heroku.com/): -``` +```json { "name": "my-project", "scripts": { From 134a3121ccc92a64681de7124e4894f928fa548a Mon Sep 17 00:00:00 2001 From: Barney Carroll Date: Mon, 9 Jan 2017 13:32:54 +0000 Subject: [PATCH 07/12] Use HTML / JSX as appropriate instead of 'markup' --- docs/introduction.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/introduction.md b/docs/introduction.md index 671541e5..217395dd 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -27,7 +27,7 @@ The easiest way to try out Mithril is to include it from a CDN, and follow this Let's create an HTML file to follow along: -```markup +```html