Merge pull request #1452 from pygy/rrrouter

[rewrite: api/router] Misc router fixes
This commit is contained in:
Leo Horie 2016-12-04 23:31:04 -05:00 committed by GitHub
commit 9a6a4dddc4
2 changed files with 26 additions and 20 deletions

View file

@ -15,7 +15,7 @@ module.exports = function($window, redrawService) {
current.component = component current.component = component
current.path = path current.path = path
current.resolve = null current.resolve = null
redrawService.render(root, current.render(Vnode(component, undefined, params))) redrawService.render(root, current.render.call(resolver, Vnode(component, undefined, params)))
} }
var run = routeService.defineRoutes(routes, function(component, params, path, route, isAction) { var run = routeService.defineRoutes(routes, function(component, params, path, route, isAction) {
if (component.view) render({}, component, params, path) if (component.view) render({}, component, params, path)
@ -27,7 +27,7 @@ module.exports = function($window, redrawService) {
render(component, resolved, params, path) render(component, resolved, params, path)
} }
component.onmatch(function(resolved) { component.onmatch(function(resolved) {
if (current.path !== path && current.resolve != null) current.resolve(resolved) if (current.resolve != null) current.resolve(resolved)
}, params, path) }, params, path)
} }
} }

View file

@ -238,25 +238,28 @@ o.spec("route", function() {
} }
} }
var resolver = {
onmatch: function(resolve, args, requestedPath) {
matchCount++
o(args.id).equals("abc")
o(requestedPath).equals("/abc")
o(this).equals(resolver)
resolve(Component)
},
render: function(vnode) {
renderCount++
o(vnode.attrs.id).equals("abc")
o(this).equals(resolver)
return vnode
},
}
$window.location.href = prefix + "/abc" $window.location.href = prefix + "/abc"
route(root, "/abc", { route(root, "/abc", {
"/:id" : { "/:id" : resolver
onmatch: function(resolve, args, requestedPath) {
matchCount++
o(args.id).equals("abc")
o(requestedPath).equals("/abc")
resolve(Component)
},
render: function(vnode) {
renderCount++
o(vnode.attrs.id).equals("abc")
return vnode
},
},
}) })
o(matchCount).equals(1) o(matchCount).equals(1)
@ -514,21 +517,24 @@ o.spec("route", function() {
o("m.route.set(m.route.get()) re-runs the resolution logic (#1180)", function(done){ o("m.route.set(m.route.get()) re-runs the resolution logic (#1180)", function(done){
var onmatch = o.spy(function(resolve) {resolve()}) var onmatch = o.spy(function(resolve) {resolve()})
var render = o.spy(function(){return m("div")})
$window.location.href = prefix + "/" $window.location.href = prefix + "/"
route(root, '/', { route(root, '/', {
"/":{ "/":{
onmatch: onmatch, onmatch: onmatch,
render: function(){return m("div")} render: render
} }
}) })
o(onmatch.callCount).equals(1) o(onmatch.callCount).equals(1)
o(render.callCount).equals(1)
route.set(route.get()) route.set(route.get())
setTimeout(function() { setTimeout(function() {
o(onmatch.callCount).equals(2) o(onmatch.callCount).equals(2)
o(render.callCount).equals(2)
done() done()
}, FRAME_BUDGET) }, FRAME_BUDGET)