Replies: 4 comments 8 replies
-
It comes up time to time so I made a demo a couple of years ago. https://codesandbox.io/s/explicit-keys-4iyen?file=/Key.js It's always tricky because while there are cases for this like immutable data it's generally always worse than using nested reactivity or stores. I didn't want to influence things negatively but it is a good tool to have and well writing these control flows can be tricky.The biggest thing to understand is it does have to be a different control flow than the others because it's like the combination of the other 2. Or basically the least optimizable as both the item and the index can change so they both have to be signals. I'm not opposed to providing this primitive but would like to hear thoughts. |
Beta Was this translation helpful? Give feedback.
-
Agree, sometimes it's quite useful |
Beta Was this translation helpful? Give feedback.
-
Made a PR to solid-primitives that adds this: solidjs-community/solid-primitives#59 |
Beta Was this translation helpful? Give feedback.
-
Have you thought about adding this to the core library? Key comparisons are used quite often... |
Beta Was this translation helpful? Give feedback.
-
Allow
<For>
to receive another property for granular comparison. Currently,<For>
only compares by items, so it doesn't work best for immutable data structures or structures that produces a new, deep copy. This applies mostly for things like Firebase wherecollection
produces a new set of data everytime a change happens. This kind of defeats the purpose of<For>
being able to move unchanged items. Since referential equality doesn't really work for immutable data structures, it's better if we can compare something that makes it "unique".With granular item comparison, we can compare a certain aspect of that item rather than the item itself. Consider:
This way, we can "move" the elements if the item still retains the same id, regardless if the item is referentially different.
Beta Was this translation helpful? Give feedback.
All reactions