From a34685d7a4316dd94b3afa9b67f6e6e668e272f5 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Gerardy Date: Fri, 2 Sep 2016 22:03:27 +0200 Subject: [PATCH] m.route.get() returns the last fully resolved route (fix #1276), change RouteResolver.onmatch() signature according to #1277 --- api/router.js | 9 +++++---- api/tests/test-router.js | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/api/router.js b/api/router.js index b1226d55..d8496c30 100644 --- a/api/router.js +++ b/api/router.js @@ -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 } diff --git a/api/tests/test-router.js b/api/tests/test-router.js index 85f977e6..43db3493 100644 --- a/api/tests/test-router.js +++ b/api/tests/test-router.js @@ -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"}