@crikey/stores-strict
v0.0.16
Published
Provide [svelte](https://svelte.dev/docs#run-time-svelte-store) compatible implementations of `readable`, `writable`, `derived` and `get` with strict inequality triggering semantics.
Downloads
33
Readme
@crikey/stores-strict
Provide svelte compatible implementations of readable
, writable
, derived
and get
with strict inequality triggering semantics.
Strict inequality triggering semantics provide a store version of the functionality seen with <svelte:options immutable={true} /> in the svelte compiler.
Strict equality stores make the most sense when programming with strict immutability rules and functional programming.
For complex structured immutable types, try @crikey/stores-immer
See @crikey/stores-strict for full documentation.
API
Store creation functions:
constant
- Create aReadable
store with a fixed valuereadable
- Create aReadable
storewritable
- Create aWritable
storederive
- Create aReadable
store derived from the resolved values of other storestransform
- Create aWritable
store by applying transform functions when reading and writing values
Utility functions:
get
- Retrieve the value of a store
Installation
# pnpm
$ pnpm add @crikey/stores-strict
# npm
$ npm add @crikey/stores-strict
# yarn
$ yarn add @crikey/stores-strict
Usage
Standard usage should be a drop in replacement for svelte/store
, with the exception of when subscriptions are
triggered.
Differences from svelte stores
Classic svelte stores signal for changes greedily. If a store value is updated and either the old or new value are complex types, then svelte will signal a change even if those values are strictly equal.
Strict stores use a simple referential inequality check (!==
) to determine if a change signal should be sent.
e.g.
const store = writable([1]);
// log each change
store.subscribe(arr => console.log(arr));
// don't change anything
store.update(arr => {
return arr;
});
// push an item onto the array
store.update(arr => {
arr.push(2);
return arr;
});
// @crikey/stores-strict
// > [1]
//
// @crikey/stores-svelte (svelte compatible stores)
// > [1]
// > [1]
// > [1,2]
//