Make api/router.js promise-aware
This commit is contained in:
parent
05e888958d
commit
22e9c3bb6f
1 changed files with 6 additions and 10 deletions
|
|
@ -7,11 +7,11 @@ module.exports = function($window, redrawService) {
|
||||||
var routeService = coreRouter($window)
|
var routeService = coreRouter($window)
|
||||||
|
|
||||||
var identity = function(v) {return v}
|
var identity = function(v) {return v}
|
||||||
var resolver, component, attrs, currentPath, resolve
|
var resolver, component, attrs, currentPath, waiting
|
||||||
var route = function(root, defaultRoute, routes) {
|
var route = function(root, defaultRoute, routes) {
|
||||||
if (root == null) throw new Error("Ensure the DOM element that was passed to `m.route` is not undefined")
|
if (root == null) throw new Error("Ensure the DOM element that was passed to `m.route` is not undefined")
|
||||||
var update = function(routeResolver, comp, params, path) {
|
var update = function(routeResolver, comp, params, path) {
|
||||||
resolver = routeResolver, component = comp, attrs = params, currentPath = path, resolve = null
|
resolver = routeResolver, component = comp, attrs = params, currentPath = path, waiting = null
|
||||||
resolver.render = routeResolver.render || identity
|
resolver.render = routeResolver.render || identity
|
||||||
render()
|
render()
|
||||||
}
|
}
|
||||||
|
|
@ -22,14 +22,10 @@ module.exports = function($window, redrawService) {
|
||||||
if (payload.view) update({}, payload, params, path)
|
if (payload.view) update({}, payload, params, path)
|
||||||
else {
|
else {
|
||||||
if (payload.onmatch) {
|
if (payload.onmatch) {
|
||||||
if (resolve != null) update(payload, component, params, path)
|
if (waiting != null) update(payload, component, params, path)
|
||||||
else {
|
else {
|
||||||
resolve = function(resolved) {
|
waiting = Promise.resolve(payload.onmatch(params, path))
|
||||||
update(payload, resolved, params, path)
|
.then(function() {update(payload, component, params, path)})
|
||||||
}
|
|
||||||
payload.onmatch(function(resolved) {
|
|
||||||
if (resolve != null) resolve(resolved)
|
|
||||||
}, params, path)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else update(payload, "div", params, path)
|
else update(payload, "div", params, path)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue