UNPKG

jotai

Version:

👻 Next gen state management that will spook you

32 lines (28 loc) • 839 B
System.register(['jotai'], (function (exports) { 'use strict'; var atom; return { setters: [function (module) { atom = module.atom; }], execute: (function () { exports('atomWithStore', atomWithStore); function atomWithStore(store) { const baseAtom = atom(store.getState()); baseAtom.onMount = (setValue) => { const callback = () => { setValue(store.getState()); }; const unsub = store.subscribe(callback); callback(); return unsub; }; const derivedAtom = atom((get) => get(baseAtom), (get, _set, update) => { const newState = typeof update === "function" ? update(get(baseAtom)) : update; store.setState(newState, true); }); return derivedAtom; } }) }; }));