-
Notifications
You must be signed in to change notification settings - Fork 18
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
Access parentNode within a nested binding handler #39
Comments
One way would be to extend the context with the future parent node, so it would be accessible for nested binding handlers. But need to think of nested |
Here is an example use case. Consider a
Now in the
@brianmhunt any thoughts? Is it a valid use case, or do you think this is a bad design? If it's bad, how would a correct one look like? |
Good question. 😄 |
Important news, the original So it seems like the original Besides that I actually need it currently, I also think that this it's a major difference and probably it would be better to handle it as the original Do you remember any reasons why you chose this order when implementing |
It's a performance benefit IIRC - operate outside the DOM then insert. Should be a trivial fix, and suggest we do it. You ok putting a PR? |
Yes I can next week sometime. But it would be interesting to test it if it matters and if it does, how much is the difference. In most cases I think the browser will not reflow until bindings have ended no matter when we bind, but maybe I'm completely wrong. I'll try to put together some performance tests. |
I never did any empirical testing of the advantage, so I'm curious to see results of a test. Since we are timing on We could make it an option to bind to parent before rendering, but I don't feel that should be a public part of the API. |
@brianmhunt I was thinking quite a bit about this issue, as you can see in your mailbox probably :) (Actually sorry for spamming you with unsorted thoughts). At the end I've found that in the current stage it's not worth dealing with this, because it would need too much code change, and probably it would have more drawbacks than benefits. So what do you think about providing a workaround and extending the child contexts with The name can be |
I'm wary of exposing Just an idea, once could put the selectable into a component, and then the ko.components.register('selectable-widget', {
viewModel: function(params) {
this.items = params.source();
this.selectedItem = params.selectedTarget;
},
template: {element: 'selectable-component'},
synchronous: true
}); <template id='selectable-component'>
<ul class='selectable-list' data-bind='fastForEach: items'>
<li data-bind='selected: $data === $component.selectedItem()'>
...
</li>
</ul>
</template> Do you think that solves the problem? |
The use case was about accessing the parent node, not the context of it. I don't think |
I noticed an issue which probably exists with the original
foreach
as well.When I have a nested binding handler which would use
element.parentNode
for whatever reason, it will fail because whenfastForEach
applies bindings to the item nodes, the nodes are not yet attached to their future parent, so theparentNode
will always be a technicaldiv
.I was thinking a bit about possible workarounds, but didn't find anything nice yet.
The text was updated successfully, but these errors were encountered: