Comments (7)
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.
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.
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.
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.
@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.
@rniemeyer Thanks for your suggestion. The execute binding works nicely!
from knockout-amd-helpers.
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)
- AfterRender not firing when module is initialized with a null observable HOT 2
- Getting the reference to the bound element HOT 10
- module and template loaders don't work with require.config moduleIDs packages HOT 12
- API available in bonded module needs to be called after template finishes rendering HOT 2
- Working with Typescript AMD Modules HOT 2
- [Request] Option to require additional files by convention HOT 1
- Provide simple way to load external templates from within custom bindings HOT 1
- afterRender still fires only for the first template when using external templates with requirejs/text HOT 2
- publish NuGet package for v.0.7.3 HOT 1
- Module Binding: require() for the template source should not have to wait until the module is downloaded
- Passing data from Tempate to Module HOT 2
- template binding with 'with' doesn't work HOT 4
- beforeRemove callback is not firing for template binding HOT 5
- Ready to use KO module using requirejs "map" HOT 2
- Passing markup into modules HOT 14
- Knockout-amd-helpers does not play well with r.js namespacing HOT 3
- renderTemplateSource produces an empty string HOT 3
- Dynamically assigning a template path in renderTemplate() HOT 2
- not working with webpack very well. HOT 2
- knockout-amd-helpers need new typings
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from knockout-amd-helpers.