m.route.get() returns the last fully resolved route (fix #1276), change RouteResolver.onmatch() signature according to #1277

This commit is contained in:
Pierre-Yves Gerardy 2016-09-02 22:03:27 +02:00
parent 419897f72c
commit a34685d7a4
2 changed files with 15 additions and 14 deletions

View file

@ -5,7 +5,7 @@ var coreRouter = require("../router/router")
module.exports = function($window, mount) {
var router = coreRouter($window)
var globalId, currentComponent, currentRender, currentArgs
var globalId, currentComponent, currentRender, currentArgs, currentPath
var RouteComponent = {view: function() {
return currentRender(Vnode(currentComponent, null, currentArgs, undefined, undefined, undefined))
@ -32,6 +32,7 @@ module.exports = function($window, mount) {
currentComponent = component != null ? component: isResolver ? "div" : payload
currentRender = render
currentArgs = args
currentPath = path
root.redraw(true)
}
@ -42,8 +43,8 @@ module.exports = function($window, mount) {
if (typeof payload.render === "function") render = payload.render.bind(payload)
if (typeof payload.onmatch === "function") onmatch = payload.onmatch
}
onmatch.call(payload, {attrs: args}, resolve)
onmatch.call(payload, resolve, args, path)
}, function() {
router.setPath(defaultRoute, null, {replace: true})
})
@ -51,7 +52,7 @@ module.exports = function($window, mount) {
route.link = router.link
route.prefix = router.setPrefix
route.set = router.setPath
route.get = router.getPath
route.get = function() {return currentPath}
return route
}

View file

@ -238,11 +238,11 @@ o.spec("route", function() {
$window.location.href = prefix + "/"
route(root, "/abc", {
"/:id" : {
onmatch: function(vnode, resolve) {
onmatch: function(resolve, args, requestedPath) {
matchCount++
o(vnode.attrs.id).equals("abc")
o(route.get()).equals("/abc")
o(args.id).equals("abc")
o(requestedPath).equals("/abc")
resolve(Component)
},
@ -276,11 +276,11 @@ o.spec("route", function() {
$window.location.href = prefix + "/"
route(root, "/abc", {
"/:id" : {
onmatch: function(vnode, resolve) {
onmatch: function(resolve, args, requestedPath) {
matchCount++
o(vnode.attrs.id).equals("abc")
o(route.get()).equals("/abc")
o(args.id).equals("abc")
o(requestedPath).equals("/abc")
resolve(Component)
},
@ -374,7 +374,7 @@ o.spec("route", function() {
$window.location.href = prefix + "/"
route(root, "/", {
"/" : {
onmatch: function(vnode, resolve) {
onmatch: function(resolve) {
matchCount++
resolve(Component)
},
@ -458,7 +458,7 @@ o.spec("route", function() {
$window.location.href = prefix + "/"
route(root, "/", {
"/": {
onmatch: function(vnode, resolve) {
onmatch: function(resolve) {
resolve(A)
resolve(B)
callAsync(function() {resolve(C)})
@ -530,7 +530,7 @@ o.spec("route", function() {
o("m.route.set(m.route.get()) re-runs the resolution logic (#1180)", function(done, timeout){
timeout(FRAME_BUDGET * 3)
var onmatch = o.spy(function(vnode, resolve){resolve()})
var onmatch = o.spy(function(resolve){resolve()})
$window.location.href = prefix + "/"
route(root, '/', {
@ -612,7 +612,7 @@ o.spec("route", function() {
$window.location.href = prefix + "/"
route(root, "/a", {
"/a": {
onmatch: function(vnode, resolve) {
onmatch: function(resolve) {
setTimeout(resolve, 20)
},
render: function(vnode) {resolved = "a"}