UNPKG

776 BJavaScriptView Raw
1System.register(['jotai'], (function (exports) {
2 'use strict';
3 var atom;
4 return {
5 setters: [function (module) {
6 atom = module.atom;
7 }],
8 execute: (function () {
9
10 exports('atomWithStore', atomWithStore);
11
12 function atomWithStore(store) {
13 const baseAtom = atom(store.getState());
14 baseAtom.onMount = (setValue) => {
15 const callback = () => {
16 setValue(store.getState());
17 };
18 const unsub = store.subscribe(callback);
19 callback();
20 return unsub;
21 };
22 const derivedAtom = atom(
23 (get) => get(baseAtom),
24 (_get, _set, action) => {
25 store.dispatch(action);
26 }
27 );
28 return derivedAtom;
29 }
30
31 })
32 };
33}));