-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
template binding's afterRender handler does not get invoked on DOM render #30
Comments
You could try either the autobind feature from core-decorators or instead use an arrow function to preserve the |
@vikashpisces It would help to see a jsFiddle. |
@brianmhunt I have a jsFiddle created which illustrates the problem. In the jsFiddle, you can see error in console when afterRender callback of template binding is being invoked on DOM render. Thanks in advance. |
@vikashpisces The first issue is that you're using Knockout 3.4 in the jsFiddle. You can use the TKO library (i.e. KO4 alpha) here: https://unpkg.com/tko@4.0.0-alpha2/dist/ko.js This version works: https://jsfiddle.net/bmh_ca/q0hh2vta/3/ Let me know if there's an issue . (Sorry for short comment -- got to run!) |
Just to complete my prior comment - You need to use If there is anything we do to improve this, please share and we can re-open. |
@brianmhunt Thanks a lot for the quick help on this. Binding renderhandler to $data or using fat arrow worked for me. One thing I would like to highlight that $data was always default current context. Whether to mention it or not, binding's current context was $data. I am not sure what has changed in that context. It could be the ES6 compiler which is causing this issue. If any support from KO provided on this part can help people who are migrating to ES6. Otherwise every places default context need to be mentioned explicitly. Thanks @brianmhunt & @krnlde for your time. |
This issue did occur in 3.4, as you can see from the first fiddle ... but I really don't know the rationale... @mbest - any idea why |
I think the rationale is that |
Got it thanks @mbest. I think with ES6 classes being used as view models the expectation has probably changed. (As per this issue) There's no technical reason we can't do this, is there? |
I am trying out TKO 4.0 in ES6 semantics with transpilation done using Babel.
When I use template binding and pass a class method to afterRender, the method does get invoked but the reference of this becomes window Object. However, if the same class method is added to click binding, method gets invoked and there this reference points out to class or the viewmodel.
Not sure if this is an issue with TKO 4.0 or ES6 compilations. If someone can help me on this with a sample working example of afterRender using ES6 and TKO 4.0 would be of great help at this time. As we have planned for migration from KO to TKO for good performance reason.
I am attaching my tried code zipped below:
Thanks is advance.
side-bar.zip
The text was updated successfully, but these errors were encountered: