UNPKG

608 BJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var jotai = require('jotai');
6
7function atomWithStore(store) {
8 var baseAtom = jotai.atom(store.getState());
9
10 baseAtom.onMount = function (setValue) {
11 var callback = function callback() {
12 setValue(store.getState());
13 };
14
15 var unsub = store.subscribe(callback);
16 callback();
17 return unsub;
18 };
19
20 var derivedAtom = jotai.atom(function (get) {
21 return get(baseAtom);
22 }, function (_get, _set, action) {
23 store.dispatch(action);
24 });
25 return derivedAtom;
26}
27
28exports.atomWithStore = atomWithStore;