fix tests

This commit is contained in:
Leo Horie 2016-12-06 00:09:09 -05:00
parent adabc37fd7
commit 3134202d24
8 changed files with 145 additions and 119 deletions

View file

@ -7,25 +7,29 @@ module.exports = function($window, redrawService) {
var routeService = coreRouter($window)
var identity = function(v) {return v}
var resolver, component, attrs, currentPath, waiting
var resolver, component, attrs, currentPath, resolve
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")
var update = function(routeResolver, comp, params, path) {
resolver = routeResolver, component = comp, attrs = params, currentPath = path, waiting = null
resolver = routeResolver, component = comp, attrs = params, currentPath = path, resolve = null
resolver.render = routeResolver.render || identity
render()
}
var render = function() {
if (resolver != null) redrawService.render(root, resolver.render(Vnode(component, attrs.key, attrs)))
if (resolver != null) redrawService.render(root, resolver.render(Vnode(component || "div", attrs.key, attrs)))
}
routeService.defineRoutes(routes, function(payload, params, path) {
if (payload.view) update({}, payload, params, path)
else {
if (payload.onmatch) {
if (waiting != null) update(payload, component, params, path)
if (resolve != null) update(payload, component, params, path)
else {
waiting = Promise.resolve(payload.onmatch(params, path))
.then(function(comp) {update(payload, comp != null ? comp : component, params, path)})
resolve = function(resolved) {
update(payload, resolved, params, path)
}
Promise.resolve(payload.onmatch(params, path)).then(function(resolved) {
if (resolve != null) resolve(resolved)
})
}
}
else update(payload, "div", params, path)