Open WHenderson opened 9 months ago
This was the root cause of a bug I spent a while tracking down in one of my projects, where I was firing off an API request when a derived
store updated, and I was seeing it fire off twice in the space of a few milliseconds. The API request happened to have a bug that made it non-idempotent, but it took me a while to realize that when the store's value updated to an object with identical values as the previous value, the derived
store was triggering an update.
Describe the problem
Currently, sveltes stores use a greedy comparator to determine if a value has changed:
This makes sense as a default as it matches the nature of reactive blocks in svelte 4.
Svelte 4 also supports immutable reactivity ( ). see: example
It would be useful if the stores had a similar parallel, allowing the ability to specify an alternative equality checker such as a strict equality checker.
Describe the proposed solution
Update the store api/implementation to allow a configurable comparison function which would override the default
safe_not_equal
.e.g.
possible apis:
extend the current implementation
offer an alternative import
Importance
nice to have