@effect/atom-react 4.0.0-beta.7 → 4.0.0-beta.70
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 +53 -13
- package/dist/Hooks.d.ts.map +1 -1
- package/dist/Hooks.js +64 -12
- package/dist/Hooks.js.map +1 -1
- package/dist/ReactHydration.d.ts +14 -2
- package/dist/ReactHydration.d.ts.map +1 -1
- package/dist/ReactHydration.js +32 -2
- package/dist/ReactHydration.js.map +1 -1
- package/dist/RegistryContext.d.ts +13 -3
- package/dist/RegistryContext.d.ts.map +1 -1
- package/dist/RegistryContext.js +36 -4
- package/dist/RegistryContext.js.map +1 -1
- package/dist/ScopedAtom.d.ts +25 -25
- package/dist/ScopedAtom.d.ts.map +1 -1
- package/dist/ScopedAtom.js +30 -13
- 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 +72 -14
- package/src/ReactHydration.ts +36 -3
- package/src/RegistryContext.ts +36 -4
- package/src/ScopedAtom.ts +43 -26
- package/src/index.ts +5 -5
package/dist/Hooks.d.ts
CHANGED
|
@@ -3,78 +3,118 @@ 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
|
+
* **Details**
|
|
9
|
+
*
|
|
10
|
+
* Each atom is initialized at most once for a given registry, so subsequent
|
|
11
|
+
* renders do not overwrite values that have already been established.
|
|
12
|
+
*
|
|
7
13
|
* @category hooks
|
|
14
|
+
* @since 4.0.0
|
|
8
15
|
*/
|
|
9
16
|
export declare const useAtomInitialValues: (initialValues: Iterable<readonly [Atom.Atom<any>, any]>) => void;
|
|
10
17
|
/**
|
|
11
|
-
*
|
|
18
|
+
* Subscribes to an atom in the current React registry and returns its current
|
|
19
|
+
* value, optionally mapped through a selector.
|
|
20
|
+
*
|
|
12
21
|
* @category hooks
|
|
22
|
+
* @since 4.0.0
|
|
13
23
|
*/
|
|
14
24
|
export declare const useAtomValue: {
|
|
15
25
|
/**
|
|
16
|
-
*
|
|
26
|
+
* Subscribes to an atom in the current React registry and returns its current
|
|
27
|
+
* value, optionally mapped through a selector.
|
|
28
|
+
*
|
|
17
29
|
* @category hooks
|
|
30
|
+
* @since 4.0.0
|
|
18
31
|
*/
|
|
19
32
|
<A>(atom: Atom.Atom<A>): A;
|
|
20
33
|
/**
|
|
21
|
-
*
|
|
34
|
+
* Subscribes to an atom in the current React registry and returns its current
|
|
35
|
+
* value, optionally mapped through a selector.
|
|
36
|
+
*
|
|
22
37
|
* @category hooks
|
|
38
|
+
* @since 4.0.0
|
|
23
39
|
*/
|
|
24
40
|
<A, B>(atom: Atom.Atom<A>, f: (_: A) => B): B;
|
|
25
41
|
};
|
|
26
42
|
/**
|
|
27
|
-
*
|
|
43
|
+
* Mounts an atom in the current React registry for the lifetime of the
|
|
44
|
+
* component.
|
|
45
|
+
*
|
|
28
46
|
* @category hooks
|
|
47
|
+
* @since 4.0.0
|
|
29
48
|
*/
|
|
30
49
|
export declare const useAtomMount: <A>(atom: Atom.Atom<A>) => void;
|
|
31
50
|
/**
|
|
32
|
-
*
|
|
51
|
+
* Mounts a writable atom and returns a setter without subscribing to its value.
|
|
52
|
+
*
|
|
33
53
|
* @category hooks
|
|
54
|
+
* @since 4.0.0
|
|
34
55
|
*/
|
|
35
56
|
export declare const useAtomSet: <R, W, Mode extends "value" | "promise" | "promiseExit" = never>(atom: Atom.Writable<R, W>, options?: {
|
|
36
57
|
readonly mode?: ([R] extends [AsyncResult.AsyncResult<any, any>] ? Mode : "value") | undefined;
|
|
37
58
|
}) => "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
59
|
/**
|
|
39
|
-
*
|
|
60
|
+
* Mounts an atom and returns a callback that refreshes it in the current React
|
|
61
|
+
* registry.
|
|
62
|
+
*
|
|
40
63
|
* @category hooks
|
|
64
|
+
* @since 4.0.0
|
|
41
65
|
*/
|
|
42
66
|
export declare const useAtomRefresh: <A>(atom: Atom.Atom<A>) => () => void;
|
|
43
67
|
/**
|
|
44
|
-
*
|
|
68
|
+
* Subscribes to a writable atom and returns its current value together with a
|
|
69
|
+
* setter for updating it.
|
|
70
|
+
*
|
|
45
71
|
* @category hooks
|
|
72
|
+
* @since 4.0.0
|
|
46
73
|
*/
|
|
47
74
|
export declare const useAtom: <R, W, const Mode extends "value" | "promise" | "promiseExit" = never>(atom: Atom.Writable<R, W>, options?: {
|
|
48
75
|
readonly mode?: ([R] extends [AsyncResult.AsyncResult<any, any>] ? Mode : "value") | undefined;
|
|
49
76
|
}) => 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
77
|
/**
|
|
51
|
-
*
|
|
78
|
+
* Reads an `AsyncResult` atom through React Suspense, suspending while the
|
|
79
|
+
* result is initial or configured as waiting.
|
|
80
|
+
*
|
|
52
81
|
* @category hooks
|
|
82
|
+
* @since 4.0.0
|
|
53
83
|
*/
|
|
54
84
|
export declare const useAtomSuspense: <A, E, const IncludeFailure extends boolean = false>(atom: Atom.Atom<AsyncResult.AsyncResult<A, E>>, options?: {
|
|
55
85
|
readonly suspendOnWaiting?: boolean | undefined;
|
|
56
86
|
readonly includeFailure?: IncludeFailure | undefined;
|
|
57
87
|
}) => AsyncResult.Success<A, E> | (IncludeFailure extends true ? AsyncResult.Failure<A, E> : never);
|
|
58
88
|
/**
|
|
59
|
-
*
|
|
89
|
+
* Subscribes a callback to an atom in the current React registry for the
|
|
90
|
+
* component lifetime.
|
|
91
|
+
*
|
|
60
92
|
* @category hooks
|
|
93
|
+
* @since 4.0.0
|
|
61
94
|
*/
|
|
62
95
|
export declare const useAtomSubscribe: <A>(atom: Atom.Atom<A>, f: (_: A) => void, options?: {
|
|
63
96
|
readonly immediate?: boolean;
|
|
64
97
|
}) => void;
|
|
65
98
|
/**
|
|
66
|
-
*
|
|
99
|
+
* Subscribes to an atom ref and returns its latest value.
|
|
100
|
+
*
|
|
67
101
|
* @category hooks
|
|
102
|
+
* @since 4.0.0
|
|
68
103
|
*/
|
|
69
104
|
export declare const useAtomRef: <A>(ref: AtomRef.ReadonlyRef<A>) => A;
|
|
70
105
|
/**
|
|
71
|
-
*
|
|
106
|
+
* Returns a memoized atom ref for a property of another atom ref.
|
|
107
|
+
*
|
|
72
108
|
* @category hooks
|
|
109
|
+
* @since 4.0.0
|
|
73
110
|
*/
|
|
74
111
|
export declare const useAtomRefProp: <A, K extends keyof A>(ref: AtomRef.AtomRef<A>, prop: K) => AtomRef.AtomRef<A[K]>;
|
|
75
112
|
/**
|
|
76
|
-
*
|
|
113
|
+
* Subscribes to a property ref derived from an atom ref and returns its current
|
|
114
|
+
* value.
|
|
115
|
+
*
|
|
77
116
|
* @category hooks
|
|
117
|
+
* @since 4.0.0
|
|
78
118
|
*/
|
|
79
119
|
export declare const useAtomRefPropValue: <A, K extends keyof A>(ref: AtomRef.AtomRef<A>, prop: K) => A[K];
|
|
80
120
|
//# 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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EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAC1D,CAAA;AAElD;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAG,CAAC,CAAC,CAAC,CACzD,CAAA"}
|
package/dist/Hooks.js
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* React hooks for reading, writing, mounting, refreshing, and subscribing to
|
|
3
|
+
* Effect atoms from the registry provided by `RegistryContext`.
|
|
4
|
+
*
|
|
5
|
+
* **Common tasks**
|
|
6
|
+
*
|
|
7
|
+
* - Read atom values in React components with {@link useAtomValue}
|
|
8
|
+
* - Read and write writable atoms with {@link useAtom}
|
|
9
|
+
* - Write without subscribing to the value with {@link useAtomSet}
|
|
10
|
+
* - Seed registry-local initial values with {@link useAtomInitialValues}
|
|
11
|
+
* - Integrate `AsyncResult` atoms with React Suspense through {@link useAtomSuspense}
|
|
12
|
+
* - Subscribe to atom changes or derive stable `AtomRef` properties
|
|
13
|
+
*
|
|
14
|
+
* **Gotchas**
|
|
15
|
+
*
|
|
16
|
+
* - Hooks use the current `RegistryContext`, so each provider has an independent atom registry
|
|
17
|
+
* - Writable atoms are mounted by the write-oriented hooks before updates are sent
|
|
18
|
+
* - Suspense support throws promises for initial or waiting `AsyncResult` values and defects for failures unless `includeFailure` is enabled
|
|
19
|
+
*
|
|
20
|
+
* @since 4.0.0
|
|
3
21
|
*/
|
|
4
22
|
"use client";
|
|
5
23
|
|
|
@@ -41,8 +59,15 @@ function useStore(registry, atom) {
|
|
|
41
59
|
}
|
|
42
60
|
const initialValuesSet = /*#__PURE__*/new WeakMap();
|
|
43
61
|
/**
|
|
44
|
-
*
|
|
62
|
+
* Seeds initial atom values in the current React atom registry.
|
|
63
|
+
*
|
|
64
|
+
* **Details**
|
|
65
|
+
*
|
|
66
|
+
* Each atom is initialized at most once for a given registry, so subsequent
|
|
67
|
+
* renders do not overwrite values that have already been established.
|
|
68
|
+
*
|
|
45
69
|
* @category hooks
|
|
70
|
+
* @since 4.0.0
|
|
46
71
|
*/
|
|
47
72
|
export const useAtomInitialValues = initialValues => {
|
|
48
73
|
const registry = React.useContext(RegistryContext);
|
|
@@ -59,8 +84,11 @@ export const useAtomInitialValues = initialValues => {
|
|
|
59
84
|
}
|
|
60
85
|
};
|
|
61
86
|
/**
|
|
62
|
-
*
|
|
87
|
+
* Subscribes to an atom in the current React registry and returns its current
|
|
88
|
+
* value, optionally mapped through a selector.
|
|
89
|
+
*
|
|
63
90
|
* @category hooks
|
|
91
|
+
* @since 4.0.0
|
|
64
92
|
*/
|
|
65
93
|
export const useAtomValue = (atom, f) => {
|
|
66
94
|
const registry = React.useContext(RegistryContext);
|
|
@@ -92,16 +120,21 @@ const flattenExit = exit => {
|
|
|
92
120
|
throw Cause.squash(exit.cause);
|
|
93
121
|
};
|
|
94
122
|
/**
|
|
95
|
-
*
|
|
123
|
+
* Mounts an atom in the current React registry for the lifetime of the
|
|
124
|
+
* component.
|
|
125
|
+
*
|
|
96
126
|
* @category hooks
|
|
127
|
+
* @since 4.0.0
|
|
97
128
|
*/
|
|
98
129
|
export const useAtomMount = atom => {
|
|
99
130
|
const registry = React.useContext(RegistryContext);
|
|
100
131
|
mountAtom(registry, atom);
|
|
101
132
|
};
|
|
102
133
|
/**
|
|
103
|
-
*
|
|
134
|
+
* Mounts a writable atom and returns a setter without subscribing to its value.
|
|
135
|
+
*
|
|
104
136
|
* @category hooks
|
|
137
|
+
* @since 4.0.0
|
|
105
138
|
*/
|
|
106
139
|
export const useAtomSet = (atom, options) => {
|
|
107
140
|
const registry = React.useContext(RegistryContext);
|
|
@@ -109,8 +142,11 @@ export const useAtomSet = (atom, options) => {
|
|
|
109
142
|
return setAtom(registry, atom, options);
|
|
110
143
|
};
|
|
111
144
|
/**
|
|
112
|
-
*
|
|
145
|
+
* Mounts an atom and returns a callback that refreshes it in the current React
|
|
146
|
+
* registry.
|
|
147
|
+
*
|
|
113
148
|
* @category hooks
|
|
149
|
+
* @since 4.0.0
|
|
114
150
|
*/
|
|
115
151
|
export const useAtomRefresh = atom => {
|
|
116
152
|
const registry = React.useContext(RegistryContext);
|
|
@@ -120,8 +156,11 @@ export const useAtomRefresh = atom => {
|
|
|
120
156
|
}, [registry, atom]);
|
|
121
157
|
};
|
|
122
158
|
/**
|
|
123
|
-
*
|
|
159
|
+
* Subscribes to a writable atom and returns its current value together with a
|
|
160
|
+
* setter for updating it.
|
|
161
|
+
*
|
|
124
162
|
* @category hooks
|
|
163
|
+
* @since 4.0.0
|
|
125
164
|
*/
|
|
126
165
|
export const useAtom = (atom, options) => {
|
|
127
166
|
const registry = React.useContext(RegistryContext);
|
|
@@ -158,8 +197,11 @@ function atomResultOrSuspend(registry, atom, suspendOnWaiting) {
|
|
|
158
197
|
return value;
|
|
159
198
|
}
|
|
160
199
|
/**
|
|
161
|
-
*
|
|
200
|
+
* Reads an `AsyncResult` atom through React Suspense, suspending while the
|
|
201
|
+
* result is initial or configured as waiting.
|
|
202
|
+
*
|
|
162
203
|
* @category hooks
|
|
204
|
+
* @since 4.0.0
|
|
163
205
|
*/
|
|
164
206
|
export const useAtomSuspense = (atom, options) => {
|
|
165
207
|
const registry = React.useContext(RegistryContext);
|
|
@@ -170,16 +212,21 @@ export const useAtomSuspense = (atom, options) => {
|
|
|
170
212
|
return result;
|
|
171
213
|
};
|
|
172
214
|
/**
|
|
173
|
-
*
|
|
215
|
+
* Subscribes a callback to an atom in the current React registry for the
|
|
216
|
+
* component lifetime.
|
|
217
|
+
*
|
|
174
218
|
* @category hooks
|
|
219
|
+
* @since 4.0.0
|
|
175
220
|
*/
|
|
176
221
|
export const useAtomSubscribe = (atom, f, options) => {
|
|
177
222
|
const registry = React.useContext(RegistryContext);
|
|
178
223
|
React.useEffect(() => registry.subscribe(atom, f, options), [registry, atom, f, options?.immediate]);
|
|
179
224
|
};
|
|
180
225
|
/**
|
|
181
|
-
*
|
|
226
|
+
* Subscribes to an atom ref and returns its latest value.
|
|
227
|
+
*
|
|
182
228
|
* @category hooks
|
|
229
|
+
* @since 4.0.0
|
|
183
230
|
*/
|
|
184
231
|
export const useAtomRef = ref => {
|
|
185
232
|
const [, setValue] = React.useState(ref.value);
|
|
@@ -187,13 +234,18 @@ export const useAtomRef = ref => {
|
|
|
187
234
|
return ref.value;
|
|
188
235
|
};
|
|
189
236
|
/**
|
|
190
|
-
*
|
|
237
|
+
* Returns a memoized atom ref for a property of another atom ref.
|
|
238
|
+
*
|
|
191
239
|
* @category hooks
|
|
240
|
+
* @since 4.0.0
|
|
192
241
|
*/
|
|
193
242
|
export const useAtomRefProp = (ref, prop) => React.useMemo(() => ref.prop(prop), [ref, prop]);
|
|
194
243
|
/**
|
|
195
|
-
*
|
|
244
|
+
* Subscribes to a property ref derived from an atom ref and returns its current
|
|
245
|
+
* value.
|
|
246
|
+
*
|
|
196
247
|
* @category hooks
|
|
248
|
+
* @since 4.0.0
|
|
197
249
|
*/
|
|
198
250
|
export const useAtomRefPropValue = (ref, prop) => useAtomRef(useAtomRefProp(ref, prop));
|
|
199
251
|
//# 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;;;;;;;;;;;;;;;;;;;;;AAqBA,YAAY;;AAEZ,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,IAAI,MAAM,aAAa;AAEnC,OAAO,KAAKC,IAAI,MAAM,iCAAiC;AAEvD,OAAO,KAAKC,YAAY,MAAM,yCAAyC;AACvE,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,eAAe,QAAQ,sBAAsB;AAQtD,MAAMC,aAAa,gBAAG,IAAIC,OAAO,EAAsE;AAEvG,SAASC,SAASA,CAA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;;;;AAOA,OAAO,MAAMQ,gBAAgB,GAAGA,CAC9BjE,IAAkB,EAClBQ,CAAiB,EACjBwB,OAA0C,KAClC;EACR,MAAMjC,QAAQ,GAAGL,KAAK,CAACuB,UAAU,CAACtB,eAAe,CAAC;EAClDD,KAAK,CAACmC,SAAS,CACb,MAAM9B,QAAQ,CAACQ,SAAS,CAACP,IAAI,EAAEQ,CAAC,EAAEwB,OAAO,CAAC,EAC1C,CAACjC,QAAQ,EAAEC,IAAI,EAAEQ,CAAC,EAAEwB,OAAO,EAAEkC,SAAS,CAAC,CACxC;AACH,CAAC;AAED;;;;;;AAMA,OAAO,MAAMC,UAAU,GAAOC,GAA2B,IAAO;EAC9D,MAAM,GAAG7C,QAAQ,CAAC,GAAG7B,KAAK,CAAC2E,QAAQ,CAACD,GAAG,CAACjD,KAAK,CAAC;EAC9CzB,KAAK,CAACmC,SAAS,CAAC,MAAMuC,GAAG,CAAC7D,SAAS,CAACgB,QAAQ,CAAC,EAAE,CAAC6C,GAAG,CAAC,CAAC;EACrD,OAAOA,GAAG,CAACjD,KAAK;AAClB,CAAC;AAED;;;;;;AAMA,OAAO,MAAMmD,cAAc,GAAGA,CAAuBF,GAAuB,EAAEG,IAAO,KACnF7E,KAAK,CAACgC,OAAO,CAAC,MAAM0C,GAAG,CAACG,IAAI,CAACA,IAAI,CAAC,EAAE,CAACH,GAAG,EAAEG,IAAI,CAAC,CAAC;AAElD;;;;;;;AAOA,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,28 @@
|
|
|
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
|
+
* Hydrates dehydrated Atom values into the current Atom registry for a React
|
|
16
|
+
* subtree.
|
|
17
|
+
*
|
|
18
|
+
* **Details**
|
|
19
|
+
*
|
|
20
|
+
* New Atom values are hydrated during render so descendants can read them
|
|
21
|
+
* immediately, while values for existing Atoms are deferred until after commit
|
|
22
|
+
* so transition data does not update the current UI before React accepts it.
|
|
23
|
+
*
|
|
13
24
|
* @category components
|
|
25
|
+
* @since 4.0.0
|
|
14
26
|
*/
|
|
15
27
|
export declare const HydrationBoundary: React.FC<HydrationBoundaryProps>;
|
|
16
28
|
//# 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":"AAyBA,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;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CA6D9D,CAAA"}
|
package/dist/ReactHydration.js
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* React helpers for hydrating Atom registry state that was serialized on the
|
|
3
|
+
* server or produced by a previous render. This module exposes
|
|
4
|
+
* {@link HydrationBoundary}, a client component that receives dehydrated Atom
|
|
5
|
+
* values and applies them to the nearest {@link RegistryContext} before
|
|
6
|
+
* rendering children when it is safe to do so.
|
|
7
|
+
*
|
|
8
|
+
* **Common use cases**
|
|
9
|
+
*
|
|
10
|
+
* - Reusing Atom values that were collected during server rendering
|
|
11
|
+
* - Restoring client-side Atom state around a routed subtree
|
|
12
|
+
* - Keeping Atom-backed React trees consistent during hydration and transitions
|
|
13
|
+
*
|
|
14
|
+
* **React gotchas**
|
|
15
|
+
*
|
|
16
|
+
* - New Atom values can be hydrated during render so children see them
|
|
17
|
+
* immediately.
|
|
18
|
+
* - Existing Atom values are queued until after commit to avoid updating the
|
|
19
|
+
* current UI with transition data that might later be discarded.
|
|
20
|
+
* - Hydration is idempotent, so repeated or older dehydrated values are safe to
|
|
21
|
+
* pass through the boundary.
|
|
22
|
+
*
|
|
23
|
+
* @since 4.0.0
|
|
3
24
|
*/
|
|
4
25
|
"use client";
|
|
5
26
|
|
|
@@ -7,8 +28,17 @@ import * as Hydration from "effect/unstable/reactivity/Hydration";
|
|
|
7
28
|
import * as React from "react";
|
|
8
29
|
import { RegistryContext } from "./RegistryContext.js";
|
|
9
30
|
/**
|
|
10
|
-
*
|
|
31
|
+
* Hydrates dehydrated Atom values into the current Atom registry for a React
|
|
32
|
+
* subtree.
|
|
33
|
+
*
|
|
34
|
+
* **Details**
|
|
35
|
+
*
|
|
36
|
+
* New Atom values are hydrated during render so descendants can read them
|
|
37
|
+
* immediately, while values for existing Atoms are deferred until after commit
|
|
38
|
+
* so transition data does not update the current UI before React accepts it.
|
|
39
|
+
*
|
|
11
40
|
* @category components
|
|
41
|
+
* @since 4.0.0
|
|
12
42
|
*/
|
|
13
43
|
export const HydrationBoundary = ({
|
|
14
44
|
children,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactHydration.js","names":["Hydration","React","RegistryContext","HydrationBoundary","children","state","registry","useContext","hydrationQueue","useMemo","dehydratedAtoms","Array","from","nodes","getNodes","newDehydratedAtoms","existingDehydratedAtoms","dehydratedAtom","existingNode","get","key","push","length","hydrate","undefined","useEffect","createElement","Fragment"],"sources":["../src/ReactHydration.ts"],"sourcesContent":[null],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ReactHydration.js","names":["Hydration","React","RegistryContext","HydrationBoundary","children","state","registry","useContext","hydrationQueue","useMemo","dehydratedAtoms","Array","from","nodes","getNodes","newDehydratedAtoms","existingDehydratedAtoms","dehydratedAtom","existingNode","get","key","push","length","hydrate","undefined","useEffect","createElement","Fragment"],"sources":["../src/ReactHydration.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,YAAY;;AACZ,OAAO,KAAKA,SAAS,MAAM,sCAAsC;AACjE,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,eAAe,QAAQ,sBAAsB;AActD;;;;;;;;;;;;;AAaA,OAAO,MAAMC,iBAAiB,GAAqCA,CAAC;EAClEC,QAAQ;EACRC;AAAK,CACN,KAAI;EACH,MAAMC,QAAQ,GAAGL,KAAK,CAACM,UAAU,CAACL,eAAe,CAAC;EAElD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAMM,cAAc,GAAqDP,KAAK,CAACQ,OAAO,CAAC,MAAK;IAC1F,IAAIJ,KAAK,EAAE;MACT,MAAMK,eAAe,GAAGC,KAAK,CAACC,IAAI,CAACP,KAAK,CAAyC;MACjF,MAAMQ,KAAK,GAAGP,QAAQ,CAACQ,QAAQ,EAAE;MAEjC,MAAMC,kBAAkB,GAAyC,EAAE;MACnE,MAAMC,uBAAuB,GAAyC,EAAE;MAExE,KAAK,MAAMC,cAAc,IAAIP,eAAe,EAAE;QAC5C,MAAMQ,YAAY,GAAGL,KAAK,CAACM,GAAG,CAACF,cAAc,CAACG,GAAG,CAAC;QAElD,IAAI,CAACF,YAAY,EAAE;UACjB;UACAH,kBAAkB,CAACM,IAAI,CAACJ,cAAc,CAAC;QACzC,CAAC,MAAM;UACL;UACAD,uBAAuB,CAACK,IAAI,CAACJ,cAAc,CAAC;QAC9C;MACF;MAEA,IAAIF,kBAAkB,CAACO,MAAM,GAAG,CAAC,EAAE;QACjC;QACA;QACAtB,SAAS,CAACuB,OAAO,CAACjB,QAAQ,EAAES,kBAAkB,CAAC;MACjD;MAEA,IAAIC,uBAAuB,CAACM,MAAM,GAAG,CAAC,EAAE;QACtC,OAAON,uBAAuB;MAChC;IACF;IACA,OAAOQ,SAAS;EAClB,CAAC,EAAE,CAAClB,QAAQ,EAAED,KAAK,CAAC,CAAC;EAErBJ,KAAK,CAACwB,SAAS,CAAC,MAAK;IACnB,IAAIjB,cAAc,EAAE;MAClBR,SAAS,CAACuB,OAAO,CAACjB,QAAQ,EAAEE,cAAc,CAAC;IAC7C;EACF,CAAC,EAAE,CAACF,QAAQ,EAAEE,cAAc,CAAC,CAAC;EAE9B,OAAOP,KAAK,CAACyB,aAAa,CAACzB,KAAK,CAAC0B,QAAQ,EAAE,EAAE,EAAEvB,QAAQ,CAAC;AAC1D,CAAC","ignoreList":[]}
|
|
@@ -2,18 +2,28 @@ import type * as Atom from "effect/unstable/reactivity/Atom";
|
|
|
2
2
|
import * as AtomRegistry from "effect/unstable/reactivity/AtomRegistry";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Schedules Atom registry work with React's scheduler at low priority and
|
|
6
|
+
* returns a cancellation function for the scheduled task.
|
|
7
|
+
*
|
|
6
8
|
* @category context
|
|
9
|
+
* @since 4.0.0
|
|
7
10
|
*/
|
|
8
11
|
export declare function scheduleTask(f: () => void): () => void;
|
|
9
12
|
/**
|
|
10
|
-
*
|
|
13
|
+
* React context that supplies the `AtomRegistry` used by Atom hooks and
|
|
14
|
+
* hydration helpers, defaulting to a standalone registry when no provider is
|
|
15
|
+
* present.
|
|
16
|
+
*
|
|
11
17
|
* @category context
|
|
18
|
+
* @since 4.0.0
|
|
12
19
|
*/
|
|
13
20
|
export declare const RegistryContext: React.Context<AtomRegistry.AtomRegistry>;
|
|
14
21
|
/**
|
|
15
|
-
*
|
|
22
|
+
* Provides a stable `AtomRegistry` to a React subtree, optionally seeding
|
|
23
|
+
* initial atom values and overriding registry scheduling or idle settings.
|
|
24
|
+
*
|
|
16
25
|
* @category context
|
|
26
|
+
* @since 4.0.0
|
|
17
27
|
*/
|
|
18
28
|
export declare const RegistryProvider: (options: {
|
|
19
29
|
readonly children?: React.ReactNode | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegistryContext.d.ts","sourceRoot":"","sources":["../src/RegistryContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RegistryContext.d.ts","sourceRoot":"","sources":["../src/RegistryContext.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,KAAK,IAAI,MAAM,iCAAiC,CAAA;AAC5D,OAAO,KAAK,YAAY,MAAM,yCAAyC,CAAA;AACvE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAGtD;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,0CAGzB,CAAA;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAI,SAAS;IACxC,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,SAAS,CAAA;IAC/C,QAAQ,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,SAAS,CAAA;IAC7E,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC,GAAG,SAAS,CAAA;IACnE,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/C,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC7C,mFA2BA,CAAA"}
|
package/dist/RegistryContext.js
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `RegistryContext` module provides the React context used by Effect Atom
|
|
3
|
+
* hooks to share an `AtomRegistry` across a component tree. The registry owns
|
|
4
|
+
* atom state, scheduling, and idle cleanup, so components that read or write
|
|
5
|
+
* atoms can coordinate through the same runtime instead of each creating an
|
|
6
|
+
* isolated registry.
|
|
7
|
+
*
|
|
8
|
+
* **Common tasks**
|
|
9
|
+
*
|
|
10
|
+
* - Use {@link RegistryProvider} to scope atom state to a React subtree
|
|
11
|
+
* - Seed atoms for tests, stories, or server-provided data with `initialValues`
|
|
12
|
+
* - Override scheduling or idle timing for custom rendering environments
|
|
13
|
+
* - Read {@link RegistryContext} when integrating lower-level atom APIs
|
|
14
|
+
*
|
|
15
|
+
* **Gotchas**
|
|
16
|
+
*
|
|
17
|
+
* - This is a client module because it depends on React runtime hooks and the
|
|
18
|
+
* scheduler package
|
|
19
|
+
* - A provider keeps the registry stable across renders and disposes it shortly
|
|
20
|
+
* after unmount, allowing React remounts to reuse the same registry
|
|
21
|
+
* - Overriding `scheduleTask` changes when atom work is flushed, so it should
|
|
22
|
+
* return a cancellation function compatible with React unmounts
|
|
23
|
+
*
|
|
24
|
+
* @since 4.0.0
|
|
3
25
|
*/
|
|
4
26
|
"use client";
|
|
5
27
|
|
|
@@ -7,24 +29,34 @@ import * as AtomRegistry from "effect/unstable/reactivity/AtomRegistry";
|
|
|
7
29
|
import * as React from "react";
|
|
8
30
|
import * as Scheduler from "scheduler";
|
|
9
31
|
/**
|
|
10
|
-
*
|
|
32
|
+
* Schedules Atom registry work with React's scheduler at low priority and
|
|
33
|
+
* returns a cancellation function for the scheduled task.
|
|
34
|
+
*
|
|
11
35
|
* @category context
|
|
36
|
+
* @since 4.0.0
|
|
12
37
|
*/
|
|
13
38
|
export function scheduleTask(f) {
|
|
14
39
|
const node = Scheduler.unstable_scheduleCallback(Scheduler.unstable_LowPriority, f);
|
|
15
40
|
return () => Scheduler.unstable_cancelCallback(node);
|
|
16
41
|
}
|
|
17
42
|
/**
|
|
18
|
-
*
|
|
43
|
+
* React context that supplies the `AtomRegistry` used by Atom hooks and
|
|
44
|
+
* hydration helpers, defaulting to a standalone registry when no provider is
|
|
45
|
+
* present.
|
|
46
|
+
*
|
|
19
47
|
* @category context
|
|
48
|
+
* @since 4.0.0
|
|
20
49
|
*/
|
|
21
50
|
export const RegistryContext = /*#__PURE__*/React.createContext(/*#__PURE__*/AtomRegistry.make({
|
|
22
51
|
scheduleTask,
|
|
23
52
|
defaultIdleTTL: 400
|
|
24
53
|
}));
|
|
25
54
|
/**
|
|
26
|
-
*
|
|
55
|
+
* Provides a stable `AtomRegistry` to a React subtree, optionally seeding
|
|
56
|
+
* initial atom values and overriding registry scheduling or idle settings.
|
|
57
|
+
*
|
|
27
58
|
* @category context
|
|
59
|
+
* @since 4.0.0
|
|
28
60
|
*/
|
|
29
61
|
export const RegistryProvider = options => {
|
|
30
62
|
const ref = React.useRef(null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegistryContext.js","names":["AtomRegistry","React","Scheduler","scheduleTask","f","node","unstable_scheduleCallback","unstable_LowPriority","unstable_cancelCallback","RegistryContext","createContext","make","defaultIdleTTL","RegistryProvider","options","ref","useRef","current","registry","initialValues","timeoutResolution","useEffect","timeout","undefined","clearTimeout","setTimeout","dispose","createElement","Provider","value","children"],"sources":["../src/RegistryContext.ts"],"sourcesContent":[null],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"RegistryContext.js","names":["AtomRegistry","React","Scheduler","scheduleTask","f","node","unstable_scheduleCallback","unstable_LowPriority","unstable_cancelCallback","RegistryContext","createContext","make","defaultIdleTTL","RegistryProvider","options","ref","useRef","current","registry","initialValues","timeoutResolution","useEffect","timeout","undefined","clearTimeout","setTimeout","dispose","createElement","Provider","value","children"],"sources":["../src/RegistryContext.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,YAAY;;AAGZ,OAAO,KAAKA,YAAY,MAAM,yCAAyC;AACvE,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,OAAO,KAAKC,SAAS,MAAM,WAAW;AAEtC;;;;;;;AAOA,OAAM,SAAUC,YAAYA,CAACC,CAAa;EACxC,MAAMC,IAAI,GAAGH,SAAS,CAACI,yBAAyB,CAACJ,SAAS,CAACK,oBAAoB,EAAEH,CAAC,CAAC;EACnF,OAAO,MAAMF,SAAS,CAACM,uBAAuB,CAACH,IAAI,CAAC;AACtD;AAEA;;;;;;;;AAQA,OAAO,MAAMI,eAAe,gBAAGR,KAAK,CAACS,aAAa,cAA4BV,YAAY,CAACW,IAAI,CAAC;EAC9FR,YAAY;EACZS,cAAc,EAAE;CACjB,CAAC,CAAC;AAEH;;;;;;;AAOA,OAAO,MAAMC,gBAAgB,GAAIC,OAMhC,IAAI;EACH,MAAMC,GAAG,GAAGd,KAAK,CAACe,MAAM,CAGrB,IAAI,CAAC;EACR,IAAID,GAAG,CAACE,OAAO,KAAK,IAAI,EAAE;IACxBF,GAAG,CAACE,OAAO,GAAG;MACZC,QAAQ,EAAElB,YAAY,CAACW,IAAI,CAAC;QAC1BR,YAAY,EAAEW,OAAO,CAACX,YAAY,IAAIA,YAAY;QAClDgB,aAAa,EAAEL,OAAO,CAACK,aAAa;QACpCC,iBAAiB,EAAEN,OAAO,CAACM,iBAAiB;QAC5CR,cAAc,EAAEE,OAAO,CAACF;OACzB;KACF;EACH;EACAX,KAAK,CAACoB,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