Skip to content

Commit

Permalink
fix async rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Apr 4, 2018
1 parent 2ff9f3d commit 9bce899
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion example/index.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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`
<body>
Async rendering.
</body>
`
}))

module.exports = app.mount('body')
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9bce899

Please sign in to comment.