@effect-atom/atom-react 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ {
2
+ "main": "../dist/cjs/Hooks.js",
3
+ "module": "../dist/esm/Hooks.js",
4
+ "types": "../dist/dts/Hooks.d.ts",
5
+ "sideEffects": []
6
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present The Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ WIP.
2
+
3
+ Docs: https://effect-ts.github.io/rx
@@ -0,0 +1,6 @@
1
+ {
2
+ "main": "../dist/cjs/ReactHydration.js",
3
+ "module": "../dist/esm/ReactHydration.js",
4
+ "types": "../dist/dts/ReactHydration.d.ts",
5
+ "sideEffects": []
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "main": "../dist/cjs/RegistryContext.js",
3
+ "module": "../dist/esm/RegistryContext.js",
4
+ "types": "../dist/dts/RegistryContext.d.ts",
5
+ "sideEffects": []
6
+ }
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @since 1.0.0
5
+ */
6
+ "use client";
7
+
8
+ Object.defineProperty(exports, "__esModule", {
9
+ value: true
10
+ });
11
+ exports.useAtomValue = exports.useAtomSuspense = exports.useAtomSubscribe = exports.useAtomSet = exports.useAtomRefresh = exports.useAtomRefPropValue = exports.useAtomRefProp = exports.useAtomRef = exports.useAtomMount = exports.useAtomInitialValues = exports.useAtom = void 0;
12
+ var Atom = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@effect-atom/atom/Atom"));
13
+ var Registry = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@effect-atom/atom/Registry"));
14
+ var _effect = /*#__PURE__*/require("effect");
15
+ var Cause = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("effect/Cause"));
16
+ var Exit = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("effect/Exit"));
17
+ var _GlobalValue = /*#__PURE__*/require("effect/GlobalValue");
18
+ var React = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("react"));
19
+ var _RegistryContext = /*#__PURE__*/require("./RegistryContext.js");
20
+ function _interopRequireWildcard(e, t) {
21
+ if ("function" == typeof WeakMap) var r = new WeakMap(),
22
+ n = new WeakMap();
23
+ return (_interopRequireWildcard = function (e, t) {
24
+ if (!t && e && e.__esModule) return e;
25
+ var o,
26
+ i,
27
+ f = {
28
+ __proto__: null,
29
+ default: e
30
+ };
31
+ if (null === e || "object" != typeof e && "function" != typeof e) return f;
32
+ if (o = t ? n : r) {
33
+ if (o.has(e)) return o.get(e);
34
+ o.set(e, f);
35
+ }
36
+ for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]);
37
+ return f;
38
+ })(e, t);
39
+ }
40
+ const storeRegistry = /*#__PURE__*/(0, _GlobalValue.globalValue)("@effect-atom/atom-react/storeRegistry", () => new WeakMap());
41
+ function makeStore(registry, atom) {
42
+ let stores = storeRegistry.get(registry);
43
+ if (stores === undefined) {
44
+ stores = new WeakMap();
45
+ storeRegistry.set(registry, stores);
46
+ }
47
+ const store = stores.get(atom);
48
+ if (store !== undefined) {
49
+ return store;
50
+ }
51
+ const newStore = {
52
+ subscribe(f) {
53
+ return registry.subscribe(atom, f);
54
+ },
55
+ snapshot() {
56
+ return registry.get(atom);
57
+ },
58
+ getServerSnapshot() {
59
+ return Atom.getServerValue(atom, registry);
60
+ }
61
+ };
62
+ stores.set(atom, newStore);
63
+ return newStore;
64
+ }
65
+ function useStore(registry, atom) {
66
+ const store = makeStore(registry, atom);
67
+ return React.useSyncExternalStore(store.subscribe, store.snapshot, store.getServerSnapshot);
68
+ }
69
+ const initialValuesSet = /*#__PURE__*/(0, _GlobalValue.globalValue)("@effect-atom/atom-react/initialValuesSet", () => new WeakMap());
70
+ /**
71
+ * @since 1.0.0
72
+ * @category hooks
73
+ */
74
+ const useAtomInitialValues = initialValues => {
75
+ const registry = React.useContext(_RegistryContext.RegistryContext);
76
+ let set = initialValuesSet.get(registry);
77
+ if (set === undefined) {
78
+ set = new WeakSet();
79
+ initialValuesSet.set(registry, set);
80
+ }
81
+ for (const [atom, value] of initialValues) {
82
+ if (!set.has(atom)) {
83
+ set.add(atom);
84
+ registry.ensureNode(atom).setValue(value);
85
+ }
86
+ }
87
+ };
88
+ /**
89
+ * @since 1.0.0
90
+ * @category hooks
91
+ */
92
+ exports.useAtomInitialValues = useAtomInitialValues;
93
+ const useAtomValue = (atom, f) => {
94
+ const registry = React.useContext(_RegistryContext.RegistryContext);
95
+ if (f) {
96
+ const atomB = React.useMemo(() => Atom.map(atom, f), [atom, f]);
97
+ return useStore(registry, atomB);
98
+ }
99
+ return useStore(registry, atom);
100
+ };
101
+ exports.useAtomValue = useAtomValue;
102
+ function mountAtom(registry, atom) {
103
+ React.useEffect(() => registry.mount(atom), [atom, registry]);
104
+ }
105
+ function setAtom(registry, atom, options) {
106
+ if (options?.mode === "promise" || options?.mode === "promiseExit") {
107
+ return React.useCallback((value, opts) => {
108
+ registry.set(atom, value);
109
+ const promise = _effect.Effect.runPromiseExit(Registry.getResult(registry, atom, {
110
+ suspendOnWaiting: true
111
+ }), opts);
112
+ return options.mode === "promise" ? promise.then(flattenExit) : promise;
113
+ }, [registry, atom, options.mode]);
114
+ }
115
+ return React.useCallback(value => {
116
+ registry.set(atom, typeof value === "function" ? value(registry.get(atom)) : value);
117
+ }, [registry, atom]);
118
+ }
119
+ const flattenExit = exit => {
120
+ if (Exit.isSuccess(exit)) return exit.value;
121
+ throw Cause.squash(exit.cause);
122
+ };
123
+ /**
124
+ * @since 1.0.0
125
+ * @category hooks
126
+ */
127
+ const useAtomMount = atom => {
128
+ const registry = React.useContext(_RegistryContext.RegistryContext);
129
+ mountAtom(registry, atom);
130
+ };
131
+ /**
132
+ * @since 1.0.0
133
+ * @category hooks
134
+ */
135
+ exports.useAtomMount = useAtomMount;
136
+ const useAtomSet = (atom, options) => {
137
+ const registry = React.useContext(_RegistryContext.RegistryContext);
138
+ mountAtom(registry, atom);
139
+ return setAtom(registry, atom, options);
140
+ };
141
+ /**
142
+ * @since 1.0.0
143
+ * @category hooks
144
+ */
145
+ exports.useAtomSet = useAtomSet;
146
+ const useAtomRefresh = atom => {
147
+ const registry = React.useContext(_RegistryContext.RegistryContext);
148
+ mountAtom(registry, atom);
149
+ return React.useCallback(() => {
150
+ registry.refresh(atom);
151
+ }, [registry, atom]);
152
+ };
153
+ /**
154
+ * @since 1.0.0
155
+ * @category hooks
156
+ */
157
+ exports.useAtomRefresh = useAtomRefresh;
158
+ const useAtom = (atom, options) => {
159
+ const registry = React.useContext(_RegistryContext.RegistryContext);
160
+ return [useStore(registry, atom), setAtom(registry, atom, options)];
161
+ };
162
+ exports.useAtom = useAtom;
163
+ const atomPromiseMap = /*#__PURE__*/(0, _GlobalValue.globalValue)("@effect-atom/atom-react/atomPromiseMap", () => ({
164
+ suspendOnWaiting: new Map(),
165
+ default: new Map()
166
+ }));
167
+ function atomToPromise(registry, atom, suspendOnWaiting) {
168
+ const map = suspendOnWaiting ? atomPromiseMap.suspendOnWaiting : atomPromiseMap.default;
169
+ let promise = map.get(atom);
170
+ if (promise !== undefined) {
171
+ return promise;
172
+ }
173
+ promise = new Promise(resolve => {
174
+ const dispose = registry.subscribe(atom, result => {
175
+ if (result._tag === "Initial" || suspendOnWaiting && result.waiting) {
176
+ return;
177
+ }
178
+ setTimeout(dispose, 1000);
179
+ resolve();
180
+ map.delete(atom);
181
+ });
182
+ });
183
+ map.set(atom, promise);
184
+ return promise;
185
+ }
186
+ function atomResultOrSuspend(registry, atom, suspendOnWaiting) {
187
+ const value = useStore(registry, atom);
188
+ if (value._tag === "Initial" || suspendOnWaiting && value.waiting) {
189
+ throw atomToPromise(registry, atom, suspendOnWaiting);
190
+ }
191
+ return value;
192
+ }
193
+ /**
194
+ * @since 1.0.0
195
+ * @category hooks
196
+ */
197
+ const useAtomSuspense = (atom, options) => {
198
+ const registry = React.useContext(_RegistryContext.RegistryContext);
199
+ const result = atomResultOrSuspend(registry, atom, options?.suspendOnWaiting ?? false);
200
+ if (result._tag === "Failure" && !options?.includeFailure) {
201
+ throw Cause.squash(result.cause);
202
+ }
203
+ return result;
204
+ };
205
+ /**
206
+ * @since 1.0.0
207
+ * @category hooks
208
+ */
209
+ exports.useAtomSuspense = useAtomSuspense;
210
+ const useAtomSubscribe = (atom, f, options) => {
211
+ const registry = React.useContext(_RegistryContext.RegistryContext);
212
+ React.useEffect(() => registry.subscribe(atom, f, options), [registry, atom, f, options?.immediate]);
213
+ };
214
+ /**
215
+ * @since 1.0.0
216
+ * @category hooks
217
+ */
218
+ exports.useAtomSubscribe = useAtomSubscribe;
219
+ const useAtomRef = ref => {
220
+ const [, setValue] = React.useState(ref.value);
221
+ React.useEffect(() => ref.subscribe(setValue), [ref]);
222
+ return ref.value;
223
+ };
224
+ /**
225
+ * @since 1.0.0
226
+ * @category hooks
227
+ */
228
+ exports.useAtomRef = useAtomRef;
229
+ const useAtomRefProp = (ref, prop) => React.useMemo(() => ref.prop(prop), [ref, prop]);
230
+ /**
231
+ * @since 1.0.0
232
+ * @category hooks
233
+ */
234
+ exports.useAtomRefProp = useAtomRefProp;
235
+ const useAtomRefPropValue = (ref, prop) => useAtomRef(useAtomRefProp(ref, prop));
236
+ exports.useAtomRefPropValue = useAtomRefPropValue;
237
+ //# sourceMappingURL=Hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Hooks.js","names":["Object","defineProperty","exports","value","useAtomValue","useAtomSuspense","useAtomSubscribe","useAtomSet","useAtomRefresh","useAtomRefPropValue","useAtomRefProp","useAtomRef","useAtomMount","useAtomInitialValues","useAtom","Atom","_interopRequireWildcard","require","Registry","_effect","Cause","Exit","_GlobalValue","React","_RegistryContext","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","getOwnPropertyDescriptor","storeRegistry","globalValue","makeStore","registry","atom","stores","undefined","store","newStore","subscribe","snapshot","getServerSnapshot","getServerValue","useStore","useSyncExternalStore","initialValuesSet","initialValues","useContext","RegistryContext","WeakSet","add","ensureNode","setValue","atomB","useMemo","map","mountAtom","useEffect","mount","setAtom","options","mode","useCallback","opts","promise","Effect","runPromiseExit","getResult","suspendOnWaiting","then","flattenExit","exit","isSuccess","squash","cause","refresh","atomPromiseMap","Map","atomToPromise","Promise","resolve","dispose","result","_tag","waiting","setTimeout","delete","atomResultOrSuspend","includeFailure","immediate","ref","useState","prop"],"sources":["../../src/Hooks.ts"],"sourcesContent":[null],"mappings":";;AAAA;;;AAGA,YAAY;;AAAAA,MAAA,CAAAC,cAAA,CAAAC,OAAA;EAAAC,KAAA;AAAA;AAAAD,OAA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C,eAAe,CAAC;EAClDrC,KAAK,CAAC8C,SAAS,CACb,MAAMxB,QAAQ,CAACM,SAAS,CAACL,IAAI,EAAEb,CAAC,EAAEuC,OAAO,CAAC,EAC1C,CAAC3B,QAAQ,EAAEC,IAAI,EAAEb,CAAC,EAAEuC,OAAO,EAAE6B,SAAS,CAAC,CACxC;AACH,CAAC;AAED;;;;AAAAnG,OAAA,CAAAI,gBAAA,GAAAA,gBAAA;AAIO,MAAMK,UAAU,GAAO2F,GAA2B,IAAO;EAC9D,MAAM,GAAGtC,QAAQ,CAAC,GAAGzC,KAAK,CAACgF,QAAQ,CAACD,GAAG,CAACnG,KAAK,CAAC;EAC9CoB,KAAK,CAAC8C,SAAS,CAAC,MAAMiC,GAAG,CAACnD,SAAS,CAACa,QAAQ,CAAC,EAAE,CAACsC,GAAG,CAAC,CAAC;EACrD,OAAOA,GAAG,CAACnG,KAAK;AAClB,CAAC;AAED;;;;AAAAD,OAAA,CAAAS,UAAA,GAAAA,UAAA;AAIO,MAAMD,cAAc,GAAGA,CAAuB4F,GAAuB,EAAEE,IAAO,KACnFjF,KAAK,CAAC2C,OAAO,CAAC,MAAMoC,GAAG,CAACE,IAAI,CAACA,IAAI,CAAC,EAAE,CAACF,GAAG,EAAEE,IAAI,CAAC,CAAC;AAElD;;;;AAAAtG,OAAA,CAAAQ,cAAA,GAAAA,cAAA;AAIO,MAAMD,mBAAmB,GAAGA,CAAuB6F,GAAuB,EAAEE,IAAO,KACxF7F,UAAU,CAACD,cAAc,CAAC4F,GAAG,EAAEE,IAAI,CAAC,CAAC;AAAAtG,OAAA,CAAAO,mBAAA,GAAAA,mBAAA","ignoreList":[]}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @since 1.0.0
5
+ */
6
+ "use client";
7
+
8
+ Object.defineProperty(exports, "__esModule", {
9
+ value: true
10
+ });
11
+ exports.HydrationBoundary = void 0;
12
+ var Hydration = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@effect-atom/atom/Hydration"));
13
+ var React = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("react"));
14
+ var _RegistryContext = /*#__PURE__*/require("./RegistryContext.js");
15
+ function _interopRequireWildcard(e, t) {
16
+ if ("function" == typeof WeakMap) var r = new WeakMap(),
17
+ n = new WeakMap();
18
+ return (_interopRequireWildcard = function (e, t) {
19
+ if (!t && e && e.__esModule) return e;
20
+ var o,
21
+ i,
22
+ f = {
23
+ __proto__: null,
24
+ default: e
25
+ };
26
+ if (null === e || "object" != typeof e && "function" != typeof e) return f;
27
+ if (o = t ? n : r) {
28
+ if (o.has(e)) return o.get(e);
29
+ o.set(e, f);
30
+ }
31
+ for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]);
32
+ return f;
33
+ })(e, t);
34
+ }
35
+ /**
36
+ * @since 1.0.0
37
+ * @category components
38
+ */
39
+ const HydrationBoundary = ({
40
+ children,
41
+ state
42
+ }) => {
43
+ const registry = React.useContext(_RegistryContext.RegistryContext);
44
+ // This useMemo is for performance reasons only, everything inside it must
45
+ // be safe to run in every render and code here should be read as "in render".
46
+ //
47
+ // This code needs to happen during the render phase, because after initial
48
+ // SSR, hydration needs to happen _before_ children render. Also, if hydrating
49
+ // during a transition, we want to hydrate as much as is safe in render so
50
+ // we can prerender as much as possible.
51
+ //
52
+ // For any Atom values that already exist in the registry, we want to hold back on
53
+ // hydrating until _after_ the render phase. The reason for this is that during
54
+ // transitions, we don't want the existing Atom values and subscribers to update to
55
+ // the new data on the current page, only _after_ the transition is committed.
56
+ // If the transition is aborted, we will have hydrated any _new_ Atom values, but
57
+ // we throw away the fresh data for any existing ones to avoid unexpectedly
58
+ // updating the UI.
59
+ const hydrationQueue = React.useMemo(() => {
60
+ if (state) {
61
+ const dehydratedAtoms = Array.from(state);
62
+ const nodes = registry.getNodes();
63
+ const newDehydratedAtoms = [];
64
+ const existingDehydratedAtoms = [];
65
+ for (const dehydratedAtom of dehydratedAtoms) {
66
+ const existingNode = nodes.get(dehydratedAtom.key);
67
+ if (!existingNode) {
68
+ // This is a new Atom value, safe to hydrate immediately
69
+ newDehydratedAtoms.push(dehydratedAtom);
70
+ } else {
71
+ // This Atom value already exists, queue it for later hydration
72
+ // TODO: Add logic to check if hydration data is newer
73
+ existingDehydratedAtoms.push(dehydratedAtom);
74
+ }
75
+ }
76
+ if (newDehydratedAtoms.length > 0) {
77
+ // It's actually fine to call this with state that already exists
78
+ // in the registry, or is older. hydrate() is idempotent.
79
+ Hydration.hydrate(registry, newDehydratedAtoms);
80
+ }
81
+ if (existingDehydratedAtoms.length > 0) {
82
+ return existingDehydratedAtoms;
83
+ }
84
+ }
85
+ return undefined;
86
+ }, [registry, state]);
87
+ React.useEffect(() => {
88
+ if (hydrationQueue) {
89
+ Hydration.hydrate(registry, hydrationQueue);
90
+ }
91
+ }, [registry, hydrationQueue]);
92
+ return React.createElement(React.Fragment, {}, children);
93
+ };
94
+ exports.HydrationBoundary = HydrationBoundary;
95
+ //# sourceMappingURL=ReactHydration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactHydration.js","names":["Object","defineProperty","exports","value","HydrationBoundary","Hydration","_interopRequireWildcard","require","React","_RegistryContext","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","getOwnPropertyDescriptor","children","state","registry","useContext","RegistryContext","hydrationQueue","useMemo","dehydratedAtoms","Array","from","nodes","getNodes","newDehydratedAtoms","existingDehydratedAtoms","dehydratedAtom","existingNode","key","push","length","hydrate","undefined","useEffect","createElement","Fragment"],"sources":["../../src/ReactHydration.ts"],"sourcesContent":[null],"mappings":";;AAAA;;;AAGA,YAAY;;AAAAA,MAAA,CAAAC,cAAA,CAAAC,OAAA;EAAAC,KAAA;AAAA;AAAAD,OAAA,CAAAE,iBAAA;AACZ,IAAAC,SAAA,gBAAAC,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Q,EAAE,EAAE,EAAEvB,QAAQ,CAAC;AAC1D,CAAC;AAAAzB,OAAA,CAAAE,iBAAA,GAAAA,iBAAA","ignoreList":[]}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @since 1.0.0
5
+ */
6
+ "use client";
7
+
8
+ Object.defineProperty(exports, "__esModule", {
9
+ value: true
10
+ });
11
+ exports.RegistryProvider = exports.RegistryContext = void 0;
12
+ exports.scheduleTask = scheduleTask;
13
+ var Registry = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@effect-atom/atom/Registry"));
14
+ var React = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("react"));
15
+ var Scheduler = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("scheduler"));
16
+ function _interopRequireWildcard(e, t) {
17
+ if ("function" == typeof WeakMap) var r = new WeakMap(),
18
+ n = new WeakMap();
19
+ return (_interopRequireWildcard = function (e, t) {
20
+ if (!t && e && e.__esModule) return e;
21
+ var o,
22
+ i,
23
+ f = {
24
+ __proto__: null,
25
+ default: e
26
+ };
27
+ if (null === e || "object" != typeof e && "function" != typeof e) return f;
28
+ if (o = t ? n : r) {
29
+ if (o.has(e)) return o.get(e);
30
+ o.set(e, f);
31
+ }
32
+ for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]);
33
+ return f;
34
+ })(e, t);
35
+ }
36
+ /**
37
+ * @since 1.0.0
38
+ * @category context
39
+ */
40
+ function scheduleTask(f) {
41
+ Scheduler.unstable_scheduleCallback(Scheduler.unstable_LowPriority, f);
42
+ }
43
+ /**
44
+ * @since 1.0.0
45
+ * @category context
46
+ */
47
+ const RegistryContext = exports.RegistryContext = /*#__PURE__*/React.createContext(/*#__PURE__*/Registry.make({
48
+ scheduleTask,
49
+ defaultIdleTTL: 400
50
+ }));
51
+ /**
52
+ * @since 1.0.0
53
+ * @category context
54
+ */
55
+ const RegistryProvider = options => {
56
+ const ref = React.useRef(null);
57
+ if (ref.current === null) {
58
+ ref.current = {
59
+ registry: Registry.make({
60
+ scheduleTask: options.scheduleTask ?? scheduleTask,
61
+ initialValues: options.initialValues,
62
+ timeoutResolution: options.timeoutResolution,
63
+ defaultIdleTTL: options.defaultIdleTTL
64
+ })
65
+ };
66
+ }
67
+ React.useEffect(() => {
68
+ if (ref.current?.timeout !== undefined) {
69
+ clearTimeout(ref.current.timeout);
70
+ }
71
+ return () => {
72
+ ref.current.timeout = setTimeout(() => {
73
+ ref.current?.registry.dispose();
74
+ ref.current = null;
75
+ }, 500);
76
+ };
77
+ }, [ref]);
78
+ return React.createElement(RegistryContext.Provider, {
79
+ value: ref.current.registry
80
+ }, options?.children);
81
+ };
82
+ exports.RegistryProvider = RegistryProvider;
83
+ //# sourceMappingURL=RegistryContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegistryContext.js","names":["Object","defineProperty","exports","value","RegistryProvider","RegistryContext","scheduleTask","Registry","_interopRequireWildcard","require","React","Scheduler","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","getOwnPropertyDescriptor","unstable_scheduleCallback","unstable_LowPriority","createContext","make","defaultIdleTTL","options","ref","useRef","current","registry","initialValues","timeoutResolution","useEffect","timeout","undefined","clearTimeout","setTimeout","dispose","createElement","Provider","children"],"sources":["../../src/RegistryContext.ts"],"sourcesContent":[null],"mappings":";;AAAA;;;AAGA,YAAY;;AAAAA,MAAA,CAAAC,cAAA,CAAAC,OAAA;EAAAC,KAAA;AAAA;AAAAD,OAAA,CAAAE,gBAAA,GAAAF,OAAA,CAAAG,eAAA;AAAAH,OAAA,CAAAI,YAAA,GAAAA,YAAA;AAEZ,IAAAC,QAAA,gBAAAC,uBAAA,cAAAC,OAAA;AACA,IAAAC,KAAA,gBAAAF,uBAAA,cAAAC,OAAA;AACA,IAAAE,SAAA,gBA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strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ Atom: true,
8
+ Registry: true,
9
+ Result: true,
10
+ AtomRef: true,
11
+ Hydration: true
12
+ };
13
+ exports.Result = exports.Registry = exports.Hydration = exports.AtomRef = exports.Atom = void 0;
14
+ var _Atom = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@effect-atom/atom/Atom"));
15
+ exports.Atom = _Atom;
16
+ var _Registry = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@effect-atom/atom/Registry"));
17
+ exports.Registry = _Registry;
18
+ var _Result = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@effect-atom/atom/Result"));
19
+ exports.Result = _Result;
20
+ var _AtomRef = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@effect-atom/atom/AtomRef"));
21
+ exports.AtomRef = _AtomRef;
22
+ var _Hydration = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("@effect-atom/atom/Hydration"));
23
+ exports.Hydration = _Hydration;
24
+ var _Hooks = /*#__PURE__*/require("./Hooks.js");
25
+ Object.keys(_Hooks).forEach(function (key) {
26
+ if (key === "default" || key === "__esModule") return;
27
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
28
+ if (key in exports && exports[key] === _Hooks[key]) return;
29
+ Object.defineProperty(exports, key, {
30
+ enumerable: true,
31
+ get: function () {
32
+ return _Hooks[key];
33
+ }
34
+ });
35
+ });
36
+ var _RegistryContext = /*#__PURE__*/require("./RegistryContext.js");
37
+ Object.keys(_RegistryContext).forEach(function (key) {
38
+ if (key === "default" || key === "__esModule") return;
39
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
40
+ if (key in exports && exports[key] === _RegistryContext[key]) return;
41
+ Object.defineProperty(exports, key, {
42
+ enumerable: true,
43
+ get: function () {
44
+ return _RegistryContext[key];
45
+ }
46
+ });
47
+ });
48
+ function _interopRequireWildcard(e, t) {
49
+ if ("function" == typeof WeakMap) var r = new WeakMap(),
50
+ n = new WeakMap();
51
+ return (_interopRequireWildcard = function (e, t) {
52
+ if (!t && e && e.__esModule) return e;
53
+ var o,
54
+ i,
55
+ f = {
56
+ __proto__: null,
57
+ default: e
58
+ };
59
+ if (null === e || "object" != typeof e && "function" != typeof e) return f;
60
+ if (o = t ? n : r) {
61
+ if (o.has(e)) return o.get(e);
62
+ o.set(e, f);
63
+ }
64
+ for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]);
65
+ return f;
66
+ })(e, t);
67
+ }
68
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_Hooks","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_RegistryContext","_interopRequireWildcard","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","set","getOwnPropertyDescriptor"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsCA,IAAAA,MAAA,gBAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAb,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AAMA,IAAAS,gBAAA,gBAAAb,OAAA;AAAAC,MAAA,CAAAC,I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AU,CAAA,CAAAK,GAAA,IAAAN,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA;IAAA,OAAAO,CAAA;EAAA,GAAAR,CAAA,EAAAC,CAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,80 @@
1
+ import * as Atom from "@effect-atom/atom/Atom";
2
+ import type * as AtomRef from "@effect-atom/atom/AtomRef";
3
+ import type * as Result from "@effect-atom/atom/Result";
4
+ import * as Exit from "effect/Exit";
5
+ /**
6
+ * @since 1.0.0
7
+ * @category hooks
8
+ */
9
+ export declare const useAtomInitialValues: (initialValues: Iterable<readonly [Atom.Atom<any>, any]>) => void;
10
+ /**
11
+ * @since 1.0.0
12
+ * @category hooks
13
+ */
14
+ export declare const useAtomValue: {
15
+ <A>(atom: Atom.Atom<A>): A;
16
+ <A, B>(atom: Atom.Atom<A>, f: (_: A) => B): B;
17
+ };
18
+ /**
19
+ * @since 1.0.0
20
+ * @category hooks
21
+ */
22
+ export declare const useAtomMount: <A>(atom: Atom.Atom<A>) => void;
23
+ /**
24
+ * @since 1.0.0
25
+ * @category hooks
26
+ */
27
+ export declare const useAtomSet: <R, W, Mode extends "value" | "promise" | "promiseExit" = never>(atom: Atom.Writable<R, W>, options?: {
28
+ readonly mode?: ([R] extends [Result.Result<any, any>] ? Mode : "value") | undefined;
29
+ }) => "promise" extends Mode ? ((value: W, options?: {
30
+ readonly signal?: AbortSignal | undefined;
31
+ } | undefined) => Promise<Result.Result.Success<R>>) : "promiseExit" extends Mode ? ((value: W, options?: {
32
+ readonly signal?: AbortSignal | undefined;
33
+ } | undefined) => Promise<Exit.Exit<Result.Result.Success<R>, Result.Result.Failure<R>>>) : ((value: W | ((value: R) => W)) => void);
34
+ /**
35
+ * @since 1.0.0
36
+ * @category hooks
37
+ */
38
+ export declare const useAtomRefresh: <A>(atom: Atom.Atom<A>) => () => void;
39
+ /**
40
+ * @since 1.0.0
41
+ * @category hooks
42
+ */
43
+ export declare const useAtom: <R, W, const Mode extends "value" | "promise" | "promiseExit" = never>(atom: Atom.Writable<R, W>, options?: {
44
+ readonly mode?: ([R] extends [Result.Result<any, any>] ? Mode : "value") | undefined;
45
+ }) => readonly [value: R, write: "promise" extends Mode ? ((value: W, options?: {
46
+ readonly signal?: AbortSignal | undefined;
47
+ } | undefined) => Promise<Result.Result.Success<R>>) : "promiseExit" extends Mode ? ((value: W, options?: {
48
+ readonly signal?: AbortSignal | undefined;
49
+ } | undefined) => Promise<Exit.Exit<Result.Result.Success<R>, Result.Result.Failure<R>>>) : ((value: W | ((value: R) => W)) => void)];
50
+ /**
51
+ * @since 1.0.0
52
+ * @category hooks
53
+ */
54
+ export declare const useAtomSuspense: <A, E, const IncludeFailure extends boolean = false>(atom: Atom.Atom<Result.Result<A, E>>, options?: {
55
+ readonly suspendOnWaiting?: boolean | undefined;
56
+ readonly includeFailure?: IncludeFailure | undefined;
57
+ }) => Result.Success<A, E> | (IncludeFailure extends true ? Result.Failure<A, E> : never);
58
+ /**
59
+ * @since 1.0.0
60
+ * @category hooks
61
+ */
62
+ export declare const useAtomSubscribe: <A>(atom: Atom.Atom<A>, f: (_: A) => void, options?: {
63
+ readonly immediate?: boolean;
64
+ }) => void;
65
+ /**
66
+ * @since 1.0.0
67
+ * @category hooks
68
+ */
69
+ export declare const useAtomRef: <A>(ref: AtomRef.ReadonlyRef<A>) => A;
70
+ /**
71
+ * @since 1.0.0
72
+ * @category hooks
73
+ */
74
+ export declare const useAtomRefProp: <A, K extends keyof A>(ref: AtomRef.AtomRef<A>, prop: K) => AtomRef.AtomRef<A[K]>;
75
+ /**
76
+ * @since 1.0.0
77
+ * @category hooks
78
+ */
79
+ export declare const useAtomRefPropValue: <A, K extends keyof A>(ref: AtomRef.AtomRef<A>, prop: K) => A[K];
80
+ //# sourceMappingURL=Hooks.d.ts.map