bypass route resolution algorithm on non-routed redraws
This commit is contained in:
parent
bb4321e8db
commit
809d8921c9
8 changed files with 105 additions and 117 deletions
|
|
@ -7,36 +7,37 @@ module.exports = function($window, redrawService) {
|
|||
var routeService = coreRouter($window)
|
||||
|
||||
var identity = function(v) {return v}
|
||||
var current = {render: identity, component: null, path: null, resolve: null}
|
||||
var current = {}
|
||||
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 render = function(resolver, component, params, path) {
|
||||
current.render = resolver.render || identity
|
||||
current.component = component
|
||||
current.path = path
|
||||
current.resolve = null
|
||||
redrawService.render(root, current.render.call(resolver, Vnode(component, undefined, params)))
|
||||
var update = function(resolver, component, params, path) {
|
||||
current = {resolver: resolver, component: component, params: params, path: path, resolve: null}
|
||||
current.resolver.render = resolver.render || identity
|
||||
render()
|
||||
}
|
||||
var run = routeService.defineRoutes(routes, function(component, params, path, route, isAction) {
|
||||
if (component.view) render({}, component, params, path)
|
||||
var render = function() {
|
||||
redrawService.render(root, current.resolver.render(Vnode(current.component, current.params.key, current.params)))
|
||||
}
|
||||
routeService.defineRoutes(routes, function(component, params, path) {
|
||||
if (component.view) update({}, component, params, path)
|
||||
else {
|
||||
if (component.onmatch) {
|
||||
if (isAction === false && current.path === path || current.resolve != null) render(current, current.component, params)
|
||||
if (current.resolve != null) update(component, current.component, params, path)
|
||||
else {
|
||||
current.resolve = function(resolved) {
|
||||
render(component, resolved, params, path)
|
||||
update(component, resolved, params, path)
|
||||
}
|
||||
component.onmatch(function(resolved) {
|
||||
if (current.resolve != null) current.resolve(resolved)
|
||||
}, params, path)
|
||||
}
|
||||
}
|
||||
else render(component, "div", params, path)
|
||||
else update(component, "div", params, path)
|
||||
}
|
||||
}, function() {
|
||||
routeService.setPath(defaultRoute)
|
||||
})
|
||||
redrawService.subscribe(root, run)
|
||||
redrawService.subscribe(root, render)
|
||||
}
|
||||
route.set = routeService.setPath
|
||||
route.get = function() {return current.path}
|
||||
|
|
|
|||
|
|
@ -521,7 +521,7 @@ o.spec("route", function() {
|
|||
|
||||
$window.location.href = prefix + "/"
|
||||
route(root, '/', {
|
||||
"/":{
|
||||
"/": {
|
||||
onmatch: onmatch,
|
||||
render: render
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue