reset m.route.param correctly on route change

This commit is contained in:
Leo Horie 2014-03-20 11:18:40 -04:00
parent 4cc123e01d
commit 83f497e129
4 changed files with 51 additions and 3 deletions

View file

@ -258,6 +258,7 @@ new function(window) {
m.route.param = function(key) {return routeParams[key]}
m.route.mode = "search"
function routeByValue(root, router, path) {
routeParams = {}
for (var route in router) {
if (route == path) return !void m.module(root, router[route])
@ -266,7 +267,6 @@ new function(window) {
return !void path.replace(matcher, function() {
var keys = route.match(/:[^\/]+/g)
var values = [].slice.call(arguments, 1, -2)
routeParams = {}
for (var i = 0; i < keys.length; i++) routeParams[keys[i].slice(1)] = values[i]
m.module(root, router[route])
})
@ -656,6 +656,23 @@ function testMithril(mock) {
})
return mock.location.search == "?/test4/foo" && root.childNodes[0].nodeValue === "foo"
})
test(function() {
mock.performance.$elapse(50)
var module = {controller: function() {}, view: function() {return m.route.param("test")}}
var root = mock.document.createElement("div")
m.route.mode = "search"
m.route(root, "/test5/foo", {
"/": module,
"/test5/:test": module
})
var paramValueBefore = m.route.param("test")
m.route("/")
var paramValueAfter = m.route.param("test")
return mock.location.search == "?/" && paramValueBefore === "foo" && paramValueAfter === undefined
})
//m.prop
test(function() {

View file

@ -2,8 +2,22 @@
[v0.1.1](/archive/v0.1.1) - maintenance
### Bug Fixes:
- `m.route.param` now resets on route change correctly [#15](https://github.com/lhorie/mithril.js/issues/15)
### Breaking changes:
- changed default value for `xhr.withCredentials` from `true` to `false` for `m.request`, since public APIs are more common than auth-walled ones
- changed default value for `xhr.withCredentials` from `true` to `false` for `m.request`, since public APIs are more common than auth-walled ones. [#14](https://github.com/lhorie/mithril.js/issues/14)
In order to configure this flag, the following configuration should be used:
```javascript
var privateAPI = function(xhr) {xhr.withCredentials = true};
m.request({method: "GET", url: "/foo", config: privateAPI});
```
---
[v0.1](/archive/v0.1) - Initial release

View file

@ -258,6 +258,7 @@ new function(window) {
m.route.param = function(key) {return routeParams[key]}
m.route.mode = "search"
function routeByValue(root, router, path) {
routeParams = {}
for (var route in router) {
if (route == path) return !void m.module(root, router[route])
@ -266,7 +267,6 @@ new function(window) {
return !void path.replace(matcher, function() {
var keys = route.match(/:[^\/]+/g)
var values = [].slice.call(arguments, 1, -2)
routeParams = {}
for (var i = 0; i < keys.length; i++) routeParams[keys[i].slice(1)] = values[i]
m.module(root, router[route])
})

View file

@ -153,6 +153,23 @@ function testMithril(mock) {
})
return mock.location.search == "?/test4/foo" && root.childNodes[0].nodeValue === "foo"
})
test(function() {
mock.performance.$elapse(50)
var module = {controller: function() {}, view: function() {return m.route.param("test")}}
var root = mock.document.createElement("div")
m.route.mode = "search"
m.route(root, "/test5/foo", {
"/": module,
"/test5/:test": module
})
var paramValueBefore = m.route.param("test")
m.route("/")
var paramValueAfter = m.route.param("test")
return mock.location.search == "?/" && paramValueBefore === "foo" && paramValueAfter === undefined
})
//m.prop
test(function() {