From f2b2e5453b822a463987737e226b7b0c9014e12a Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Mon, 24 Nov 2014 16:50:21 +0200 Subject: [PATCH 1/5] Fix typo In the TOC link title, "auto-redrawing-works" -> "auto-redrawing works" --- docs/mithril.computation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/mithril.computation.md b/docs/mithril.computation.md index b625e34e..b7c7d2d9 100644 --- a/docs/mithril.computation.md +++ b/docs/mithril.computation.md @@ -2,7 +2,7 @@ --- -- [How auto-redrawing-works](#how-auto-redrawing-works) +- [How auto-redrawing works](#how-auto-redrawing-works) - [Integrating multiple execution threads](#integrating-multiple-execution-threads) - [Integrating to legacy code](#integrating-to-legacy-code) - [Signature](#signature) @@ -242,4 +242,4 @@ void startComputation() ```clike void endComputation() -``` \ No newline at end of file +``` From 83bc89f188002cdf5a0c855603a34d552ac8a9f3 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Mon, 24 Nov 2014 10:01:54 -0500 Subject: [PATCH 2/5] #355 prevent interop problem w/ QUnit + requireJS --- mithril.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mithril.js b/mithril.js index 7a5d5a93..254d7526 100644 --- a/mithril.js +++ b/mithril.js @@ -974,5 +974,5 @@ Mithril = m = new function app(window, undefined) { return m }(typeof window != "undefined" ? window : {}); -if (typeof module != "undefined" && module !== null) module.exports = m; +if (typeof module != "undefined" && module !== null && module.exports) module.exports = m; if (typeof define == "function" && define.amd) define(function() {return m}); From 6ef1f8ae2e2cda14ceadcac7581e8d2df5ea72de Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Tue, 25 Nov 2014 19:36:25 -0500 Subject: [PATCH 3/5] don't duplicate route args when redirecting #352 --- mithril.js | 19 ++++++++++++------- tests/mithril-tests.js | 26 +++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/mithril.js b/mithril.js index 254d7526..8a17d522 100644 --- a/mithril.js +++ b/mithril.js @@ -1,4 +1,4 @@ -Mithril = m = new function app(window, undefined) { +var m = (function app(window, undefined) { var OBJECT = "[object Object]", ARRAY = "[object Array]", STRING = "[object String]", FUNCTION = "function"; var type = {}.toString; var parser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g, attrParser = /\[(.+?)(?:=("|'|)(.*?)\2)?\]/; @@ -581,11 +581,16 @@ Mithril = m = new function app(window, undefined) { element.removeEventListener("click", routeUnobtrusive); element.addEventListener("click", routeUnobtrusive) } - //m.route(route) + //m.route(route, params) else if (type.call(arguments[0]) == STRING) { currentRoute = arguments[0]; - var querystring = arguments[1] != null && type.call(arguments[1]) == OBJECT ? buildQueryString(arguments[1]) : null; - if (querystring) currentRoute += (currentRoute.indexOf("?") === -1 ? "?" : "&") + querystring; + var args = arguments[1] || {} + var queryIndex = currentRoute.indexOf("?") + var params = queryIndex > -1 ? parseQueryString(currentRoute.slice(queryIndex + 1)) : {} + for (var i in args) params[i] = args[i] + var querystring = buildQueryString(params) + var currentPath = queryIndex > -1 ? currentRoute.slice(0, queryIndex) : currentRoute + if (querystring) currentRoute = currentPath + (currentPath.indexOf("?") === -1 ? "?" : "&") + querystring; var shouldReplaceHistoryEntry = (arguments.length == 3 ? arguments[2] : arguments[1]) === true; @@ -655,7 +660,7 @@ Mithril = m = new function app(window, undefined) { var pairs = str.split("&"), params = {}; for (var i = 0; i < pairs.length; i++) { var pair = pairs[i].split("="); - params[decodeSpace(pair[0])] = pair[1] ? decodeSpace(pair[1]) : (pair.length === 1 ? true : "") + params[decodeSpace(pair[0])] = pair[1] ? decodeSpace(pair[1]) : "" } return params } @@ -972,7 +977,7 @@ Mithril = m = new function app(window, undefined) { m.deps.factory = app; return m -}(typeof window != "undefined" ? window : {}); +})(typeof window != "undefined" ? window : {}); if (typeof module != "undefined" && module !== null && module.exports) module.exports = m; -if (typeof define == "function" && define.amd) define(function() {return m}); +else if (typeof define == "function" && define.amd) define(function() {return m}); diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 6b3212d5..4160d24b 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -1063,7 +1063,7 @@ function testMithril(mock) { mock.requestAnimationFrame.$resolve() m.route("/test14?test&test2=") mock.requestAnimationFrame.$resolve() //teardown - return mock.location.search == "?/test14?test&test2=" && m.route.param("test") === true && m.route.param("test2") === "" + return mock.location.search == "?/test14?test=&test2=" && m.route.param("test") === "" && m.route.param("test2") === "" }) test(function() { mock.requestAnimationFrame.$resolve() //setup @@ -1597,6 +1597,30 @@ function testMithril(mock) { return root.childNodes[0].nodeValue == "b" }) + test(function() { + mock.requestAnimationFrame.$resolve() + mock.location.search = "?" + + var root = mock.document.createElement("div") + + var a = {} + a.controller = function() { + m.route("/b?foo=1", {foo: 2}) + } + a.view = function() {return "a"} + + var b = {} + b.controller = function() {} + b.view = function() {return "b"} + + m.route(root, "/", { + "/": a, + "/b": b, + }) + mock.requestAnimationFrame.$resolve() + + return mock.location.search == "?/b?foo=2" + }) //end m.route //m.prop From 76aaa782d0feefb479d7e92e24f1e473d4bb72e0 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Tue, 25 Nov 2014 19:46:50 -0500 Subject: [PATCH 4/5] #358 ignore potential meaningless error --- mithril.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mithril.js b/mithril.js index 8a17d522..491b63f3 100644 --- a/mithril.js +++ b/mithril.js @@ -363,7 +363,8 @@ var m = (function app(window, undefined) { function clear(nodes, cached) { for (var i = nodes.length - 1; i > -1; i--) { if (nodes[i] && nodes[i].parentNode) { - nodes[i].parentNode.removeChild(nodes[i]); + try {nodes[i].parentNode.removeChild(nodes[i])} + catch (e) {} //ignore if this fails due to order of events (see http://stackoverflow.com/questions/21926083/failed-to-execute-removechild-on-node) cached = [].concat(cached); if (cached[i]) unload(cached[i]) } From 49e325d9e7b02e8f9a3333461531b32eae013c29 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Tue, 25 Nov 2014 19:47:06 -0500 Subject: [PATCH 5/5] remove section about global namespace --- docs/practices.md | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/docs/practices.md b/docs/practices.md index 172531b3..71545a82 100644 --- a/docs/practices.md +++ b/docs/practices.md @@ -68,32 +68,6 @@ That organization pattern needlessly ties unrelated aspects of the application t --- -## Global Namespace Hygiene - -For developer convenience, Mithril uses the global `m` variable as a namespace, much like jQuery uses `$`. - -If you want to ensure global namespace hygiene, you can wrap your code in "islands" like this: - -```javascript -new function(m) { - - //your code goes here - -}(Mithril); -``` - -If you are creating components to be used by 3rd parties, it's recommended that you always use this idiom. - -In the unlikely case that you have another global variable called `m` in your page, you should consider renaming it to make it more descriptive, or use the idiom below to keep it intact. - -```markup - - - -``` - ---- - ## Usage of m.redraw `m.redraw` is a method that allows you to render a template outside the scope of Mithril's auto-redrawing system.