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

Loop item identity vs. compare by reference #2418

Closed
fabien opened this issue Aug 13, 2017 · 5 comments
Closed

Loop item identity vs. compare by reference #2418

fabien opened this issue Aug 13, 2017 · 5 comments

Comments

@fabien
Copy link
Contributor

@fabien fabien commented Aug 13, 2017

If I gather correctly, this is the line where 'comparison by reference' happens:

oldPos = oldItems.indexOf(item),

I'm seeing lists being fully recreated whenever I cannot ensure these references are maintained, even if the underlying data has not changed. My state library (Baobab) does not preserve references by default, when an array changes. This causes unnecessary redrawing, which is slow and ugly.

In 99% of these cases, a unique identifier is already present and I would like to take advantage of this, similar to VueJS's 'key' attribute: https://vuejs.org/v2/guide/list.html#key

Is this something to consider as a new Riot attribute, or to make configurable using a callback function perhaps? The no-reorder option does not help with this, as it causes other issues.

@GianlucaGuarini
Copy link
Member

@GianlucaGuarini GianlucaGuarini commented Aug 18, 2017

@fabien that's really I good point I will definitely look into this soon

@fabien
Copy link
Contributor Author

@fabien fabien commented Aug 27, 2017

Here's the same concept in re:dom https://redom.js.org/documentation/#keyed-list

GianlucaGuarini added a commit that referenced this issue Sep 2, 2017
GianlucaGuarini added a commit that referenced this issue Sep 2, 2017
* feature/key-loops:
  added: tests for #2418
  updated: add functions to generate dynamic key values
  updated: implement keyed loops #2418
GianlucaGuarini added a commit that referenced this issue Sep 2, 2017
@GianlucaGuarini
Copy link
Member

@GianlucaGuarini GianlucaGuarini commented Sep 2, 2017

feature added in riot@3.7.0 now you can use the key attribute to provide unique ids to your items in a collection

@cybervaldez
Copy link

@cybervaldez cybervaldez commented Sep 21, 2017

in the documentation it says key=“id”, i think its suppose to say key={ id }

I find the documentation is lacking in demonstrating the purpose of this as well.

@GianlucaGuarini
Copy link
Member

@GianlucaGuarini GianlucaGuarini commented Sep 22, 2017

@cybervaldez contribution to the documentation are always welcome (https://github.com/riot/riot.github.io).

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.