Add support for (m.mount + m.route) × (factory + constructible) components
This commit is contained in:
parent
f4fb5ac4be
commit
f273b012c9
2 changed files with 4 additions and 3 deletions
|
|
@ -10,7 +10,7 @@ module.exports = function(redrawService) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (component.view == null) throw new Error("m.mount(element, component) expects a component, not a vnode")
|
if (component.view == null && typeof component !== "function") throw new Error("m.mount(element, component) expects a component, not a vnode")
|
||||||
|
|
||||||
var run = function() {
|
var run = function() {
|
||||||
redrawService.render(root, Vnode(component))
|
redrawService.render(root, Vnode(component))
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,12 @@ module.exports = function($window, redrawService) {
|
||||||
routeService.defineRoutes(routes, function(payload, params, path) {
|
routeService.defineRoutes(routes, function(payload, params, path) {
|
||||||
var update = lastUpdate = function(routeResolver, comp) {
|
var update = lastUpdate = function(routeResolver, comp) {
|
||||||
if (update !== lastUpdate) return
|
if (update !== lastUpdate) return
|
||||||
component = comp != null && typeof comp.view === "function" ? comp : "div", attrs = params, currentPath = path, lastUpdate = null
|
component = comp != null && (typeof comp.view === "function" || typeof comp === "function")? comp : "div"
|
||||||
|
attrs = params, currentPath = path, lastUpdate = null
|
||||||
render = (routeResolver.render || identity).bind(routeResolver)
|
render = (routeResolver.render || identity).bind(routeResolver)
|
||||||
run()
|
run()
|
||||||
}
|
}
|
||||||
if (payload.view) update({}, payload)
|
if (payload.view || typeof payload === "function") update({}, payload)
|
||||||
else {
|
else {
|
||||||
if (payload.onmatch) {
|
if (payload.onmatch) {
|
||||||
Promise.resolve(payload.onmatch(params, path)).then(function(resolved) {
|
Promise.resolve(payload.onmatch(params, path)).then(function(resolved) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue