@effect/atom-react 4.0.0-beta.8 → 4.0.0-beta.81
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.
- package/dist/Hooks.d.ts +214 -13
- package/dist/Hooks.d.ts.map +1 -1
- package/dist/Hooks.js +186 -12
- package/dist/Hooks.js.map +1 -1
- package/dist/ReactHydration.d.ts +22 -2
- package/dist/ReactHydration.d.ts.map +1 -1
- package/dist/ReactHydration.js +25 -2
- package/dist/ReactHydration.js.map +1 -1
- package/dist/RegistryContext.d.ts +40 -3
- package/dist/RegistryContext.d.ts.map +1 -1
- package/dist/RegistryContext.js +46 -4
- package/dist/RegistryContext.js.map +1 -1
- package/dist/ScopedAtom.d.ts +49 -23
- package/dist/ScopedAtom.d.ts.map +1 -1
- package/dist/ScopedAtom.js +38 -12
- package/dist/ScopedAtom.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -5
- package/package.json +9 -9
- package/src/Hooks.ts +220 -14
- package/src/ReactHydration.ts +29 -3
- package/src/RegistryContext.ts +46 -4
- package/src/ScopedAtom.ts +55 -24
- package/src/index.ts +5 -5
package/dist/Hooks.d.ts
CHANGED
|
@@ -3,78 +3,279 @@ import type * as AsyncResult from "effect/unstable/reactivity/AsyncResult";
|
|
|
3
3
|
import * as Atom from "effect/unstable/reactivity/Atom";
|
|
4
4
|
import type * as AtomRef from "effect/unstable/reactivity/AtomRef";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Seeds initial atom values in the current React atom registry.
|
|
7
|
+
*
|
|
8
|
+
* **When to use**
|
|
9
|
+
*
|
|
10
|
+
* Use to seed atom values from a React component after the current registry
|
|
11
|
+
* already exists.
|
|
12
|
+
*
|
|
13
|
+
* **Gotchas**
|
|
14
|
+
*
|
|
15
|
+
* Each atom is initialized at most once for a given registry by this hook, so
|
|
16
|
+
* later calls for the same atom in that registry are ignored.
|
|
17
|
+
*
|
|
7
18
|
* @category hooks
|
|
19
|
+
* @since 4.0.0
|
|
8
20
|
*/
|
|
9
21
|
export declare const useAtomInitialValues: (initialValues: Iterable<readonly [Atom.Atom<any>, any]>) => void;
|
|
10
22
|
/**
|
|
11
|
-
*
|
|
23
|
+
* Subscribes to an atom in the current React registry and returns its current
|
|
24
|
+
* value, optionally mapped through a selector.
|
|
25
|
+
*
|
|
26
|
+
* **When to use**
|
|
27
|
+
*
|
|
28
|
+
* Use when a React component needs to render from an atom value without also
|
|
29
|
+
* returning a setter.
|
|
30
|
+
*
|
|
31
|
+
* **Details**
|
|
32
|
+
*
|
|
33
|
+
* When a selector is provided, the hook maps the atom before subscribing so the
|
|
34
|
+
* component reads the selected value from the current `RegistryContext`.
|
|
35
|
+
*
|
|
36
|
+
* @see {@link useAtom} for reading and updating a writable atom from one component
|
|
37
|
+
* @see {@link useAtomRef} for reading an `AtomRef` directly
|
|
38
|
+
*
|
|
12
39
|
* @category hooks
|
|
40
|
+
* @since 4.0.0
|
|
13
41
|
*/
|
|
14
42
|
export declare const useAtomValue: {
|
|
15
43
|
/**
|
|
16
|
-
*
|
|
44
|
+
* Subscribes to an atom in the current React registry and returns its current
|
|
45
|
+
* value, optionally mapped through a selector.
|
|
46
|
+
*
|
|
47
|
+
* **When to use**
|
|
48
|
+
*
|
|
49
|
+
* Use when a React component needs to render from an atom value without also
|
|
50
|
+
* returning a setter.
|
|
51
|
+
*
|
|
52
|
+
* **Details**
|
|
53
|
+
*
|
|
54
|
+
* When a selector is provided, the hook maps the atom before subscribing so the
|
|
55
|
+
* component reads the selected value from the current `RegistryContext`.
|
|
56
|
+
*
|
|
57
|
+
* @see {@link useAtom} for reading and updating a writable atom from one component
|
|
58
|
+
* @see {@link useAtomRef} for reading an `AtomRef` directly
|
|
59
|
+
*
|
|
17
60
|
* @category hooks
|
|
61
|
+
* @since 4.0.0
|
|
18
62
|
*/
|
|
19
63
|
<A>(atom: Atom.Atom<A>): A;
|
|
20
64
|
/**
|
|
21
|
-
*
|
|
65
|
+
* Subscribes to an atom in the current React registry and returns its current
|
|
66
|
+
* value, optionally mapped through a selector.
|
|
67
|
+
*
|
|
68
|
+
* **When to use**
|
|
69
|
+
*
|
|
70
|
+
* Use when a React component needs to render from an atom value without also
|
|
71
|
+
* returning a setter.
|
|
72
|
+
*
|
|
73
|
+
* **Details**
|
|
74
|
+
*
|
|
75
|
+
* When a selector is provided, the hook maps the atom before subscribing so the
|
|
76
|
+
* component reads the selected value from the current `RegistryContext`.
|
|
77
|
+
*
|
|
78
|
+
* @see {@link useAtom} for reading and updating a writable atom from one component
|
|
79
|
+
* @see {@link useAtomRef} for reading an `AtomRef` directly
|
|
80
|
+
*
|
|
22
81
|
* @category hooks
|
|
82
|
+
* @since 4.0.0
|
|
23
83
|
*/
|
|
24
84
|
<A, B>(atom: Atom.Atom<A>, f: (_: A) => B): B;
|
|
25
85
|
};
|
|
26
86
|
/**
|
|
27
|
-
*
|
|
87
|
+
* Mounts an atom in the current React registry for the lifetime of the
|
|
88
|
+
* component.
|
|
89
|
+
*
|
|
90
|
+
* **When to use**
|
|
91
|
+
*
|
|
92
|
+
* Use to keep an atom mounted from a React component without reading, writing,
|
|
93
|
+
* or refreshing it.
|
|
94
|
+
*
|
|
95
|
+
* **Details**
|
|
96
|
+
*
|
|
97
|
+
* The hook uses the current `RegistryContext` and releases the mount through
|
|
98
|
+
* React effect cleanup when the component unmounts or when the registry or atom
|
|
99
|
+
* dependency changes.
|
|
100
|
+
*
|
|
101
|
+
* @see {@link useAtomSet} for mounting a writable atom while returning a setter
|
|
102
|
+
* @see {@link useAtomRefresh} for mounting an atom while returning a refresh callback
|
|
103
|
+
*
|
|
28
104
|
* @category hooks
|
|
105
|
+
* @since 4.0.0
|
|
29
106
|
*/
|
|
30
107
|
export declare const useAtomMount: <A>(atom: Atom.Atom<A>) => void;
|
|
31
108
|
/**
|
|
32
|
-
*
|
|
109
|
+
* Mounts a writable atom and returns a setter without subscribing to its value.
|
|
110
|
+
*
|
|
111
|
+
* **When to use**
|
|
112
|
+
*
|
|
113
|
+
* Use when a React component needs to update a writable atom without rendering
|
|
114
|
+
* from that atom's value.
|
|
115
|
+
*
|
|
116
|
+
* **Details**
|
|
117
|
+
*
|
|
118
|
+
* The hook mounts the atom and returns a setter. In value mode the setter
|
|
119
|
+
* accepts a write value or updater function; for `AsyncResult` atoms, `promise`
|
|
120
|
+
* and `promiseExit` modes return a promise for the success value or full `Exit`.
|
|
121
|
+
*
|
|
122
|
+
* @see {@link useAtom} for reading and updating the same writable atom
|
|
123
|
+
*
|
|
33
124
|
* @category hooks
|
|
125
|
+
* @since 4.0.0
|
|
34
126
|
*/
|
|
35
127
|
export declare const useAtomSet: <R, W, Mode extends "value" | "promise" | "promiseExit" = never>(atom: Atom.Writable<R, W>, options?: {
|
|
36
128
|
readonly mode?: ([R] extends [AsyncResult.AsyncResult<any, any>] ? Mode : "value") | undefined;
|
|
37
129
|
}) => "promise" extends Mode ? ((value: W) => Promise<AsyncResult.AsyncResult.Success<R>>) : "promiseExit" extends Mode ? ((value: W) => Promise<Exit.Exit<AsyncResult.AsyncResult.Success<R>, AsyncResult.AsyncResult.Failure<R>>>) : ((value: W | ((value: R) => W)) => void);
|
|
38
130
|
/**
|
|
39
|
-
*
|
|
131
|
+
* Mounts an atom and returns a callback that refreshes it in the current React
|
|
132
|
+
* registry.
|
|
133
|
+
*
|
|
134
|
+
* **When to use**
|
|
135
|
+
*
|
|
136
|
+
* Use to expose a React callback that requests a refresh for an atom without
|
|
137
|
+
* reading or writing its value.
|
|
138
|
+
*
|
|
139
|
+
* **Details**
|
|
140
|
+
*
|
|
141
|
+
* The hook uses the current `RegistryContext`, mounts the atom for the
|
|
142
|
+
* component lifetime, and returns a callback that calls `registry.refresh`.
|
|
143
|
+
*
|
|
144
|
+
* @see {@link useAtomMount} for mounting an atom without returning a refresh callback
|
|
145
|
+
*
|
|
40
146
|
* @category hooks
|
|
147
|
+
* @since 4.0.0
|
|
41
148
|
*/
|
|
42
149
|
export declare const useAtomRefresh: <A>(atom: Atom.Atom<A>) => () => void;
|
|
43
150
|
/**
|
|
44
|
-
*
|
|
151
|
+
* Subscribes to a writable atom and returns its current value together with a
|
|
152
|
+
* setter for updating it.
|
|
153
|
+
*
|
|
154
|
+
* **When to use**
|
|
155
|
+
*
|
|
156
|
+
* Use when a React component needs both to render the current value of a
|
|
157
|
+
* writable atom and update it from the same component.
|
|
158
|
+
*
|
|
159
|
+
* @see {@link useAtomValue} for subscribing to an atom without a setter
|
|
160
|
+
* @see {@link useAtomSet} for updating a writable atom without subscribing to its value
|
|
161
|
+
*
|
|
45
162
|
* @category hooks
|
|
163
|
+
* @since 4.0.0
|
|
46
164
|
*/
|
|
47
165
|
export declare const useAtom: <R, W, const Mode extends "value" | "promise" | "promiseExit" = never>(atom: Atom.Writable<R, W>, options?: {
|
|
48
166
|
readonly mode?: ([R] extends [AsyncResult.AsyncResult<any, any>] ? Mode : "value") | undefined;
|
|
49
167
|
}) => readonly [value: R, write: "promise" extends Mode ? ((value: W) => Promise<AsyncResult.AsyncResult.Success<R>>) : "promiseExit" extends Mode ? ((value: W) => Promise<Exit.Exit<AsyncResult.AsyncResult.Success<R>, AsyncResult.AsyncResult.Failure<R>>>) : ((value: W | ((value: R) => W)) => void)];
|
|
50
168
|
/**
|
|
51
|
-
*
|
|
169
|
+
* Reads an `AsyncResult` atom through React Suspense, suspending while the
|
|
170
|
+
* result is initial or configured as waiting.
|
|
171
|
+
*
|
|
172
|
+
* **When to use**
|
|
173
|
+
*
|
|
174
|
+
* Use when a React component should render only after an `AsyncResult` atom has
|
|
175
|
+
* left its initial state, with loading delegated to a Suspense boundary.
|
|
176
|
+
*
|
|
177
|
+
* **Details**
|
|
178
|
+
*
|
|
179
|
+
* `suspendOnWaiting` defaults to `false`. When `includeFailure` is `true`, a
|
|
180
|
+
* failure result is returned instead of being thrown.
|
|
181
|
+
*
|
|
182
|
+
* **Gotchas**
|
|
183
|
+
*
|
|
184
|
+
* Without `includeFailure`, failure results are thrown with
|
|
185
|
+
* `Cause.squash(result.cause)`, so callers need an error boundary for failures.
|
|
186
|
+
*
|
|
187
|
+
* @see {@link useAtomValue} for reading the raw `AsyncResult` value without Suspense
|
|
188
|
+
*
|
|
52
189
|
* @category hooks
|
|
190
|
+
* @since 4.0.0
|
|
53
191
|
*/
|
|
54
192
|
export declare const useAtomSuspense: <A, E, const IncludeFailure extends boolean = false>(atom: Atom.Atom<AsyncResult.AsyncResult<A, E>>, options?: {
|
|
55
193
|
readonly suspendOnWaiting?: boolean | undefined;
|
|
56
194
|
readonly includeFailure?: IncludeFailure | undefined;
|
|
57
195
|
}) => AsyncResult.Success<A, E> | (IncludeFailure extends true ? AsyncResult.Failure<A, E> : never);
|
|
58
196
|
/**
|
|
59
|
-
*
|
|
197
|
+
* Subscribes a callback to an atom in the current React registry for the
|
|
198
|
+
* component lifetime.
|
|
199
|
+
*
|
|
200
|
+
* **When to use**
|
|
201
|
+
*
|
|
202
|
+
* Use when a React component needs to run a callback for atom changes without
|
|
203
|
+
* reading the atom value during render.
|
|
204
|
+
*
|
|
205
|
+
* **Details**
|
|
206
|
+
*
|
|
207
|
+
* The subscription is installed in a React effect and cleaned up on unmount or
|
|
208
|
+
* dependency change. When `options.immediate` is enabled, the callback receives
|
|
209
|
+
* the current value when the effect subscribes.
|
|
210
|
+
*
|
|
211
|
+
* @see {@link useAtomValue} for reading an atom value during render instead of running a callback
|
|
212
|
+
*
|
|
60
213
|
* @category hooks
|
|
214
|
+
* @since 4.0.0
|
|
61
215
|
*/
|
|
62
216
|
export declare const useAtomSubscribe: <A>(atom: Atom.Atom<A>, f: (_: A) => void, options?: {
|
|
63
217
|
readonly immediate?: boolean;
|
|
64
218
|
}) => void;
|
|
65
219
|
/**
|
|
66
|
-
*
|
|
220
|
+
* Subscribes to an atom ref and returns its latest value.
|
|
221
|
+
*
|
|
222
|
+
* **When to use**
|
|
223
|
+
*
|
|
224
|
+
* Use when a React component should render from an `AtomRef.ReadonlyRef`
|
|
225
|
+
* directly instead of reading an atom through the current registry.
|
|
226
|
+
*
|
|
227
|
+
* **Details**
|
|
228
|
+
*
|
|
229
|
+
* The hook subscribes with `ref.subscribe`, triggers re-renders through React
|
|
230
|
+
* state, and returns the current `ref.value`.
|
|
231
|
+
*
|
|
232
|
+
* @see {@link useAtomValue} for reading an `Atom` from the current registry
|
|
233
|
+
* @see {@link useAtomRefPropValue} for reading a property ref value
|
|
234
|
+
*
|
|
67
235
|
* @category hooks
|
|
236
|
+
* @since 4.0.0
|
|
68
237
|
*/
|
|
69
238
|
export declare const useAtomRef: <A>(ref: AtomRef.ReadonlyRef<A>) => A;
|
|
70
239
|
/**
|
|
71
|
-
*
|
|
240
|
+
* Returns a memoized atom ref for a property of another atom ref.
|
|
241
|
+
*
|
|
242
|
+
* **When to use**
|
|
243
|
+
*
|
|
244
|
+
* Use to derive an `AtomRef` for one property of an object-shaped atom ref.
|
|
245
|
+
*
|
|
246
|
+
* **Details**
|
|
247
|
+
*
|
|
248
|
+
* The hook memoizes `ref.prop(prop)` for the `[ref, prop]` dependency pair and
|
|
249
|
+
* returns the property ref so callers can read, set, update, or subscribe to
|
|
250
|
+
* that nested property.
|
|
251
|
+
*
|
|
252
|
+
* @see {@link useAtomRef} for subscribing to an atom ref value
|
|
253
|
+
* @see {@link useAtomRefPropValue} for subscribing directly to a property value
|
|
254
|
+
*
|
|
72
255
|
* @category hooks
|
|
256
|
+
* @since 4.0.0
|
|
73
257
|
*/
|
|
74
258
|
export declare const useAtomRefProp: <A, K extends keyof A>(ref: AtomRef.AtomRef<A>, prop: K) => AtomRef.AtomRef<A[K]>;
|
|
75
259
|
/**
|
|
76
|
-
*
|
|
260
|
+
* Subscribes to a property ref derived from an atom ref and returns its current
|
|
261
|
+
* value.
|
|
262
|
+
*
|
|
263
|
+
* **When to use**
|
|
264
|
+
*
|
|
265
|
+
* Use when a React component needs only the current value of one property from
|
|
266
|
+
* an object-shaped `AtomRef`.
|
|
267
|
+
*
|
|
268
|
+
* **Details**
|
|
269
|
+
*
|
|
270
|
+
* The hook composes `useAtomRefProp(ref, prop)` with `useAtomRef`, so the
|
|
271
|
+
* property ref is memoized for the `[ref, prop]` pair and then subscribed
|
|
272
|
+
* through `ref.subscribe`.
|
|
273
|
+
*
|
|
274
|
+
* @see {@link useAtomRefProp} for returning the property ref directly
|
|
275
|
+
* @see {@link useAtomRef} for subscribing to a whole atom ref value
|
|
276
|
+
*
|
|
77
277
|
* @category hooks
|
|
278
|
+
* @since 4.0.0
|
|
78
279
|
*/
|
|
79
280
|
export declare const useAtomRefPropValue: <A, K extends keyof A>(ref: AtomRef.AtomRef<A>, prop: K) => A[K];
|
|
80
281
|
//# sourceMappingURL=Hooks.d.ts.map
|
package/dist/Hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Hooks.d.ts","sourceRoot":"","sources":["../src/Hooks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Hooks.d.ts","sourceRoot":"","sources":["../src/Hooks.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,KAAK,WAAW,MAAM,wCAAwC,CAAA;AAC1E,OAAO,KAAK,IAAI,MAAM,iCAAiC,CAAA;AACvD,OAAO,KAAK,KAAK,OAAO,MAAM,oCAAoC,CAAA;AA8ClE;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,oBAAoB,GAAI,eAAe,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,KAAG,IAa9F,CAAA;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,YAAY,EAAE;IACzB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IAC1B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,CAAC,C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atoms from components. The hooks read,
|
|
3
|
+
* write, mount, refresh, and subscribe to atoms from `RegistryContext`, handle
|
|
4
|
+
* `AsyncResult` atoms with React Suspense, and expose helpers for reading and
|
|
5
|
+
* deriving `AtomRef` values.
|
|
6
|
+
*
|
|
7
|
+
* @since 4.0.0
|
|
3
8
|
*/
|
|
4
9
|
"use client";
|
|
5
10
|
|
|
@@ -41,8 +46,20 @@ function useStore(registry, atom) {
|
|
|
41
46
|
}
|
|
42
47
|
const initialValuesSet = /*#__PURE__*/new WeakMap();
|
|
43
48
|
/**
|
|
44
|
-
*
|
|
49
|
+
* Seeds initial atom values in the current React atom registry.
|
|
50
|
+
*
|
|
51
|
+
* **When to use**
|
|
52
|
+
*
|
|
53
|
+
* Use to seed atom values from a React component after the current registry
|
|
54
|
+
* already exists.
|
|
55
|
+
*
|
|
56
|
+
* **Gotchas**
|
|
57
|
+
*
|
|
58
|
+
* Each atom is initialized at most once for a given registry by this hook, so
|
|
59
|
+
* later calls for the same atom in that registry are ignored.
|
|
60
|
+
*
|
|
45
61
|
* @category hooks
|
|
62
|
+
* @since 4.0.0
|
|
46
63
|
*/
|
|
47
64
|
export const useAtomInitialValues = initialValues => {
|
|
48
65
|
const registry = React.useContext(RegistryContext);
|
|
@@ -59,8 +76,24 @@ export const useAtomInitialValues = initialValues => {
|
|
|
59
76
|
}
|
|
60
77
|
};
|
|
61
78
|
/**
|
|
62
|
-
*
|
|
79
|
+
* Subscribes to an atom in the current React registry and returns its current
|
|
80
|
+
* value, optionally mapped through a selector.
|
|
81
|
+
*
|
|
82
|
+
* **When to use**
|
|
83
|
+
*
|
|
84
|
+
* Use when a React component needs to render from an atom value without also
|
|
85
|
+
* returning a setter.
|
|
86
|
+
*
|
|
87
|
+
* **Details**
|
|
88
|
+
*
|
|
89
|
+
* When a selector is provided, the hook maps the atom before subscribing so the
|
|
90
|
+
* component reads the selected value from the current `RegistryContext`.
|
|
91
|
+
*
|
|
92
|
+
* @see {@link useAtom} for reading and updating a writable atom from one component
|
|
93
|
+
* @see {@link useAtomRef} for reading an `AtomRef` directly
|
|
94
|
+
*
|
|
63
95
|
* @category hooks
|
|
96
|
+
* @since 4.0.0
|
|
64
97
|
*/
|
|
65
98
|
export const useAtomValue = (atom, f) => {
|
|
66
99
|
const registry = React.useContext(RegistryContext);
|
|
@@ -92,16 +125,48 @@ const flattenExit = exit => {
|
|
|
92
125
|
throw Cause.squash(exit.cause);
|
|
93
126
|
};
|
|
94
127
|
/**
|
|
95
|
-
*
|
|
128
|
+
* Mounts an atom in the current React registry for the lifetime of the
|
|
129
|
+
* component.
|
|
130
|
+
*
|
|
131
|
+
* **When to use**
|
|
132
|
+
*
|
|
133
|
+
* Use to keep an atom mounted from a React component without reading, writing,
|
|
134
|
+
* or refreshing it.
|
|
135
|
+
*
|
|
136
|
+
* **Details**
|
|
137
|
+
*
|
|
138
|
+
* The hook uses the current `RegistryContext` and releases the mount through
|
|
139
|
+
* React effect cleanup when the component unmounts or when the registry or atom
|
|
140
|
+
* dependency changes.
|
|
141
|
+
*
|
|
142
|
+
* @see {@link useAtomSet} for mounting a writable atom while returning a setter
|
|
143
|
+
* @see {@link useAtomRefresh} for mounting an atom while returning a refresh callback
|
|
144
|
+
*
|
|
96
145
|
* @category hooks
|
|
146
|
+
* @since 4.0.0
|
|
97
147
|
*/
|
|
98
148
|
export const useAtomMount = atom => {
|
|
99
149
|
const registry = React.useContext(RegistryContext);
|
|
100
150
|
mountAtom(registry, atom);
|
|
101
151
|
};
|
|
102
152
|
/**
|
|
103
|
-
*
|
|
153
|
+
* Mounts a writable atom and returns a setter without subscribing to its value.
|
|
154
|
+
*
|
|
155
|
+
* **When to use**
|
|
156
|
+
*
|
|
157
|
+
* Use when a React component needs to update a writable atom without rendering
|
|
158
|
+
* from that atom's value.
|
|
159
|
+
*
|
|
160
|
+
* **Details**
|
|
161
|
+
*
|
|
162
|
+
* The hook mounts the atom and returns a setter. In value mode the setter
|
|
163
|
+
* accepts a write value or updater function; for `AsyncResult` atoms, `promise`
|
|
164
|
+
* and `promiseExit` modes return a promise for the success value or full `Exit`.
|
|
165
|
+
*
|
|
166
|
+
* @see {@link useAtom} for reading and updating the same writable atom
|
|
167
|
+
*
|
|
104
168
|
* @category hooks
|
|
169
|
+
* @since 4.0.0
|
|
105
170
|
*/
|
|
106
171
|
export const useAtomSet = (atom, options) => {
|
|
107
172
|
const registry = React.useContext(RegistryContext);
|
|
@@ -109,8 +174,23 @@ export const useAtomSet = (atom, options) => {
|
|
|
109
174
|
return setAtom(registry, atom, options);
|
|
110
175
|
};
|
|
111
176
|
/**
|
|
112
|
-
*
|
|
177
|
+
* Mounts an atom and returns a callback that refreshes it in the current React
|
|
178
|
+
* registry.
|
|
179
|
+
*
|
|
180
|
+
* **When to use**
|
|
181
|
+
*
|
|
182
|
+
* Use to expose a React callback that requests a refresh for an atom without
|
|
183
|
+
* reading or writing its value.
|
|
184
|
+
*
|
|
185
|
+
* **Details**
|
|
186
|
+
*
|
|
187
|
+
* The hook uses the current `RegistryContext`, mounts the atom for the
|
|
188
|
+
* component lifetime, and returns a callback that calls `registry.refresh`.
|
|
189
|
+
*
|
|
190
|
+
* @see {@link useAtomMount} for mounting an atom without returning a refresh callback
|
|
191
|
+
*
|
|
113
192
|
* @category hooks
|
|
193
|
+
* @since 4.0.0
|
|
114
194
|
*/
|
|
115
195
|
export const useAtomRefresh = atom => {
|
|
116
196
|
const registry = React.useContext(RegistryContext);
|
|
@@ -120,8 +200,19 @@ export const useAtomRefresh = atom => {
|
|
|
120
200
|
}, [registry, atom]);
|
|
121
201
|
};
|
|
122
202
|
/**
|
|
123
|
-
*
|
|
203
|
+
* Subscribes to a writable atom and returns its current value together with a
|
|
204
|
+
* setter for updating it.
|
|
205
|
+
*
|
|
206
|
+
* **When to use**
|
|
207
|
+
*
|
|
208
|
+
* Use when a React component needs both to render the current value of a
|
|
209
|
+
* writable atom and update it from the same component.
|
|
210
|
+
*
|
|
211
|
+
* @see {@link useAtomValue} for subscribing to an atom without a setter
|
|
212
|
+
* @see {@link useAtomSet} for updating a writable atom without subscribing to its value
|
|
213
|
+
*
|
|
124
214
|
* @category hooks
|
|
215
|
+
* @since 4.0.0
|
|
125
216
|
*/
|
|
126
217
|
export const useAtom = (atom, options) => {
|
|
127
218
|
const registry = React.useContext(RegistryContext);
|
|
@@ -158,8 +249,28 @@ function atomResultOrSuspend(registry, atom, suspendOnWaiting) {
|
|
|
158
249
|
return value;
|
|
159
250
|
}
|
|
160
251
|
/**
|
|
161
|
-
*
|
|
252
|
+
* Reads an `AsyncResult` atom through React Suspense, suspending while the
|
|
253
|
+
* result is initial or configured as waiting.
|
|
254
|
+
*
|
|
255
|
+
* **When to use**
|
|
256
|
+
*
|
|
257
|
+
* Use when a React component should render only after an `AsyncResult` atom has
|
|
258
|
+
* left its initial state, with loading delegated to a Suspense boundary.
|
|
259
|
+
*
|
|
260
|
+
* **Details**
|
|
261
|
+
*
|
|
262
|
+
* `suspendOnWaiting` defaults to `false`. When `includeFailure` is `true`, a
|
|
263
|
+
* failure result is returned instead of being thrown.
|
|
264
|
+
*
|
|
265
|
+
* **Gotchas**
|
|
266
|
+
*
|
|
267
|
+
* Without `includeFailure`, failure results are thrown with
|
|
268
|
+
* `Cause.squash(result.cause)`, so callers need an error boundary for failures.
|
|
269
|
+
*
|
|
270
|
+
* @see {@link useAtomValue} for reading the raw `AsyncResult` value without Suspense
|
|
271
|
+
*
|
|
162
272
|
* @category hooks
|
|
273
|
+
* @since 4.0.0
|
|
163
274
|
*/
|
|
164
275
|
export const useAtomSuspense = (atom, options) => {
|
|
165
276
|
const registry = React.useContext(RegistryContext);
|
|
@@ -170,16 +281,47 @@ export const useAtomSuspense = (atom, options) => {
|
|
|
170
281
|
return result;
|
|
171
282
|
};
|
|
172
283
|
/**
|
|
173
|
-
*
|
|
284
|
+
* Subscribes a callback to an atom in the current React registry for the
|
|
285
|
+
* component lifetime.
|
|
286
|
+
*
|
|
287
|
+
* **When to use**
|
|
288
|
+
*
|
|
289
|
+
* Use when a React component needs to run a callback for atom changes without
|
|
290
|
+
* reading the atom value during render.
|
|
291
|
+
*
|
|
292
|
+
* **Details**
|
|
293
|
+
*
|
|
294
|
+
* The subscription is installed in a React effect and cleaned up on unmount or
|
|
295
|
+
* dependency change. When `options.immediate` is enabled, the callback receives
|
|
296
|
+
* the current value when the effect subscribes.
|
|
297
|
+
*
|
|
298
|
+
* @see {@link useAtomValue} for reading an atom value during render instead of running a callback
|
|
299
|
+
*
|
|
174
300
|
* @category hooks
|
|
301
|
+
* @since 4.0.0
|
|
175
302
|
*/
|
|
176
303
|
export const useAtomSubscribe = (atom, f, options) => {
|
|
177
304
|
const registry = React.useContext(RegistryContext);
|
|
178
305
|
React.useEffect(() => registry.subscribe(atom, f, options), [registry, atom, f, options?.immediate]);
|
|
179
306
|
};
|
|
180
307
|
/**
|
|
181
|
-
*
|
|
308
|
+
* Subscribes to an atom ref and returns its latest value.
|
|
309
|
+
*
|
|
310
|
+
* **When to use**
|
|
311
|
+
*
|
|
312
|
+
* Use when a React component should render from an `AtomRef.ReadonlyRef`
|
|
313
|
+
* directly instead of reading an atom through the current registry.
|
|
314
|
+
*
|
|
315
|
+
* **Details**
|
|
316
|
+
*
|
|
317
|
+
* The hook subscribes with `ref.subscribe`, triggers re-renders through React
|
|
318
|
+
* state, and returns the current `ref.value`.
|
|
319
|
+
*
|
|
320
|
+
* @see {@link useAtomValue} for reading an `Atom` from the current registry
|
|
321
|
+
* @see {@link useAtomRefPropValue} for reading a property ref value
|
|
322
|
+
*
|
|
182
323
|
* @category hooks
|
|
324
|
+
* @since 4.0.0
|
|
183
325
|
*/
|
|
184
326
|
export const useAtomRef = ref => {
|
|
185
327
|
const [, setValue] = React.useState(ref.value);
|
|
@@ -187,13 +329,45 @@ export const useAtomRef = ref => {
|
|
|
187
329
|
return ref.value;
|
|
188
330
|
};
|
|
189
331
|
/**
|
|
190
|
-
*
|
|
332
|
+
* Returns a memoized atom ref for a property of another atom ref.
|
|
333
|
+
*
|
|
334
|
+
* **When to use**
|
|
335
|
+
*
|
|
336
|
+
* Use to derive an `AtomRef` for one property of an object-shaped atom ref.
|
|
337
|
+
*
|
|
338
|
+
* **Details**
|
|
339
|
+
*
|
|
340
|
+
* The hook memoizes `ref.prop(prop)` for the `[ref, prop]` dependency pair and
|
|
341
|
+
* returns the property ref so callers can read, set, update, or subscribe to
|
|
342
|
+
* that nested property.
|
|
343
|
+
*
|
|
344
|
+
* @see {@link useAtomRef} for subscribing to an atom ref value
|
|
345
|
+
* @see {@link useAtomRefPropValue} for subscribing directly to a property value
|
|
346
|
+
*
|
|
191
347
|
* @category hooks
|
|
348
|
+
* @since 4.0.0
|
|
192
349
|
*/
|
|
193
350
|
export const useAtomRefProp = (ref, prop) => React.useMemo(() => ref.prop(prop), [ref, prop]);
|
|
194
351
|
/**
|
|
195
|
-
*
|
|
352
|
+
* Subscribes to a property ref derived from an atom ref and returns its current
|
|
353
|
+
* value.
|
|
354
|
+
*
|
|
355
|
+
* **When to use**
|
|
356
|
+
*
|
|
357
|
+
* Use when a React component needs only the current value of one property from
|
|
358
|
+
* an object-shaped `AtomRef`.
|
|
359
|
+
*
|
|
360
|
+
* **Details**
|
|
361
|
+
*
|
|
362
|
+
* The hook composes `useAtomRefProp(ref, prop)` with `useAtomRef`, so the
|
|
363
|
+
* property ref is memoized for the `[ref, prop]` pair and then subscribed
|
|
364
|
+
* through `ref.subscribe`.
|
|
365
|
+
*
|
|
366
|
+
* @see {@link useAtomRefProp} for returning the property ref directly
|
|
367
|
+
* @see {@link useAtomRef} for subscribing to a whole atom ref value
|
|
368
|
+
*
|
|
196
369
|
* @category hooks
|
|
370
|
+
* @since 4.0.0
|
|
197
371
|
*/
|
|
198
372
|
export const useAtomRefPropValue = (ref, prop) => useAtomRef(useAtomRefProp(ref, prop));
|
|
199
373
|
//# sourceMappingURL=Hooks.js.map
|
package/dist/Hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Hooks.js","names":["Cause","Effect","Exit","Atom","AtomRegistry","React","RegistryContext","storeRegistry","WeakMap","makeStore","registry","atom","stores","get","undefined","set","store","newStore","subscribe","f","snapshot","getServerSnapshot","getServerValue","useStore","useSyncExternalStore","initialValuesSet","useAtomInitialValues","initialValues","useContext","WeakSet","value","has","add","ensureNode","setValue","useAtomValue","atomB","useMemo","map","mountAtom","useEffect","mount","setAtom","options","mode","useCallback","promise","runPromiseExit","getResult","suspendOnWaiting","then","flattenExit","exit","isSuccess","squash","cause","useAtomMount","useAtomSet","useAtomRefresh","refresh","useAtom","atomPromiseMap","Map","default","atomToPromise","Promise","resolve","dispose","result","_tag","waiting","setTimeout","delete","atomResultOrSuspend","useAtomSuspense","includeFailure","useAtomSubscribe","immediate","useAtomRef","ref","useState","useAtomRefProp","prop","useAtomRefPropValue"],"sources":["../src/Hooks.ts"],"sourcesContent":[null],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Hooks.js","names":["Cause","Effect","Exit","Atom","AtomRegistry","React","RegistryContext","storeRegistry","WeakMap","makeStore","registry","atom","stores","get","undefined","set","store","newStore","subscribe","f","snapshot","getServerSnapshot","getServerValue","useStore","useSyncExternalStore","initialValuesSet","useAtomInitialValues","initialValues","useContext","WeakSet","value","has","add","ensureNode","setValue","useAtomValue","atomB","useMemo","map","mountAtom","useEffect","mount","setAtom","options","mode","useCallback","promise","runPromiseExit","getResult","suspendOnWaiting","then","flattenExit","exit","isSuccess","squash","cause","useAtomMount","useAtomSet","useAtomRefresh","refresh","useAtom","atomPromiseMap","Map","default","atomToPromise","Promise","resolve","dispose","result","_tag","waiting","setTimeout","delete","atomResultOrSuspend","useAtomSuspense","includeFailure","useAtomSubscribe","immediate","useAtomRef","ref","useState","useAtomRefProp","prop","useAtomRefPropValue"],"sources":["../src/Hooks.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;AAQA,YAAY;;AAEZ,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,e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G,IAAI,CAACA,IAAI,CAAC,EAAE,CAACH,GAAG,EAAEG,IAAI,CAAC,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;AAqBA,OAAO,MAAMC,mBAAmB,GAAGA,CAAuBJ,GAAuB,EAAEG,IAAO,KACxFJ,UAAU,CAACG,cAAc,CAACF,GAAG,EAAEG,IAAI,CAAC,CAAC","ignoreList":[]}
|
package/dist/ReactHydration.d.ts
CHANGED
|
@@ -1,16 +1,36 @@
|
|
|
1
1
|
import * as Hydration from "effect/unstable/reactivity/Hydration";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Props for a boundary that applies dehydrated Atom values to the nearest
|
|
5
|
+
* {@link RegistryContext} while rendering its children.
|
|
6
|
+
*
|
|
5
7
|
* @category components
|
|
8
|
+
* @since 4.0.0
|
|
6
9
|
*/
|
|
7
10
|
export interface HydrationBoundaryProps {
|
|
8
11
|
state?: Iterable<Hydration.DehydratedAtom>;
|
|
9
12
|
children?: React.ReactNode;
|
|
10
13
|
}
|
|
11
14
|
/**
|
|
12
|
-
*
|
|
15
|
+
* Provides a React hydration boundary that loads dehydrated Atom values into
|
|
16
|
+
* the current Atom registry.
|
|
17
|
+
*
|
|
18
|
+
* **When to use**
|
|
19
|
+
*
|
|
20
|
+
* Use to apply dehydrated Atom state to a React subtree that reads from the
|
|
21
|
+
* nearest `RegistryContext`.
|
|
22
|
+
*
|
|
23
|
+
* **Details**
|
|
24
|
+
*
|
|
25
|
+
* New Atom values are hydrated during render so descendants can read them
|
|
26
|
+
* immediately, while values for existing Atoms are deferred until after commit
|
|
27
|
+
* so transition data does not update the current UI before React accepts it.
|
|
28
|
+
*
|
|
29
|
+
* @see {@link Hydration.dehydrate} for producing dehydrated Atom state
|
|
30
|
+
* @see {@link Hydration.hydrate} for lower-level non-React hydration
|
|
31
|
+
*
|
|
13
32
|
* @category components
|
|
33
|
+
* @since 4.0.0
|
|
14
34
|
*/
|
|
15
35
|
export declare const HydrationBoundary: React.FC<HydrationBoundaryProps>;
|
|
16
36
|
//# sourceMappingURL=ReactHydration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactHydration.d.ts","sourceRoot":"","sources":["../src/ReactHydration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ReactHydration.d.ts","sourceRoot":"","sources":["../src/ReactHydration.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,SAAS,MAAM,sCAAsC,CAAA;AACjE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;IAC1C,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CA6D9D,CAAA"}
|