UNPKG

1.1 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('jotai')) :
3 typeof define === 'function' && define.amd ? define(['exports', 'jotai'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.jotaiZustand = {}, global.jotai));
5})(this, (function (exports, jotai) { 'use strict';
6
7 function 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, update) {
23 var newState = typeof update === 'function' ? update(get(baseAtom)) : update;
24 store.setState(newState, true);
25 });
26 return derivedAtom;
27 }
28
29 exports.atomWithStore = atomWithStore;
30
31 Object.defineProperty(exports, '__esModule', { value: true });
32
33}));