GithubHelp home page GithubHelp logo

components) Add `afterRender` about tko HOT 5 CLOSED

knockout avatar knockout commented on July 19, 2024
components) Add `afterRender`

from tko.

Comments (5)

brianmhunt avatar brianmhunt commented on July 19, 2024 1

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!

from tko.

krnlde avatar krnlde commented on July 19, 2024

Maybe do

constructor (...params) {
  super(...params)
  // ...
}

to make it even more future-proof.

from tko.

brianmhunt avatar brianmhunt commented on July 19, 2024

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.

from tko.

krnlde avatar krnlde commented on July 19, 2024

awesome!

from tko.

brianmhunt avatar brianmhunt commented on July 19, 2024

Closing in lieu of #47 (just for ease of reference)

from tko.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.