Allow listeners to attach before rendering (#493)
* Allow listeners to attach before rendering * Move rerender listeners down. Subtle sequencing * Update docs to reflect changes
This commit is contained in:
@@ -263,7 +263,7 @@ The `render` event should be emitted (`emitter.emit('render')`) whenever you wan
|
|||||||
|
|
||||||
The `pushState` can be emitted to navigate between routes: `emitted.emit('pushState', '/some/route')`.
|
The `pushState` can be emitted to navigate between routes: `emitted.emit('pushState', '/some/route')`.
|
||||||
|
|
||||||
Both `render` and `pushState` will only have an effect once the `DOMContentLoaded` event has been fired.
|
Note `render` will only have an effect once the `DOMContentLoaded` event has been fired.
|
||||||
|
|
||||||
### `app.route(routeName, handler)`
|
### `app.route(routeName, handler)`
|
||||||
Register a route on the router. Uses [nanorouter][nanorouter] under the hood.
|
Register a route on the router. Uses [nanorouter][nanorouter] under the hood.
|
||||||
|
|||||||
@@ -50,22 +50,6 @@ function Choo (opts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function start () {
|
function start () {
|
||||||
tree = router(createLocation())
|
|
||||||
rerender = nanoraf(function () {
|
|
||||||
if (hasPerformance && timingEnabled) {
|
|
||||||
window.performance.mark('choo:renderStart')
|
|
||||||
}
|
|
||||||
var newTree = router(createLocation())
|
|
||||||
tree = nanomorph(tree, newTree)
|
|
||||||
assert.notEqual(tree, newTree, 'choo.start: a different node type was returned as the root node on a rerender. Make sure that the root node is always the same type to prevent the application from being unmounted.')
|
|
||||||
if (hasPerformance && timingEnabled) {
|
|
||||||
window.performance.mark('choo:renderEnd')
|
|
||||||
window.performance.measure('choo:render', 'choo:renderStart', 'choo:renderEnd')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
bus.prependListener('render', rerender)
|
|
||||||
|
|
||||||
if (opts.history !== false) {
|
if (opts.history !== false) {
|
||||||
nanohistory(function (href) {
|
nanohistory(function (href) {
|
||||||
bus.emit('pushState')
|
bus.emit('pushState')
|
||||||
@@ -89,10 +73,27 @@ function Choo (opts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rerender = nanoraf(function () {
|
||||||
|
if (hasPerformance && timingEnabled) {
|
||||||
|
window.performance.mark('choo:renderStart')
|
||||||
|
}
|
||||||
|
var newTree = router(createLocation())
|
||||||
|
tree = nanomorph(tree, newTree)
|
||||||
|
assert.notEqual(tree, newTree, 'choo.start: a different node type was returned as the root node on a rerender. Make sure that the root node is always the same type to prevent the application from being unmounted.')
|
||||||
|
if (hasPerformance && timingEnabled) {
|
||||||
|
window.performance.mark('choo:renderEnd')
|
||||||
|
window.performance.measure('choo:render', 'choo:renderStart', 'choo:renderEnd')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
bus.prependListener('render', rerender)
|
||||||
|
|
||||||
documentReady(function () {
|
documentReady(function () {
|
||||||
bus.emit('DOMContentLoaded')
|
bus.emit('DOMContentLoaded')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tree = router(createLocation())
|
||||||
|
|
||||||
return tree
|
return tree
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user