UNPKG

742 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((get) => get(baseAtom), (_get, _set, action) => {
23 store.dispatch(action);
24 });
25 return derivedAtom;
26 }
27
28 })
29 };
30}));