Skip to content
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

Closed
kesne opened this issue Aug 15, 2015 · 5 comments
Closed

Keyed Nodes #3

kesne opened this issue Aug 15, 2015 · 5 comments

Comments

@kesne
Copy link

kesne commented Aug 15, 2015

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!

@patrick-steele-idem
Copy link
Owner

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?

@kesne
Copy link
Author

kesne commented Aug 15, 2015

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.

@patrick-steele-idem
Copy link
Owner

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!

@kesne
Copy link
Author

kesne commented Aug 15, 2015

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.

@patrick-steele-idem
Copy link
Owner

Sounds good. I will close this issue, but we can always reevaluate later. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants