-
Notifications
You must be signed in to change notification settings - Fork 132
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
Keyed Nodes #3
Comments
Hi @kesne, morphdom uses the "id" attribute as the "key" by design. That is, morphdom works best if there are stable IDs for HTML elements and it will take extra steps to match up elements with matching IDs that are found in both the old DOM and the new DOM. Is there something else that you think is still missing? |
Ah, probably would have been good to read through the source before making an issue! My mistake. I guess the only callout is that the benefit of a key design is that keys can be re-used in two different trees that you're running through morphdom, whereas IDs need to be absolutely unique. |
True. With Marko Widgets we have a strategy for ensure IDs are always unique by prefixing IDs with the ID of the parent widget. That trick has worked really well for Marko Widgets. For rendering lists of items we recommend using the index of the current iteration prefixed with the ID of the parent widget as the unique ID. If you have any other thoughts or suggestions please share! |
Yeah it's not really an issue with my use cases, I just thought I would call it out. Feel free to close the issue if you're fine with the state of things. |
Sounds good. I will close this issue, but we can always reevaluate later. Thanks. |
I think it would be beneficial to have some way to have morphdom handle keys similar to how they are handled in virtual-dom (https://github.com/Matt-Esch/virtual-dom/blob/master/virtual-hyperscript/README.md#key).
Maybe a non-standard HTML attribute (such as
key="someKey"
) could be used along with the tagName to determine if a node is identical?I'm happy to make a PR for whatever you're are happy with, I just think something like this would be helpful!
The text was updated successfully, but these errors were encountered: