Provide svelte compatible implementations of readable
, writable
, derived
and get
using immutible values via immer.
Strict inequality triggering semantics provide a store version of the functionality seen with <svelte:options immutable={true} /> in the svelte compiler.
Using immer, @crikey/stores-immer
is able to provide copy-on-write semantics
during updates.
See @crikey/stores-immer for full documentation.
constant
- Create aReadable
store with a fixed valuereadable
- Create aReadable
storewritable
- Create aWritable
immer storederive
- Create aReadable
store derived from the resolved values of other stores
get
- Retrieve the value of a store
# pnpm
$ pnpm add @crikey/stores-immer
# npm
$ npm add @crikey/stores-immer
# yarn
$ yarn add @crikey/stores-immer
Standard usage should be a drop in replacement for svelte/store
.
The key difference being that mutating a store value will use immer to perform
copy-on-write semantics during an Writable.update | update
.
const initial = [1,2,3];
const store = writable([1,2,3]);
store.subscribe(value => console.log(value));
// > [ 1, 2, 3 ]
store.update(value => {
value.push(4);
return value;
})
// > [ 1, 2, 3, 4 ]
console.log(get(store) !== initial);
// > true