From 9bce8996ada717fcc82d0566c5f053c06b062aba Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Wed, 4 Apr 2018 17:03:19 +0200 Subject: [PATCH] fix async rendering --- example/index.js | 9 ++++++++- index.js | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/example/index.js b/example/index.js index e6c15337..f9718933 100644 --- a/example/index.js +++ b/example/index.js @@ -1,6 +1,7 @@ var split = require('split-require') var css = require('sheetify') var choo = require('../') +var html = require('choo/html') css('todomvc-common/base.css') css('todomvc-app-css/index.css') @@ -16,6 +17,12 @@ app.route('#active', require('./views/main')) app.route('#completed', require('./views/main')) app.route('*', require('./views/main')) -app.experimentalAsyncRoute('/async', () => split('./views/main.js')) +app.experimentalAsyncRoute('/async', () => Promise.resolve(function (state, emit) { + return html` + + Async rendering. + + ` +})) module.exports = app.mount('body') diff --git a/index.js b/index.js index d08d5941..1838a45d 100644 --- a/index.js +++ b/index.js @@ -83,9 +83,9 @@ Choo.prototype.route = function (route, handler) { } // Register a route to be loaded asynchronously. -Choo.prototype.experimentalAsyncRoute = function (route, load) { +Choo.prototype.experimentalAsyncRoute = function (route, loader) { assert.equal(typeof route, 'string', 'choo.asyncRoute: asyncRoute should be type string') - assert.equal(typeof handler, 'function', 'choo.asyncRoute: route should be type function') + assert.equal(typeof loader, 'function', 'choo.asyncRoute: loader should be type function') var IDLE = 0 var LOADING = 1 @@ -104,7 +104,7 @@ Choo.prototype.experimentalAsyncRoute = function (route, load) { renderRoute = state.route loadingState = LOADING - var p = load(onload) + var p = loader(onload) assert(p && p.then, 'choo.asyncRoute: async route should return a Promise') p.then(onload.bind(null, null), onload) return self._asyncProxy