Skip to content

Commit

Permalink
feat(router): Use new descendantsComplete binding event to delay afte…
Browse files Browse the repository at this point in the history
…rRender until all descendants c

BREAKING CHANGE: Requires KnockoutJS 3.5.0-rc
  • Loading branch information
caseyWebb committed Jun 28, 2018
1 parent be14d20 commit ccc6b74
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/router/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ ko.components.register('router', {
ko.bindingHandlers.__router__ = {
init(el, valueAccessor, allBindings, viewModel, bindingCtx) {
const $router = bindingCtx.$rawData
const bindingEvent: any = ko.bindingEvent

bindingEvent.subscribe(el, 'descendantsComplete', () => {
if ($router.ctx.$parent) {
$router.ctx.$parent.router.initialized
.then(() => $router.init())
.catch(noop)
} else {
$router.init()
}
})

ko.applyBindingsToNode(
el,
Expand All @@ -35,14 +46,6 @@ ko.bindingHandlers.__router__ = {
bindingCtx.extend({ $router })
)

if ($router.isRoot) {
$router.init()
} else {
$router.ctx.$parent.router.initialized
.then(() => $router.init())
.catch(noop)
}

return { controlsDescendantBindings: true }
}
}
Expand Down

0 comments on commit ccc6b74

Please sign in to comment.