From 5080db017fc6c9bca1ce671e5b99a0a396bcb79f Mon Sep 17 00:00:00 2001 From: Andreas Date: Thu, 29 Jan 2015 22:38:03 +0700 Subject: [PATCH 1/4] Fixed context when calling a module view during redraw. --- mithril.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mithril.js b/mithril.js index f1da83f6..9c08b826 100644 --- a/mithril.js +++ b/mithril.js @@ -542,7 +542,7 @@ var m = (function app(window, undefined) { var forceRedraw = m.redraw.strategy() === "all"; for (var i = 0, root; root = roots[i]; i++) { if (controllers[i]) { - m.render(root, (modules[i].view || blank)(controllers[i]), forceRedraw) + m.render(root, modules[i].view ? modules[i].view(controllers[i]) : blank(), forceRedraw) } } //after rendering within a routed context, we need to scroll back to the top, and fetch the document title for history.pushState From e158b52c477cd308a84390b9616f604df62eb2b2 Mon Sep 17 00:00:00 2001 From: webcss Date: Fri, 30 Jan 2015 11:20:53 +0100 Subject: [PATCH 2/4] fix for #428 introduces new misbehaviour The fix for #428 provided prevents entries beeing written to history. History.back() or hitting browsers back-button don't work anymore, since there are no history entries. This is because you are assigning the new path to route to to currentPath and compare these, which always turn out to be equal. Saving the currentPath before the assignment fixes this missbehaviour. --- mithril.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mithril.js b/mithril.js index f1da83f6..2a0a083d 100644 --- a/mithril.js +++ b/mithril.js @@ -614,6 +614,7 @@ var m = (function app(window, undefined) { } //m.route(route, params) else if (type.call(arguments[0]) === STRING) { + var oldRoute = currentRoute; currentRoute = arguments[0]; var args = arguments[1] || {} var queryIndex = currentRoute.indexOf("?") @@ -623,7 +624,7 @@ var m = (function app(window, undefined) { 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 || currentRoute === arguments[0]; + var shouldReplaceHistoryEntry = (arguments.length === 3 ? arguments[2] : arguments[1]) === true || oldRoute === arguments[0]; if (window.history.pushState) { computePostRedrawHook = function() { From 0cd1c4e5bfb39994877643c3509ef3fff1d13b6a Mon Sep 17 00:00:00 2001 From: Liam Curry Date: Sun, 1 Feb 2015 00:59:46 -0700 Subject: [PATCH 3/4] Small change to example code --- docs/mithril.deferred.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/mithril.deferred.md b/docs/mithril.deferred.md index 4b90ea01..69120a21 100644 --- a/docs/mithril.deferred.md +++ b/docs/mithril.deferred.md @@ -163,7 +163,7 @@ The other side of the coin is still supported: if a developer needs to signal an var error = m.prop() m.request({method: "GET", url: "/user/:id", data: {id: 1}}) .then(function(user) { - if (user.isAdmin) throw new Error("Sorry, you don't have permissions") + if (!user.isAdmin) throw new Error("Sorry, you don't have permissions") }) .then(null, error) //handle the application error: bind to a getter-setter for diplaying it on the template ``` @@ -249,4 +249,4 @@ where: **void onerror(Error e)** - This method gets called every time an exception is thrown inside a promise callback. By default, it rethrows to the console if an error is a subclass of Error (but not an instance of Error itself). Otherwise it follows the Promises/A+ specifications. \ No newline at end of file + This method gets called every time an exception is thrown inside a promise callback. By default, it rethrows to the console if an error is a subclass of Error (but not an instance of Error itself). Otherwise it follows the Promises/A+ specifications. From da4ef441fdb4f96b5872fb6d246f08d3e3ee1e16 Mon Sep 17 00:00:00 2001 From: Shlomo Dalezman Date: Mon, 2 Feb 2015 13:38:12 -0500 Subject: [PATCH 4/4] added multi argument brackets --- mithril.js | 2 +- tests/mithril-tests.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mithril.js b/mithril.js index 59ffc113..29082ca9 100644 --- a/mithril.js +++ b/mithril.js @@ -693,7 +693,7 @@ var m = (function app(window, undefined) { var pair = value != null && (valueType === OBJECT) ? buildQueryString(value, key) : valueType === ARRAY ? - value.map(function(item) {return encodeURIComponent(key) + "=" + encodeURIComponent(item)}).join("&") : + value.map(function(item) {return encodeURIComponent(key + "[]") + "=" + encodeURIComponent(item)}).join("&") : encodeURIComponent(key) + "=" + encodeURIComponent(value) str.push(pair) } diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 2b3ce839..ca7b21de 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -1799,7 +1799,7 @@ function testMithril(mock) { test(function() { var prop = m.request({method: "GET", url: "test", data: {foo: [1, 2]}}) mock.XMLHttpRequest.$instances.pop().onreadystatechange() - return prop().url === "test?foo=1&foo=2" + return prop().url === "test?foo%5B%5D=1&foo%5B%5D=2" }) // m.request over jsonp