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

Possible to define key parameter for each? #33

Closed
pakastin opened this issue Nov 29, 2016 · 2 comments
Closed

Possible to define key parameter for each? #33

pakastin opened this issue Nov 29, 2016 · 2 comments

Comments

@pakastin
Copy link

With Angular you can use track by with ng-repeat and with React the key parameter to reorder/reuse DOM elements. Does Svelte have reordering/reusing option with each?

@Rich-Harris
Copy link
Member

Not currently. It's definitely on the TODO list. There are basically two (possibly overlapping) approaches that are possible:

  1. Use some syntax to declare the key, like {{#each:id ...}} or {{#eachkeyed foo, i, key}} or whatever.
  2. Create an API for manipulating lists programmatically

The advantage of 1 is that it's an easy way to get that functionality even in deeply nested each blocks. The advantage of 2 is that you can be very precise about which parts of the component need to be checked for changes (i.e. you can insert an item into a list and not touch anything else at all, whereas with keyed updates you need to account for changes in items whose keys are the same), and there's no requirement for any sort of diffing.

Open to API/design suggestions!

@Rich-Harris
Copy link
Member

Closing in favour of #81

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