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. diff --git a/mithril.js b/mithril.js index 8b37a750..fe7c23f1 100644 --- a/mithril.js +++ b/mithril.js @@ -568,7 +568,7 @@ var m = (function app(window, undefined) { for (var i = 0, root; root = roots[i]; i++) { if (controllers[i]) { var args = modules[i].controller && modules[i].controller.$$args ? [controllers[i]].concat(modules[i].controller.$$args) : [controllers[i]] - m.render(root, (modules[i].view || blank).apply(modules[i], args), forceRedraw) + m.render(root, modules[i].view ? modules[i].view(controllers[i], args) : blank(), forceRedraw) } } //after rendering within a routed context, we need to scroll back to the top, and fetch the document title for history.pushState @@ -640,6 +640,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("?") @@ -649,7 +650,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() { @@ -718,7 +719,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