@crikey/stores-immer
v0.0.18
Published
Provide [svelte](https://svelte.dev/docs#run-time-svelte-store) compatible implementations of `readable`, `writable`, `derived` and `get` using immutible values via [immer](https://immerjs.github.io/immer/).
Downloads
22
Readme
@crikey/stores-immer
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.
API
Store creation functions:
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
Utility functions:
get
- Retrieve the value of a store
Installation
# pnpm
$ pnpm add @crikey/stores-immer
# npm
$ npm add @crikey/stores-immer
# yarn
$ yarn add @crikey/stores-immer
Usage
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
.
Example
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