1.6.4 • Published 10 months ago
@marianmeres/store v1.6.4
@marianmeres/store
Basic store (arbitrary data with the ability to subscribe to changes) utility. Svelte store contract compatible.
Install
$ npm i @marianmeres/store
Usage
const store = createStore('foo');
// always able to `get` current value
assert('foo' === store.get());
// from now on, console.log changes
let unsub = store.subscribe(console.log); // log: foo
store.set('bar'); // logs: bar
store.update((old) => old + 'baz'); // logs: barbaz
unsub(); // stop console.log changes for `store`
// derived example
const store2 = createStore(123);
const derived = createDerivedStore([store, store2], ([a, b]) => [a, b].join());
// derived store value is intially `undefined` until subscription exists
assert(derived.get() === undefined);
unsub = derived.subscribe(console.log); // logs: barbaz,123
store2.set(456); // logs: barbaz,456
unsub();
store.set(789); // no log
// derived async example (the deriveFn accepts second 'set' argument)
const derivedAsync = createDerivedStore([store, store2], ([a, b], set) => {
setTimeout(() => { set([a, b].join()) }, 1000)
});
1.6.4
10 months ago
1.6.3
10 months ago
1.6.2
10 months ago
1.6.1
1 year ago
1.6.0
1 year ago
1.5.0
2 years ago
1.4.1
2 years ago
1.3.2
2 years ago
1.4.0
2 years ago
1.3.1
2 years ago
1.3.0
2 years ago
1.2.1
2 years ago
1.2.0
2 years ago
1.1.0
2 years ago
1.0.0
2 years ago
0.1.2
2 years ago
0.1.1
2 years ago
0.1.0
2 years ago
0.0.2
2 years ago