UNPKG

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