From f273b012c948c4efe9fead69fbfa7850b5af82c2 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Gerardy Date: Wed, 15 Feb 2017 21:58:10 +0100 Subject: [PATCH] =?UTF-8?q?Add=20support=20for=20(m.mount=20+=20m.route)?= =?UTF-8?q?=20=C3=97=20(factory=20+=20constructible)=20components?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/mount.js | 2 +- api/router.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api/mount.js b/api/mount.js index 0cebfcf6..2178505a 100644 --- a/api/mount.js +++ b/api/mount.js @@ -10,7 +10,7 @@ module.exports = function(redrawService) { 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() { redrawService.render(root, Vnode(component)) diff --git a/api/router.js b/api/router.js index b4690966..c182008f 100644 --- a/api/router.js +++ b/api/router.js @@ -21,11 +21,12 @@ module.exports = function($window, redrawService) { routeService.defineRoutes(routes, function(payload, params, path) { var update = lastUpdate = function(routeResolver, comp) { 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) run() } - if (payload.view) update({}, payload) + if (payload.view || typeof payload === "function") update({}, payload) else { if (payload.onmatch) { Promise.resolve(payload.onmatch(params, path)).then(function(resolved) {