1 | System.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, update) => {
|
25 | const newState = typeof update === "function" ? update(get(baseAtom)) : update;
|
26 | store.setState(newState, true);
|
27 | }
|
28 | );
|
29 | return derivedAtom;
|
30 | }
|
31 |
|
32 | })
|
33 | };
|
34 | }));
|