Skip to content

Commit afd1c18

Browse files
committed
fix async rendering
1 parent 2ff9f3d commit afd1c18

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

example/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
var split = require('split-require')
1+
// var split = require('split-require')
22
var css = require('sheetify')
33
var choo = require('../')
4+
var html = require('choo/html')
45

56
css('todomvc-common/base.css')
67
css('todomvc-app-css/index.css')
@@ -16,6 +17,12 @@ app.route('#active', require('./views/main'))
1617
app.route('#completed', require('./views/main'))
1718
app.route('*', require('./views/main'))
1819

19-
app.experimentalAsyncRoute('/async', () => split('./views/main.js'))
20+
app.experimentalAsyncRoute('/async', () => Promise.resolve(function (state, emit) {
21+
return html`
22+
<body>
23+
Async rendering.
24+
</body>
25+
`
26+
}))
2027

2128
module.exports = app.mount('body')

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ Choo.prototype.route = function (route, handler) {
8383
}
8484

8585
// Register a route to be loaded asynchronously.
86-
Choo.prototype.experimentalAsyncRoute = function (route, load) {
86+
Choo.prototype.experimentalAsyncRoute = function (route, loader) {
8787
assert.equal(typeof route, 'string', 'choo.asyncRoute: asyncRoute should be type string')
88-
assert.equal(typeof handler, 'function', 'choo.asyncRoute: route should be type function')
88+
assert.equal(typeof loader, 'function', 'choo.asyncRoute: loader should be type function')
8989

9090
var IDLE = 0
9191
var LOADING = 1
@@ -104,7 +104,7 @@ Choo.prototype.experimentalAsyncRoute = function (route, load) {
104104
renderRoute = state.route
105105
loadingState = LOADING
106106

107-
var p = load(onload)
107+
var p = loader(onload)
108108
assert(p && p.then, 'choo.asyncRoute: async route should return a Promise')
109109
p.then(onload.bind(null, null), onload)
110110
return self._asyncProxy

0 commit comments

Comments
 (0)