@effect/atom-react 4.0.0-beta.7 → 4.0.0-beta.71
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 +199 -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 +40 -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 +63 -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 +50 -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 +233 -14
- package/src/ReactHydration.ts +44 -3
- package/src/RegistryContext.ts +63 -4
- package/src/ScopedAtom.ts +67 -24
- package/src/index.ts +5 -5
|
@@ -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;;;;;;;;;;;;;;;;;;;;GAoBG;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,25 @@ 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
|
+
* **When to use**
|
|
35
|
+
*
|
|
36
|
+
* Use to apply dehydrated Atom state to a React subtree that reads from the
|
|
37
|
+
* nearest `RegistryContext`.
|
|
38
|
+
*
|
|
39
|
+
* **Details**
|
|
40
|
+
*
|
|
41
|
+
* New Atom values are hydrated during render so descendants can read them
|
|
42
|
+
* immediately, while values for existing Atoms are deferred until after commit
|
|
43
|
+
* so transition data does not update the current UI before React accepts it.
|
|
44
|
+
*
|
|
45
|
+
* @see {@link Hydration.dehydrate} for producing dehydrated Atom state
|
|
46
|
+
* @see {@link Hydration.hydrate} for lower-level non-React hydration
|
|
47
|
+
*
|
|
11
48
|
* @category components
|
|
49
|
+
* @since 4.0.0
|
|
12
50
|
*/
|
|
13
51
|
export const HydrationBoundary = ({
|
|
14
52
|
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;;;;;;;;;;;;;;;;;;;;;AAqBA,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;EAC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|
|
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
|
+
*
|
|
17
|
+
* **When to use**
|
|
18
|
+
*
|
|
19
|
+
* Use to supply an existing `AtomRegistry` through React context when hooks or
|
|
20
|
+
* hydration helpers need to share registry state that is managed outside
|
|
21
|
+
* `RegistryProvider`.
|
|
22
|
+
*
|
|
23
|
+
* @see {@link RegistryProvider} for creating and providing a registry for a React subtree
|
|
24
|
+
*
|
|
11
25
|
* @category context
|
|
26
|
+
* @since 4.0.0
|
|
12
27
|
*/
|
|
13
28
|
export declare const RegistryContext: React.Context<AtomRegistry.AtomRegistry>;
|
|
14
29
|
/**
|
|
15
|
-
*
|
|
30
|
+
* Provides a stable `AtomRegistry` to a React subtree, optionally seeding
|
|
31
|
+
* initial atom values and overriding registry scheduling or idle settings.
|
|
32
|
+
*
|
|
33
|
+
* **When to use**
|
|
34
|
+
*
|
|
35
|
+
* Use to scope atom state, scheduling, and idle cleanup to a React subtree.
|
|
36
|
+
*
|
|
37
|
+
* **Details**
|
|
38
|
+
*
|
|
39
|
+
* The provider creates one `AtomRegistry` with `AtomRegistry.make`, passes it
|
|
40
|
+
* through `RegistryContext.Provider`, and forwards `initialValues`,
|
|
41
|
+
* `scheduleTask`, `timeoutResolution`, and `defaultIdleTTL` only when that
|
|
42
|
+
* registry is created.
|
|
43
|
+
*
|
|
44
|
+
* **Gotchas**
|
|
45
|
+
*
|
|
46
|
+
* Option changes after the first render do not rebuild the registry. When the
|
|
47
|
+
* provider unmounts, registry disposal is delayed briefly and canceled if the
|
|
48
|
+
* provider remounts before the timeout fires.
|
|
49
|
+
*
|
|
50
|
+
* @see {@link RegistryContext} for the React context supplied by this provider
|
|
51
|
+
*
|
|
16
52
|
* @category context
|
|
53
|
+
* @since 4.0.0
|
|
17
54
|
*/
|
|
18
55
|
export declare const RegistryProvider: (options: {
|
|
19
56
|
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;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,0CAGzB,CAAA;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;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,61 @@ 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
|
+
*
|
|
47
|
+
* **When to use**
|
|
48
|
+
*
|
|
49
|
+
* Use to supply an existing `AtomRegistry` through React context when hooks or
|
|
50
|
+
* hydration helpers need to share registry state that is managed outside
|
|
51
|
+
* `RegistryProvider`.
|
|
52
|
+
*
|
|
53
|
+
* @see {@link RegistryProvider} for creating and providing a registry for a React subtree
|
|
54
|
+
*
|
|
19
55
|
* @category context
|
|
56
|
+
* @since 4.0.0
|
|
20
57
|
*/
|
|
21
58
|
export const RegistryContext = /*#__PURE__*/React.createContext(/*#__PURE__*/AtomRegistry.make({
|
|
22
59
|
scheduleTask,
|
|
23
60
|
defaultIdleTTL: 400
|
|
24
61
|
}));
|
|
25
62
|
/**
|
|
26
|
-
*
|
|
63
|
+
* Provides a stable `AtomRegistry` to a React subtree, optionally seeding
|
|
64
|
+
* initial atom values and overriding registry scheduling or idle settings.
|
|
65
|
+
*
|
|
66
|
+
* **When to use**
|
|
67
|
+
*
|
|
68
|
+
* Use to scope atom state, scheduling, and idle cleanup to a React subtree.
|
|
69
|
+
*
|
|
70
|
+
* **Details**
|
|
71
|
+
*
|
|
72
|
+
* The provider creates one `AtomRegistry` with `AtomRegistry.make`, passes it
|
|
73
|
+
* through `RegistryContext.Provider`, and forwards `initialValues`,
|
|
74
|
+
* `scheduleTask`, `timeoutResolution`, and `defaultIdleTTL` only when that
|
|
75
|
+
* registry is created.
|
|
76
|
+
*
|
|
77
|
+
* **Gotchas**
|
|
78
|
+
*
|
|
79
|
+
* Option changes after the first render do not rebuild the registry. When the
|
|
80
|
+
* provider unmounts, registry disposal is delayed briefly and canceled if the
|
|
81
|
+
* provider remounts before the timeout fires.
|
|
82
|
+
*
|
|
83
|
+
* @see {@link RegistryContext} for the React context supplied by this provider
|
|
84
|
+
*
|
|
27
85
|
* @category context
|
|
86
|
+
* @since 4.0.0
|
|
28
87
|
*/
|
|
29
88
|
export const RegistryProvider = options => {
|
|
30
89
|
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,M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EgB,QAAQ,CAAC;AAC1G,CAAC","ignoreList":[]}
|
package/dist/ScopedAtom.d.ts
CHANGED
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
import type * as Atom from "effect/unstable/reactivity/Atom";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @category Type IDs
|
|
4
|
+
* Literal type used as the `ScopedAtom` type identifier.
|
|
6
5
|
*
|
|
7
|
-
*
|
|
6
|
+
* **Details**
|
|
7
|
+
*
|
|
8
|
+
* Used as the computed property key and marker value stored on `ScopedAtom`
|
|
9
|
+
* objects.
|
|
10
|
+
*
|
|
11
|
+
* @category type IDs
|
|
12
|
+
* @since 4.0.0
|
|
8
13
|
*/
|
|
9
14
|
export type TypeId = "~@effect/atom-react/ScopedAtom";
|
|
10
15
|
/**
|
|
11
|
-
* @since 1.0.0
|
|
12
|
-
* @category Type IDs
|
|
13
|
-
*
|
|
14
16
|
* Type identifier for ScopedAtom.
|
|
17
|
+
*
|
|
18
|
+
* **Details**
|
|
19
|
+
*
|
|
20
|
+
* Used as the computed property key and marker value stored on `ScopedAtom`
|
|
21
|
+
* objects.
|
|
22
|
+
*
|
|
23
|
+
* @category type IDs
|
|
24
|
+
* @since 4.0.0
|
|
15
25
|
*/
|
|
16
26
|
export declare const TypeId: TypeId;
|
|
17
27
|
/**
|
|
18
|
-
* @since 1.0.0
|
|
19
|
-
* @category models
|
|
20
|
-
*
|
|
21
28
|
* Scoped Atom interface with a provider-backed instance.
|
|
22
29
|
*
|
|
23
|
-
*
|
|
30
|
+
* **Example** (Providing and reading a scoped atom)
|
|
31
|
+
*
|
|
24
32
|
* ```ts
|
|
25
|
-
* import
|
|
33
|
+
* import { make, useAtomValue } from "@effect/atom-react"
|
|
34
|
+
* import { Atom } from "effect/unstable/reactivity"
|
|
26
35
|
* import * as React from "react"
|
|
27
|
-
* import * as ScopedAtom from "@effect/atom-react/ScopedAtom"
|
|
28
|
-
* import { useAtomValue } from "@effect/atom-react"
|
|
29
36
|
*
|
|
30
|
-
* const Counter =
|
|
37
|
+
* const Counter = make(() => Atom.make(0))
|
|
31
38
|
*
|
|
32
39
|
* function View() {
|
|
33
40
|
* const atom = Counter.use()
|
|
@@ -39,11 +46,14 @@ export declare const TypeId: TypeId;
|
|
|
39
46
|
* return React.createElement(Counter.Provider, null, React.createElement(View))
|
|
40
47
|
* }
|
|
41
48
|
* ```
|
|
49
|
+
*
|
|
50
|
+
* @category models
|
|
51
|
+
* @since 4.0.0
|
|
42
52
|
*/
|
|
43
53
|
export interface ScopedAtom<A extends Atom.Atom<any>, Input = never> {
|
|
44
54
|
readonly [TypeId]: TypeId;
|
|
45
55
|
use(): A;
|
|
46
|
-
Provider: Input extends never ? React.FC<{
|
|
56
|
+
Provider: [Input] extends [never] ? React.FC<{
|
|
47
57
|
readonly children?: React.ReactNode | undefined;
|
|
48
58
|
}> : React.FC<{
|
|
49
59
|
readonly children?: React.ReactNode | undefined;
|
|
@@ -52,19 +62,32 @@ export interface ScopedAtom<A extends Atom.Atom<any>, Input = never> {
|
|
|
52
62
|
Context: React.Context<A>;
|
|
53
63
|
}
|
|
54
64
|
/**
|
|
55
|
-
* @since 1.0.0
|
|
56
|
-
* @category constructors
|
|
57
|
-
*
|
|
58
65
|
* Creates a ScopedAtom from a factory function.
|
|
59
66
|
*
|
|
60
|
-
*
|
|
67
|
+
* **When to use**
|
|
68
|
+
*
|
|
69
|
+
* Use to create an atom instance that is owned by a React provider and scoped
|
|
70
|
+
* to a component subtree.
|
|
71
|
+
*
|
|
72
|
+
* **Details**
|
|
73
|
+
*
|
|
74
|
+
* The returned scoped atom includes a `Provider`, `Context`, and `use`
|
|
75
|
+
* accessor. The provider creates the atom once for its lifetime, passing the
|
|
76
|
+
* `value` prop to the factory when the scoped atom expects input.
|
|
77
|
+
*
|
|
78
|
+
* **Gotchas**
|
|
79
|
+
*
|
|
80
|
+
* `use` must run under the matching provider. Changing the provider `value`
|
|
81
|
+
* prop after mount does not recreate the atom.
|
|
82
|
+
*
|
|
83
|
+
* **Example** (Creating a scoped atom with input)
|
|
84
|
+
*
|
|
61
85
|
* ```ts
|
|
62
|
-
* import
|
|
86
|
+
* import { make, useAtomValue } from "@effect/atom-react"
|
|
87
|
+
* import { Atom } from "effect/unstable/reactivity"
|
|
63
88
|
* import * as React from "react"
|
|
64
|
-
* import * as ScopedAtom from "@effect/atom-react/ScopedAtom"
|
|
65
|
-
* import { useAtomValue } from "@effect/atom-react"
|
|
66
89
|
*
|
|
67
|
-
* const User =
|
|
90
|
+
* const User = make((name: string) => Atom.make(name))
|
|
68
91
|
*
|
|
69
92
|
* function UserName() {
|
|
70
93
|
* const atom = User.use()
|
|
@@ -80,6 +103,9 @@ export interface ScopedAtom<A extends Atom.Atom<any>, Input = never> {
|
|
|
80
103
|
* )
|
|
81
104
|
* }
|
|
82
105
|
* ```
|
|
106
|
+
*
|
|
107
|
+
* @category constructors
|
|
108
|
+
* @since 4.0.0
|
|
83
109
|
*/
|
|
84
110
|
export declare const make: <A extends Atom.Atom<any>, Input = never>(f: (() => A) | ((input: Input) => A)) => ScopedAtom<A, Input>;
|
|
85
111
|
//# sourceMappingURL=ScopedAtom.d.ts.map
|
package/dist/ScopedAtom.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScopedAtom.d.ts","sourceRoot":"","sources":["../src/ScopedAtom.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ScopedAtom.d.ts","sourceRoot":"","sources":["../src/ScopedAtom.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,KAAK,IAAI,MAAM,iCAAiC,CAAA;AAC5D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B;;;;;;;;;;GAUG;AACH,MAAM,MAAM,MAAM,GAAG,gCAAgC,CAAA;AAErD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,MAAM,EAAE,MAAyC,CAAA;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK;IACjE,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACzB,GAAG,IAAI,CAAC,CAAA;IACR,QAAQ,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC;QAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,SAAS,CAAA;KAAE,CAAC,GAC7F,KAAK,CAAC,EAAE,CAAC;QAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,SAAS,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC,CAAA;IACxF,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,EAC1D,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,CAAC,CAAC,KACnC,UAAU,CAAC,CAAC,EAAE,KAAK,CA6BrB,CAAA"}
|
package/dist/ScopedAtom.js
CHANGED
|
@@ -1,30 +1,65 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `ScopedAtom` module provides a small React integration for creating atom
|
|
3
|
+
* instances that are scoped to a component subtree. A scoped atom bundles a
|
|
4
|
+
* React provider, context, and `use` accessor so each mounted provider owns its
|
|
5
|
+
* own atom instance instead of sharing a single module-level atom.
|
|
6
|
+
*
|
|
7
|
+
* Use `ScopedAtom` when an atom needs to be isolated per feature, route,
|
|
8
|
+
* component instance, test harness, or provider input. The provider may receive
|
|
9
|
+
* an initial `value` that is passed to the atom factory, making it useful for
|
|
10
|
+
* state that should be seeded from React props while still being consumed by the
|
|
11
|
+
* atom hooks in descendants.
|
|
12
|
+
*
|
|
13
|
+
* **Gotchas**
|
|
14
|
+
*
|
|
15
|
+
* - `use` must be called under the matching provider or it throws.
|
|
16
|
+
* - The provider creates the atom once for its lifetime; changing the provider
|
|
17
|
+
* `value` prop after mount does not recreate the atom.
|
|
18
|
+
*
|
|
19
|
+
* @since 4.0.0
|
|
3
20
|
*/
|
|
4
21
|
"use client";
|
|
5
22
|
|
|
6
23
|
import * as React from "react";
|
|
7
24
|
/**
|
|
8
|
-
* @since 1.0.0
|
|
9
|
-
* @category Type IDs
|
|
10
|
-
*
|
|
11
25
|
* Type identifier for ScopedAtom.
|
|
26
|
+
*
|
|
27
|
+
* **Details**
|
|
28
|
+
*
|
|
29
|
+
* Used as the computed property key and marker value stored on `ScopedAtom`
|
|
30
|
+
* objects.
|
|
31
|
+
*
|
|
32
|
+
* @category type IDs
|
|
33
|
+
* @since 4.0.0
|
|
12
34
|
*/
|
|
13
35
|
export const TypeId = "~@effect/atom-react/ScopedAtom";
|
|
14
36
|
/**
|
|
15
|
-
* @since 1.0.0
|
|
16
|
-
* @category constructors
|
|
17
|
-
*
|
|
18
37
|
* Creates a ScopedAtom from a factory function.
|
|
19
38
|
*
|
|
20
|
-
*
|
|
39
|
+
* **When to use**
|
|
40
|
+
*
|
|
41
|
+
* Use to create an atom instance that is owned by a React provider and scoped
|
|
42
|
+
* to a component subtree.
|
|
43
|
+
*
|
|
44
|
+
* **Details**
|
|
45
|
+
*
|
|
46
|
+
* The returned scoped atom includes a `Provider`, `Context`, and `use`
|
|
47
|
+
* accessor. The provider creates the atom once for its lifetime, passing the
|
|
48
|
+
* `value` prop to the factory when the scoped atom expects input.
|
|
49
|
+
*
|
|
50
|
+
* **Gotchas**
|
|
51
|
+
*
|
|
52
|
+
* `use` must run under the matching provider. Changing the provider `value`
|
|
53
|
+
* prop after mount does not recreate the atom.
|
|
54
|
+
*
|
|
55
|
+
* **Example** (Creating a scoped atom with input)
|
|
56
|
+
*
|
|
21
57
|
* ```ts
|
|
22
|
-
* import
|
|
58
|
+
* import { make, useAtomValue } from "@effect/atom-react"
|
|
59
|
+
* import { Atom } from "effect/unstable/reactivity"
|
|
23
60
|
* import * as React from "react"
|
|
24
|
-
* import * as ScopedAtom from "@effect/atom-react/ScopedAtom"
|
|
25
|
-
* import { useAtomValue } from "@effect/atom-react"
|
|
26
61
|
*
|
|
27
|
-
* const User =
|
|
62
|
+
* const User = make((name: string) => Atom.make(name))
|
|
28
63
|
*
|
|
29
64
|
* function UserName() {
|
|
30
65
|
* const atom = User.use()
|
|
@@ -40,6 +75,9 @@ export const TypeId = "~@effect/atom-react/ScopedAtom";
|
|
|
40
75
|
* )
|
|
41
76
|
* }
|
|
42
77
|
* ```
|
|
78
|
+
*
|
|
79
|
+
* @category constructors
|
|
80
|
+
* @since 4.0.0
|
|
43
81
|
*/
|
|
44
82
|
export const make = f => {
|
|
45
83
|
const Context = React.createContext(undefined);
|
package/dist/ScopedAtom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScopedAtom.js","names":["React","TypeId","make","f","Context","createContext","undefined","use","atom","useContext","Error","Provider","props","useRef","current","value","createElement","children"],"sources":["../src/ScopedAtom.ts"],"sourcesContent":[null],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ScopedAtom.js","names":["React","TypeId","make","f","Context","createContext","undefined","use","atom","useContext","Error","Provider","props","useRef","current","value","createElement","children"],"sources":["../src/ScopedAtom.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;AAoBA,YAAY;;AAGZ,OAAO,KAAKA,KAAK,MAAM,OAAO;AAe9B;;;;;;;;;;;AAWA,OAAO,MAAMC,MAAM,GAAW,gCAAgC;AAoC9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,OAAO,MAAMC,IAAI,GACfC,CAAoC,IACZ;EACxB,MAAMC,OAAO,GAAGJ,KAAK,CAACK,aAAa,CAAIC,SAAyB,CAAC;EAEjE,MAAMC,GAAG,GAAGA,CAAA,KAAQ;IAClB,MAAMC,IAAI,GAAGR,KAAK,CAACS,UAAU,CAACL,OAAO,CAAC;IACtC,IAAII,IAAI,KAAKF,SAAS,EAAE;MACtB,MAAM,IAAII,KAAK,CAAC,yCAAyC,CAAC;IAC5D;IACA,OAAOF,IAAI;EACb,CAAC;EAED,MAAMG,QAAQ,GAA2FC,KAAK,IAAI;IAChH,MAAMJ,IAAI,GAAGR,KAAK,CAACa,MAAM,CAAW,IAAI,CAAC;IACzC,IAAIL,IAAI,CAACM,OAAO,KAAK,IAAI,EAAE;MACzB,IAAI,OAAO,IAAIF,KAAK,EAAE;QACpBJ,IAAI,CAACM,OAAO,GAAIX,CAAyB,CAACS,KAAK,CAACG,KAAc,CAAC;MACjE,CAAC,MAAM;QACLP,IAAI,CAACM,OAAO,GAAIX,CAAa,EAAE;MACjC;IACF;IACA,OAAOH,KAAK,CAACgB,aAAa,CAACZ,OAAO,CAACO,QAAQ,EAAE;MAAEI,KAAK,EAAEP,IAAI,CAACM;IAAO,CAAE,EAAEF,KAAK,CAACK,QAAQ,CAAC;EACvF,CAAC;EAED,OAAO;IACL,CAAChB,MAAM,GAAGA,MAAM;IAChBM,GAAG;IACHI,QAAQ,EAAEA,QAAe;IACzBP;GACD;AACH,CAAC","ignoreList":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
* @since
|
|
5
|
+
* @since 4.0.0
|
|
6
6
|
*/
|
|
7
7
|
export * from "./Hooks.ts";
|
|
8
8
|
/**
|
|
9
|
-
* @since
|
|
9
|
+
* @since 4.0.0
|
|
10
10
|
*/
|
|
11
11
|
export * from "./RegistryContext.ts";
|
|
12
12
|
/**
|
|
13
|
-
* @since
|
|
13
|
+
* @since 4.0.0
|
|
14
14
|
*/
|
|
15
15
|
export * from "./ReactHydration.ts";
|
|
16
16
|
/**
|
|
17
|
-
* @since
|
|
17
|
+
* @since 4.0.0
|
|
18
18
|
*/
|
|
19
19
|
export * from "./ScopedAtom.ts";
|
|
20
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @since
|
|
2
|
+
* @since 4.0.0
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
* @since
|
|
5
|
+
* @since 4.0.0
|
|
6
6
|
*/
|
|
7
7
|
export * from "./Hooks.js";
|
|
8
8
|
/**
|
|
9
|
-
* @since
|
|
9
|
+
* @since 4.0.0
|
|
10
10
|
*/
|
|
11
11
|
export * from "./RegistryContext.js";
|
|
12
12
|
/**
|
|
13
|
-
* @since
|
|
13
|
+
* @since 4.0.0
|
|
14
14
|
*/
|
|
15
15
|
export * from "./ReactHydration.js";
|
|
16
16
|
/**
|
|
17
|
-
* @since
|
|
17
|
+
* @since 4.0.0
|
|
18
18
|
*/
|
|
19
19
|
export * from "./ScopedAtom.js";
|
|
20
20
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/atom-react",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.71",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "React bindings for the Effect Atom modules",
|
|
@@ -45,21 +45,21 @@
|
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"react": "^19.2.4",
|
|
47
47
|
"scheduler": "*",
|
|
48
|
-
"effect": "^4.0.0-beta.
|
|
48
|
+
"effect": "^4.0.0-beta.71"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@testing-library/dom": "^10.4.1",
|
|
52
52
|
"@testing-library/jest-dom": "^6.9.1",
|
|
53
|
-
"@testing-library/react": "^16.3.
|
|
54
|
-
"@types/react": "^19.2.
|
|
53
|
+
"@testing-library/react": "^16.3.2",
|
|
54
|
+
"@types/react": "^19.2.14",
|
|
55
55
|
"@types/react-dom": "^19.2.2",
|
|
56
56
|
"@types/scheduler": "^0.26.0",
|
|
57
|
-
"jsdom": "^
|
|
58
|
-
"react": "19.2.
|
|
59
|
-
"react-dom": "19.2.
|
|
60
|
-
"react-error-boundary": "^6.
|
|
57
|
+
"jsdom": "^29.1.1",
|
|
58
|
+
"react": "19.2.6",
|
|
59
|
+
"react-dom": "19.2.6",
|
|
60
|
+
"react-error-boundary": "^6.1.1",
|
|
61
61
|
"scheduler": "^0.27.0",
|
|
62
|
-
"effect": "^4.0.0-beta.
|
|
62
|
+
"effect": "^4.0.0-beta.71"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "tsc -b tsconfig.json && pnpm babel",
|