Closed brianmhunt closed 6 years ago
The applyBindings*
functions now return Promises, so it'd be trivial to add an afterBinding
binding e.g.
class AfterBindingHandler extends ko.AsyncBindingHandler {
constructor (params) {
super(params)
applyBindingsToDescendants(this.$context, this.$element)
.then(this.completeBinding) // notify parent bindings that this binding is done
.then(this.value) // this.value is the `valueAccessor()`, presumably a function.
}
get controlsDescendants () { return true }
}
Then, once registered as e.g. after
with e.g. ko.bindingHandlers.set({after: AfterBindingHandler})
, you'd use it like this:
<span data-bind='after: callback'></span>
where callback
is some function.
I think this is a reasonable solution for the problem of callbacks being called when a component is done rendering. That said, it's not the same as afterRender
.
I'd accept the equivalent of the PR from knockout/knockout#1944 for afterRender
functionality.
Please share if you think there are other or better options!
Maybe do
constructor (...params) {
super(...params)
// ...
}
to make it even more future-proof.
The BindingHandler
constructor API follows Crockford's single-object-param model, so we can extend it by adding named attributes to the param
object that's passed in via applyBindings
.
awesome!
Closing in lieu of #47 (just for ease of reference)
Per knockout/knockout#1944
Noting comment by @jmvtrinidad on tko.computed issue (pre-monorepo):