Coder Social home page Coder Social logo

Comments (7)

rniemeyer avatar rniemeyer commented on September 3, 2024

What type of logic are you using this afterRender function for? Is this running logic on the DOM elements?

You can pass an afterRender option into the module binding and it will pass it on as the template's afterRender. Does this work for you?

from knockout-amd-helpers.

nmehlei avatar nmehlei commented on September 3, 2024

Thanks for the quick response.

I am planning on using it for custom animation logic, custom scrollbar updates, that kind of stuff ;)

I tried the afterRender option, but this invokes a method on the parent view model, not on the view model of the module. Since the ko module binding dynamically creates this (child) view model instance, it doesn't seem logical to catch the afterRender event/invocation on the parent level and somehow relay it to an acquired instance of the child view model.

from knockout-amd-helpers.

rniemeyer avatar rniemeyer commented on September 3, 2024

OK- I see the issue that you are having. I could potentially see passing a string for afterRender (or possibly as a new option afterModuleRender or something) and then checking if that function exists and executing it with the normal afterRender arguments. I don't think it would take too much to implement it.

However, overall I think that you might be happier in the long run moving to custom bindings, rather than using afterRender for this type of thing. I would be happy to help you explore that option, if you are interested. Otherwise, I would be willing to pursue adding an additional option to the library, as time permits.

from knockout-amd-helpers.

neo-headz avatar neo-headz commented on September 3, 2024

I need this functionality as well. My app is constructed entirely of modules, meaning I have no parent model other than the empty, global object I declare in the main.js file: ko.applyBindings({});. Since the afterRender function is not called on the module being rendered, I cannot contain functionality within the module.

The reason I'm using the afterRender function instead of doing stuff upon initialization is because the stuff I'm doing needs the elements to be rendered first.

Is there a workaround, besides adding the afterRender functions to the global viewModel?

from knockout-amd-helpers.

rniemeyer avatar rniemeyer commented on September 3, 2024

@headz68 - one workaround is to use a custom binding that you place on the container of your module's template. This could be a specific custom binding (fade in, etc.) or a custom binding that executes a generic function (like afterRender). Here is a sample of the latter: http://jsfiddle.net/rniemeyer/9wva2/. Hope that helps.

from knockout-amd-helpers.

neo-headz avatar neo-headz commented on September 3, 2024

@rniemeyer Thanks for your suggestion. The execute binding works nicely!

from knockout-amd-helpers.

ehimsi avatar ehimsi commented on September 3, 2024

I need this functionality as well. When we talk about each individual modules/widgets in an application its best to have a view+viewModel config( Like something we have in durandaljs). Also not sure about the feasibility, but having these methods inside the viewModels even without specifying them in html bindings would be a better option.

from knockout-amd-helpers.

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.