From 7e88af0820b1a3848070963dfd49a1600bd31d56 Mon Sep 17 00:00:00 2001 From: Dominik Dumaine Date: Sun, 7 Feb 2016 18:20:56 +1100 Subject: [PATCH 1/8] Amending template converter Switching to @arthurclemens modified template converter --- docs/tools.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tools.md b/docs/tools.md index a0c0ae76..f7634a70 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -4,7 +4,7 @@ If you already have your HTML written and want to convert it into a Mithril template, you can use the tool below for one-off manual conversion. -[Template Converter](tools/template-converter.html) +[Template Converter](http://arthurclemens.github.io/mithril-template-converter/index.html) --- From 6e60ed5720c6c3e5d6c5c044854c50307698b9c9 Mon Sep 17 00:00:00 2001 From: Barney Carroll Date: Sun, 7 Feb 2016 19:20:31 +0000 Subject: [PATCH 2/8] "Currently active component" is ambiguous at best It seems this condition is put here to reassure users that redrawing in a given route state will not draw the views of components for other routes, but it's difficult to imagine how somebody might worry that might happen. As it is, people end up believing that redraw acts per-component, which is highly misleading in a situation where there are nested components or multiple mount points, and the call to redraw is invoked within one of those components. --- docs/mithril.redraw.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/mithril.redraw.md b/docs/mithril.redraw.md index ee0f0e51..d69c9b3d 100644 --- a/docs/mithril.redraw.md +++ b/docs/mithril.redraw.md @@ -10,7 +10,7 @@ --- -Redraws the view for the currently active component. Use [`m.mount()`](mithril.mount.md) or [`m.route()`](mithril.route.md) to activate a component. +Redraws the view. Use [`m.mount()`](mithril.mount.md) or [`m.route()`](mithril.route.md) to activate a component. Calling `m.redraw` triggers a redraw regardless of whether AJAX requests (and other asynchronous services) are completed. Therefore, you should ensure that templates have null checks in place to account for the possibility of variables being uninitialized when the forced redraw occurs. From 42d756ea74aa89230b3f95bf8c791697be1ee7d8 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Mon, 8 Feb 2016 10:28:51 -0500 Subject: [PATCH 3/8] change link to Arthur Clemens' template compiler --- docs/tools.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tools.md b/docs/tools.md index a0c0ae76..f7634a70 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -4,7 +4,7 @@ If you already have your HTML written and want to convert it into a Mithril template, you can use the tool below for one-off manual conversion. -[Template Converter](tools/template-converter.html) +[Template Converter](http://arthurclemens.github.io/mithril-template-converter/index.html) --- From 7a184cb3b7f7bb992de6522808ca1c3dd37c9e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=CC=81r=20O=CC=88rlygsson?= Date: Thu, 18 Feb 2016 18:42:26 +0000 Subject: [PATCH 4/8] Use RegExp#test instead of String#match Using `.test()` is both faster and more explicit. --- mithril.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mithril.js b/mithril.js index d023ac34..7d3721c8 100644 --- a/mithril.js +++ b/mithril.js @@ -456,7 +456,7 @@ nodes = injectHTML(parentElement, index, data) } else { nodes = [$document.createTextNode(data)] - if (!parentElement.nodeName.match(voidElements)) { + if (!voidElements.test(parentElement.nodeName)) { insertNode(parentElement, nodes[0], index) } } @@ -1902,7 +1902,7 @@ m.deferred.onerror = function (e) { if (type.call(e) === "[object Error]" && - !e.constructor.toString().match(/ Error/)) { + !/ Error/.test(e.constructor.toString())) { pendingRequests = 0 throw e } From 74062cda29ccf1e161b3a9f415bc9ed4592eca39 Mon Sep 17 00:00:00 2001 From: mar Date: Thu, 18 Feb 2016 18:53:45 +0000 Subject: [PATCH 5/8] Parameterize URLs with a single String#replace --- mithril.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mithril.js b/mithril.js index 7d3721c8..5106d3b7 100644 --- a/mithril.js +++ b/mithril.js @@ -2048,16 +2048,14 @@ } function parameterizeUrl(url, data) { - var tokens = url.match(/:[a-z]\w+/gi) - - if (tokens && data) { - forEach(tokens, function (token) { + if (data) { + url = url.replace(/:[a-z]\w+/gi, function(token){ var key = token.slice(1) - url = url.replace(token, data[key]) + var value = data[key] delete data[key] + return value }) } - return url } From 3e4af6ff221947dd5bc244cbf08c5beac37af624 Mon Sep 17 00:00:00 2001 From: mar Date: Thu, 18 Feb 2016 19:08:07 +0000 Subject: [PATCH 6/8] Use Array#slice to convert arguments to Array --- mithril.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mithril.js b/mithril.js index 5106d3b7..e30f9cae 100644 --- a/mithril.js +++ b/mithril.js @@ -126,9 +126,7 @@ * or splat (optional) */ function m(tag, pairs) { - for (var args = [], i = 1; i < arguments.length; i++) { - args[i - 1] = arguments[i] - } + var args = [].slice.call(arguments, 1) if (isObject(tag)) return parameterize(tag, args) @@ -1298,9 +1296,7 @@ } m.component = function (component) { - for (var args = [], i = 1; i < arguments.length; i++) { - args.push(arguments[i]) - } + var args = [].slice.call(arguments, 1) return parameterize(component, args) } From 01ff1a36fd40199505d816752f09151256a75739 Mon Sep 17 00:00:00 2001 From: mar Date: Thu, 18 Feb 2016 19:47:38 +0000 Subject: [PATCH 7/8] Use object lookup instead of long RegExp Should be faster. --- mithril.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/mithril.js b/mithril.js index e30f9cae..01896d7c 100644 --- a/mithril.js +++ b/mithril.js @@ -38,9 +38,24 @@ function noop() {} - /* eslint-disable max-len */ - var voidElements = /^(AREA|BASE|BR|COL|COMMAND|EMBED|HR|IMG|INPUT|KEYGEN|LINK|META|PARAM|SOURCE|TRACK|WBR)$/ - /* eslint-enable max-len */ + var voidElements = { + AREA: 1, + BASE: 1, + BR: 1, + COL: 1, + COMMAND: 1, + EMBED: 1, + HR: 1, + IMG: 1, + INPUT: 1, + KEYGEN: 1, + LINK: 1, + META: 1, + PARAM: 1, + SOURCE: 1, + TRACK: 1, + WBR: 1 + } // caching commonly used variables var $document, $location, $requestAnimationFrame, $cancelAnimationFrame @@ -454,7 +469,7 @@ nodes = injectHTML(parentElement, index, data) } else { nodes = [$document.createTextNode(data)] - if (!voidElements.test(parentElement.nodeName)) { + if (!(parentElement.nodeName in voidElements)) { insertNode(parentElement, nodes[0], index) } } From 3f097135832fdb58301e825923ead04d2feeed32 Mon Sep 17 00:00:00 2001 From: mar Date: Thu, 18 Feb 2016 19:52:39 +0000 Subject: [PATCH 8/8] Use object lookup instead of long condition chain --- mithril.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mithril.js b/mithril.js index 01896d7c..30cf3714 100644 --- a/mithril.js +++ b/mithril.js @@ -983,13 +983,13 @@ } } - function shouldUseSetAttribute(attrName) { - return attrName !== "list" && - attrName !== "style" && - attrName !== "form" && - attrName !== "type" && - attrName !== "width" && - attrName !== "height" + var shouldUseSetAttribute = { + list: 1, + style: 1, + form: 1, + type: 1, + width: 1, + height: 1 } function setSingleAttr( @@ -1020,7 +1020,7 @@ attrName === "className" ? "class" : attrName, dataAttr) } - } else if (attrName in node && shouldUseSetAttribute(attrName)) { + } else if (attrName in node && !shouldUseSetAttribute[attrName]) { // handle cases that are properties (but ignore cases where we // should use setAttribute instead) //