Hi,
I've been testing knockout 3.5.0-rc and I've noticed that the foreach binding behaviour has changed.
I've created a sample trying to replicate something I'll do with the 3.4.x version hoping that you can help me understand how we should deal with these cases from now on.
Since the context is no longer bound to the item in the array, I need to manually bind functions inside the foreach with the proper arguments. However, I'm not sure if this is the appropriate solution.
Best regards
I initially went with click: () => removeUser(user)
, but ultimately refactored to avoid using foreach as
entirely as I needed the mouse events to apply ripples.
I'll make sure to explain this better in the release notes.
If you want the previous behavior, you can set a global option:
ko.options.createChildContextWithAs = true
Hi @avickers,
Thanks for your input. I might follow that approach 馃憤.
Hi @mbest,
Sorry, I actually saw that option in the release notes. Is there any drawback with that approach? What's the reasoning behind the behaviour change?
Thanks
This is breaking applications of mine as well.
I think this is more serious than a documentation issue. As I discuss in https://github.com/knockout/knockout/pull/907#issuecomment-392603922 I suggest
ko.options.createChildContextWithAs
default value to true
(or better, remove ko.options.createChildContextWithAs
altogether)createChildContext
(default true
) or noChildContext
(default false
), to allow specifying the behavior on an individual basis, for each usage of foreach
Hi @fastfasterfastest,
Thanks for your input. I also agree that is more serious than a documentation issue. I don't mind having breaking changes provided they are explicit in the release notes. However, in the past, knockout has been pretty cautious about breaking changes (e.g. knockout deferred updates are false by default) which enforces that this kind of changes should be very explicit.
I would like to know which are the consequences of enabling ko.options.createChildContextWithAs
since I believe this comes with a performance hit.
You've made some good points. I'll take another look at how we present this option.
I've finally gotten some time to work on this. Please take a look at #2403.
Hi Michael,
Sorry for the late reply.
Thanks for fixing this issue! The merged PR seems good to me 馃憤 I'll give it a try as soon as we have a new release.
Most helpful comment
You've made some good points. I'll take another look at how we present this option.