You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
/** * @param {any} a * @param {any} b * @returns {boolean} */exportfunctionstrict_not_equal(a,b){returna!==a;}
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 (<svelte:options immutable={true} />). 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
The text was updated successfully, but these errors were encountered: