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

Comments

Projects
None yet
3 participants
@fabien
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@GianlucaGuarini

GianlucaGuarini Aug 18, 2017

Member

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

Member

GianlucaGuarini commented Aug 18, 2017

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

@fabien

This comment has been minimized.

Show comment
Hide comment
@fabien

fabien Aug 27, 2017

Contributor

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

Contributor

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

Merge branch 'feature/key-loops' into dev
* 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

This comment has been minimized.

Show comment
Hide comment
@GianlucaGuarini

GianlucaGuarini Sep 2, 2017

Member

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

Member

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

This comment has been minimized.

Show comment
Hide comment
@cybervaldez

cybervaldez 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.

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

This comment has been minimized.

Show comment
Hide comment
@GianlucaGuarini

GianlucaGuarini Sep 22, 2017

Member

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

Member

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