prevent race condition between route.set and async resolve

remove path and route from attrs
This commit is contained in:
Leo Horie 2016-08-26 00:56:01 -04:00
parent a1a087c4be
commit 00d555b9f4
2 changed files with 34 additions and 10 deletions

View file

@ -240,8 +240,7 @@ o.spec("route", function() {
matchCount++
o(vnode.attrs.id).equals("abc")
o(vnode.attrs.path).equals("/abc")
o(vnode.attrs.route).equals("/:id")
o(route.get()).equals("/abc")
resolve(Component)
},
@ -279,8 +278,7 @@ o.spec("route", function() {
matchCount++
o(vnode.attrs.id).equals("abc")
o(vnode.attrs.path).equals("/abc")
o(vnode.attrs.route).equals("/:id")
o(route.get()).equals("/abc")
resolve(Component)
},
@ -457,7 +455,7 @@ o.spec("route", function() {
$window.location.href = prefix + "/"
route(root, "/", {
"/" : {
"/": {
onmatch: function(vnode, resolve) {
resolve(A)
resolve(B)
@ -476,6 +474,33 @@ o.spec("route", function() {
done()
}, FRAME_BUDGET)
})
o("calling route.set invalidates pending onmatch resolution", function(done, timeout) {
timeout(100)
var resolved
$window.location.href = prefix + "/"
route(root, "/a", {
"/a": {
onmatch: function(vnode, resolve) {
setTimeout(resolve, 20)
},
render: function(vnode) {resolved = "a"}
},
"/b": {
view: function() {resolved = "b"}
}
})
setTimeout(function() {
route.set("/b")
setTimeout(function() {
o(resolved).equals("b")
done()
}, 30)
}, FRAME_BUDGET)
})
})
})
})