@effect/atom-solid 4.0.0-beta.66 → 4.0.0-beta.67
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 +50 -13
- package/dist/Hooks.d.ts.map +1 -1
- package/dist/Hooks.js +64 -12
- package/dist/Hooks.js.map +1 -1
- package/dist/RegistryContext.d.ts +32 -3
- package/dist/RegistryContext.d.ts.map +1 -1
- package/dist/RegistryContext.js +9 -2
- package/dist/RegistryContext.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/package.json +4 -4
- package/src/Hooks.ts +72 -14
- package/src/RegistryContext.ts +32 -3
- package/src/index.ts +3 -3
package/dist/Hooks.d.ts
CHANGED
|
@@ -4,77 +4,114 @@ import * as Atom from "effect/unstable/reactivity/Atom";
|
|
|
4
4
|
import type * as AtomRef from "effect/unstable/reactivity/AtomRef";
|
|
5
5
|
import type { Accessor, ResourceOptions, ResourceReturn } from "solid-js";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Seeds initial atom values in the current Solid atom registry.
|
|
8
|
+
*
|
|
9
|
+
* **Details**
|
|
10
|
+
*
|
|
11
|
+
* Each atom is initialized at most once for a given registry, so subsequent
|
|
12
|
+
* computations do not overwrite values that have already been established.
|
|
13
|
+
*
|
|
8
14
|
* @category hooks
|
|
15
|
+
* @since 4.0.0
|
|
9
16
|
*/
|
|
10
17
|
export declare const useAtomInitialValues: (initialValues: Iterable<readonly [Atom.Atom<any>, any]>) => void;
|
|
11
18
|
/**
|
|
12
|
-
*
|
|
19
|
+
* Subscribes to an atom in the current Solid registry and returns its value as
|
|
20
|
+
* a Solid accessor.
|
|
21
|
+
*
|
|
13
22
|
* @category hooks
|
|
23
|
+
* @since 4.0.0
|
|
14
24
|
*/
|
|
15
25
|
export declare const useAtomValue: {
|
|
16
26
|
/**
|
|
17
|
-
*
|
|
27
|
+
* Subscribes to an atom in the current Solid registry and returns its value as
|
|
28
|
+
* a Solid accessor.
|
|
29
|
+
*
|
|
18
30
|
* @category hooks
|
|
31
|
+
* @since 4.0.0
|
|
19
32
|
*/
|
|
20
33
|
<A>(atom: () => Atom.Atom<A>): Accessor<A>;
|
|
21
34
|
/**
|
|
22
|
-
*
|
|
35
|
+
* Subscribes to an atom in the current Solid registry and returns its value as
|
|
36
|
+
* a Solid accessor.
|
|
37
|
+
*
|
|
23
38
|
* @category hooks
|
|
39
|
+
* @since 4.0.0
|
|
24
40
|
*/
|
|
25
41
|
<A, B>(atom: () => Atom.Atom<A>, f: (_: A) => B): Accessor<B>;
|
|
26
42
|
};
|
|
27
43
|
/**
|
|
28
|
-
*
|
|
44
|
+
* Mounts an atom in the current Solid registry for the lifetime of the current
|
|
45
|
+
* Solid computation.
|
|
46
|
+
*
|
|
29
47
|
* @category hooks
|
|
48
|
+
* @since 4.0.0
|
|
30
49
|
*/
|
|
31
50
|
export declare const useAtomMount: <A>(atom: () => Atom.Atom<A>) => void;
|
|
32
51
|
/**
|
|
33
|
-
*
|
|
52
|
+
* Returns a setter for a writable atom without subscribing to its value.
|
|
53
|
+
*
|
|
34
54
|
* @category hooks
|
|
55
|
+
* @since 4.0.0
|
|
35
56
|
*/
|
|
36
57
|
export declare const useAtomSet: <R, W, Mode extends "value" | "promise" | "promiseExit" = never>(atom: () => Atom.Writable<R, W>, options?: {
|
|
37
58
|
readonly mode?: ([R] extends [AsyncResult.AsyncResult<any, any>] ? Mode : "value") | undefined;
|
|
38
59
|
}) => "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);
|
|
39
60
|
/**
|
|
40
|
-
*
|
|
61
|
+
* Mounts an atom and returns a callback that refreshes the current atom.
|
|
62
|
+
*
|
|
41
63
|
* @category hooks
|
|
64
|
+
* @since 4.0.0
|
|
42
65
|
*/
|
|
43
66
|
export declare const useAtomRefresh: <A>(atom: () => Atom.Atom<A>) => () => void;
|
|
44
67
|
/**
|
|
45
|
-
*
|
|
68
|
+
* Returns a Solid accessor for a writable atom together with a setter for
|
|
69
|
+
* updating it.
|
|
70
|
+
*
|
|
46
71
|
* @category hooks
|
|
72
|
+
* @since 4.0.0
|
|
47
73
|
*/
|
|
48
74
|
export declare const useAtom: <R, W, const Mode extends "value" | "promise" | "promiseExit" = never>(atom: () => Atom.Writable<R, W>, options?: {
|
|
49
75
|
readonly mode?: ([R] extends [AsyncResult.AsyncResult<any, any>] ? Mode : "value") | undefined;
|
|
50
76
|
}) => readonly [value: Accessor<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)];
|
|
51
77
|
/**
|
|
52
|
-
*
|
|
78
|
+
* Subscribes a callback to an atom in the current Solid registry.
|
|
79
|
+
*
|
|
53
80
|
* @category hooks
|
|
81
|
+
* @since 4.0.0
|
|
54
82
|
*/
|
|
55
83
|
export declare const useAtomSubscribe: <A>(atom: () => Atom.Atom<A>, f: (_: A) => void, options?: {
|
|
56
84
|
readonly immediate?: boolean;
|
|
57
85
|
}) => void;
|
|
58
86
|
/**
|
|
59
|
-
*
|
|
87
|
+
* Converts an `AsyncResult` atom into a Solid resource.
|
|
88
|
+
*
|
|
60
89
|
* @category hooks
|
|
90
|
+
* @since 4.0.0
|
|
61
91
|
*/
|
|
62
92
|
export declare const useAtomResource: <A, E>(atom: () => Atom.Atom<AsyncResult.AsyncResult<A, E>>, options?: ResourceOptions<A> & {
|
|
63
93
|
readonly suspendOnWaiting?: boolean | undefined;
|
|
64
94
|
}) => ResourceReturn<A, void>;
|
|
65
95
|
/**
|
|
66
|
-
*
|
|
96
|
+
* Subscribes to an atom ref and returns its value as a Solid accessor.
|
|
97
|
+
*
|
|
67
98
|
* @category hooks
|
|
99
|
+
* @since 4.0.0
|
|
68
100
|
*/
|
|
69
101
|
export declare const useAtomRef: <A>(ref: () => AtomRef.ReadonlyRef<A>) => Accessor<A>;
|
|
70
102
|
/**
|
|
71
|
-
*
|
|
103
|
+
* Returns a Solid accessor for a property ref derived from an atom ref.
|
|
104
|
+
*
|
|
72
105
|
* @category hooks
|
|
106
|
+
* @since 4.0.0
|
|
73
107
|
*/
|
|
74
108
|
export declare const useAtomRefProp: <A, K extends keyof A>(ref: () => AtomRef.AtomRef<A>, prop: K) => Accessor<AtomRef.AtomRef<A[K]>>;
|
|
75
109
|
/**
|
|
76
|
-
*
|
|
110
|
+
* Returns a Solid accessor for the value of a property ref derived from an atom
|
|
111
|
+
* ref.
|
|
112
|
+
*
|
|
77
113
|
* @category hooks
|
|
114
|
+
* @since 4.0.0
|
|
78
115
|
*/
|
|
79
116
|
export declare const useAtomRefPropValue: <A, K extends keyof A>(ref: () => AtomRef.AtomRef<A>, prop: K) => Accessor<A[K]>;
|
|
80
117
|
//# 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":"AA0BA,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,WAAW,MAAM,wCAAwC,CAAA;AACrE,OAAO,KAAK,IAAI,MAAM,iCAAiC,CAAA;AACvD,OAAO,KAAK,KAAK,OAAO,MAAM,oCAAoC,CAAA;AAElE,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAMzE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB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,CAAC,CAAC,CAAC,CACzE,CAAA"}
|
package/dist/Hooks.js
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `Hooks` module provides SolidJS hooks for reading, writing, mounting, and
|
|
3
|
+
* subscribing to Effect atoms through the current Solid atom registry.
|
|
4
|
+
*
|
|
5
|
+
* **Common tasks**
|
|
6
|
+
*
|
|
7
|
+
* - Read an atom as a Solid accessor with {@link useAtomValue}
|
|
8
|
+
* - Read and write a writable atom with {@link useAtom}
|
|
9
|
+
* - Write without subscribing to the value with {@link useAtomSet}
|
|
10
|
+
* - Refresh or mount atoms from components with {@link useAtomRefresh} and {@link useAtomMount}
|
|
11
|
+
* - Convert `AsyncResult` atoms into Solid resources with {@link useAtomResource}
|
|
12
|
+
* - Work with atom refs and nested ref properties with {@link useAtomRef}, {@link useAtomRefProp},
|
|
13
|
+
* and {@link useAtomRefPropValue}
|
|
14
|
+
*
|
|
15
|
+
* **Solid integration notes**
|
|
16
|
+
*
|
|
17
|
+
* Hooks in this module read the registry from {@link RegistryContext}, so they
|
|
18
|
+
* should be used under the matching provider for the atom graph you want to
|
|
19
|
+
* observe. Atom arguments are thunks so Solid can track dynamic atom selection;
|
|
20
|
+
* subscriptions are registered in Solid computations and disposed with
|
|
21
|
+
* `onCleanup` when the computation changes or the component unmounts.
|
|
22
|
+
*
|
|
23
|
+
* @since 4.0.0
|
|
3
24
|
*/
|
|
4
25
|
import * as Cause from "effect/Cause";
|
|
5
26
|
import * as Effect from "effect/Effect";
|
|
@@ -11,8 +32,15 @@ import { createComputed, createEffect, createMemo, createResource, createSignal,
|
|
|
11
32
|
import { RegistryContext } from "./RegistryContext.js";
|
|
12
33
|
const initialValuesSet = /*#__PURE__*/new WeakMap();
|
|
13
34
|
/**
|
|
14
|
-
*
|
|
35
|
+
* Seeds initial atom values in the current Solid atom registry.
|
|
36
|
+
*
|
|
37
|
+
* **Details**
|
|
38
|
+
*
|
|
39
|
+
* Each atom is initialized at most once for a given registry, so subsequent
|
|
40
|
+
* computations do not overwrite values that have already been established.
|
|
41
|
+
*
|
|
15
42
|
* @category hooks
|
|
43
|
+
* @since 4.0.0
|
|
16
44
|
*/
|
|
17
45
|
export const useAtomInitialValues = initialValues => {
|
|
18
46
|
const registry = useContext(RegistryContext);
|
|
@@ -29,8 +57,11 @@ export const useAtomInitialValues = initialValues => {
|
|
|
29
57
|
}
|
|
30
58
|
};
|
|
31
59
|
/**
|
|
32
|
-
*
|
|
60
|
+
* Subscribes to an atom in the current Solid registry and returns its value as
|
|
61
|
+
* a Solid accessor.
|
|
62
|
+
*
|
|
33
63
|
* @category hooks
|
|
64
|
+
* @since 4.0.0
|
|
34
65
|
*/
|
|
35
66
|
export const useAtomValue = (atom, f) => {
|
|
36
67
|
const registry = useContext(RegistryContext);
|
|
@@ -71,16 +102,21 @@ const flattenExit = exit => {
|
|
|
71
102
|
throw Cause.squash(exit.cause);
|
|
72
103
|
};
|
|
73
104
|
/**
|
|
74
|
-
*
|
|
105
|
+
* Mounts an atom in the current Solid registry for the lifetime of the current
|
|
106
|
+
* Solid computation.
|
|
107
|
+
*
|
|
75
108
|
* @category hooks
|
|
109
|
+
* @since 4.0.0
|
|
76
110
|
*/
|
|
77
111
|
export const useAtomMount = atom => {
|
|
78
112
|
const registry = useContext(RegistryContext);
|
|
79
113
|
mountAtom(registry, atom);
|
|
80
114
|
};
|
|
81
115
|
/**
|
|
82
|
-
*
|
|
116
|
+
* Returns a setter for a writable atom without subscribing to its value.
|
|
117
|
+
*
|
|
83
118
|
* @category hooks
|
|
119
|
+
* @since 4.0.0
|
|
84
120
|
*/
|
|
85
121
|
export const useAtomSet = (atom, options) => {
|
|
86
122
|
const registry = useContext(RegistryContext);
|
|
@@ -88,8 +124,10 @@ export const useAtomSet = (atom, options) => {
|
|
|
88
124
|
return setAtom(registry, atom, options);
|
|
89
125
|
};
|
|
90
126
|
/**
|
|
91
|
-
*
|
|
127
|
+
* Mounts an atom and returns a callback that refreshes the current atom.
|
|
128
|
+
*
|
|
92
129
|
* @category hooks
|
|
130
|
+
* @since 4.0.0
|
|
93
131
|
*/
|
|
94
132
|
export const useAtomRefresh = atom => {
|
|
95
133
|
const registry = useContext(RegistryContext);
|
|
@@ -98,16 +136,21 @@ export const useAtomRefresh = atom => {
|
|
|
98
136
|
return () => registry.refresh(memo());
|
|
99
137
|
};
|
|
100
138
|
/**
|
|
101
|
-
*
|
|
139
|
+
* Returns a Solid accessor for a writable atom together with a setter for
|
|
140
|
+
* updating it.
|
|
141
|
+
*
|
|
102
142
|
* @category hooks
|
|
143
|
+
* @since 4.0.0
|
|
103
144
|
*/
|
|
104
145
|
export const useAtom = (atom, options) => {
|
|
105
146
|
const registry = useContext(RegistryContext);
|
|
106
147
|
return [createAtomAccessor(registry, atom), setAtom(registry, atom, options)];
|
|
107
148
|
};
|
|
108
149
|
/**
|
|
109
|
-
*
|
|
150
|
+
* Subscribes a callback to an atom in the current Solid registry.
|
|
151
|
+
*
|
|
110
152
|
* @category hooks
|
|
153
|
+
* @since 4.0.0
|
|
111
154
|
*/
|
|
112
155
|
export const useAtomSubscribe = (atom, f, options) => {
|
|
113
156
|
const registry = useContext(RegistryContext);
|
|
@@ -116,8 +159,10 @@ export const useAtomSubscribe = (atom, f, options) => {
|
|
|
116
159
|
});
|
|
117
160
|
};
|
|
118
161
|
/**
|
|
119
|
-
*
|
|
162
|
+
* Converts an `AsyncResult` atom into a Solid resource.
|
|
163
|
+
*
|
|
120
164
|
* @category hooks
|
|
165
|
+
* @since 4.0.0
|
|
121
166
|
*/
|
|
122
167
|
export const useAtomResource = (atom, options) => {
|
|
123
168
|
const result = useAtomValue(atom);
|
|
@@ -132,8 +177,10 @@ export const useAtomResource = (atom, options) => {
|
|
|
132
177
|
};
|
|
133
178
|
const constUnresolvedPromise = /*#__PURE__*/new Promise(() => {});
|
|
134
179
|
/**
|
|
135
|
-
*
|
|
180
|
+
* Subscribes to an atom ref and returns its value as a Solid accessor.
|
|
181
|
+
*
|
|
136
182
|
* @category hooks
|
|
183
|
+
* @since 4.0.0
|
|
137
184
|
*/
|
|
138
185
|
export const useAtomRef = ref => {
|
|
139
186
|
const [value, setValue] = createSignal(null);
|
|
@@ -145,13 +192,18 @@ export const useAtomRef = ref => {
|
|
|
145
192
|
return value;
|
|
146
193
|
};
|
|
147
194
|
/**
|
|
148
|
-
*
|
|
195
|
+
* Returns a Solid accessor for a property ref derived from an atom ref.
|
|
196
|
+
*
|
|
149
197
|
* @category hooks
|
|
198
|
+
* @since 4.0.0
|
|
150
199
|
*/
|
|
151
200
|
export const useAtomRefProp = (ref, prop) => createMemo(() => ref().prop(prop));
|
|
152
201
|
/**
|
|
153
|
-
*
|
|
202
|
+
* Returns a Solid accessor for the value of a property ref derived from an atom
|
|
203
|
+
* ref.
|
|
204
|
+
*
|
|
154
205
|
* @category hooks
|
|
206
|
+
* @since 4.0.0
|
|
155
207
|
*/
|
|
156
208
|
export const useAtomRefPropValue = (ref, prop) => useAtomRef(useAtomRefProp(ref, prop));
|
|
157
209
|
//# sourceMappingURL=Hooks.js.map
|
package/dist/Hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Hooks.js","names":["Cause","Effect","Exit","AsyncResult","Atom","AtomRegistry","createComputed","createEffect","createMemo","createResource","createSignal","onCleanup","useContext","RegistryContext","initialValuesSet","WeakMap","useAtomInitialValues","initialValues","registry","set","get","undefined","WeakSet","atom","value","has","add","ensureNode","setValue","useAtomValue","f","createAtomAccessor","map","subscribe","constImmediate","immediate","mountAtom","mount","setAtom","options","memo","mode","promise","runPromiseExit","getResult","suspendOnWaiting","then","flattenExit","exit","isSuccess","squash","cause","useAtomMount","useAtomSet","useAtomRefresh","refresh","useAtom","useAtomSubscribe","useAtomResource","result","isInitial","waiting","constUnresolvedPromise","Promise","resolve","reject","useAtomRef","ref","r","useAtomRefProp","prop","useAtomRefPropValue"],"sources":["../src/Hooks.ts"],"sourcesContent":[null],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Hooks.js","names":["Cause","Effect","Exit","AsyncResult","Atom","AtomRegistry","createComputed","createEffect","createMemo","createResource","createSignal","onCleanup","useContext","RegistryContext","initialValuesSet","WeakMap","useAtomInitialValues","initialValues","registry","set","get","undefined","WeakSet","atom","value","has","add","ensureNode","setValue","useAtomValue","f","createAtomAccessor","map","subscribe","constImmediate","immediate","mountAtom","mount","setAtom","options","memo","mode","promise","runPromiseExit","getResult","suspendOnWaiting","then","flattenExit","exit","isSuccess","squash","cause","useAtomMount","useAtomSet","useAtomRefresh","refresh","useAtom","useAtomSubscribe","useAtomResource","result","isInitial","waiting","constUnresolvedPromise","Promise","resolve","reject","useAtomRef","ref","r","useAtomRefProp","prop","useAtomRefPropValue"],"sources":["../src/Hooks.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,WAAW,MAAM,wCAAwC;AACrE,OAAO,KAAKC,IAAI,MAAM,iCAAiC;AAEvD,OAAO,KAAKC,YAAY,MAAM,yCAAyC;AAEvE,SAASC,cAAc,EAAEC,YAAY,EAAEC,UAAU,EAAEC,cAAc,EAAEC,YAAY,EAAEC,SAAS,EAAEC,UAAU,QAAQ,UAAU;AACxH,SAASC,eAAe,QAAQ,sBAAsB;AAEtD,MAAMC,gBAAgB,gBAAG,IAAIC,OAAO,EAAsD;AAE1F;;;;;;;;;;;AAWA,OAAO,MAAMC,oBAAoB,GAAIC,aAAuD,IAAU;EACpG,MAAMC,QAAQ,GAAGN,UAAU,CAACC,eAAe,CAAC;EAC5C,IAAIM,GAAG,GAAGL,gBAAgB,CAACM,GAAG,CAACF,QAAQ,CAAC;EACxC,IAAIC,GAAG,KAAKE,SAAS,EAAE;IACrBF,GAAG,GAAG,IAAIG,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,OAAO,EAAEM,gBAAgB,IAAIc,MAAM,CAACE,OAAQ,EAAE;MAClF,OAAOC,sBAAsB;IAC/B,CAAC,MAAM,IAAI3D,WAAW,CAAC8C,SAAS,CAACU,MAAM,CAAC,EAAE;MACxC,OAAOI,OAAO,CAACC,OAAO,CAACL,MAAM,CAACnC,KAAK,CAAC;IACtC;IACA,OAAOuC,OAAO,CAACE,MAAM,CAACjE,KAAK,CAACkD,MAAM,CAACS,MAAM,CAACR,KAAK,CAAC,CAAC;EACnD,CAAC,CAAC;AACJ,CAAC;AAED,MAAMW,sBAAsB,gBAAG,IAAIC,OAAO,CAAQ,MAAK,CAAE,CAAC,CAAC;AAE3D;;;;;;AAMA,OAAO,MAAMG,UAAU,GAAOC,GAAiC,IAAiB;EAC9E,MAAM,CAAC3C,KAAK,EAAEI,QAAQ,CAAC,GAAGlB,YAAY,CAAC,IAAS,CAAC;EACjDJ,cAAc,CAAC,MAAK;IAClB,MAAM8D,CAAC,GAAGD,GAAG,EAAE;IACfvC,QAAQ,CAACwC,CAAC,CAAC5C,KAAY,CAAC;IACxBb,SAAS,CAACyD,CAAC,CAACnC,SAAS,CAACL,QAAQ,CAAC,CAAC;EAClC,CAAC,CAAC;EACF,OAAOJ,KAAK;AACd,CAAC;AAED;;;;;;AAMA,OAAO,MAAM6C,cAAc,GAAGA,CAC5BF,GAA6B,EAC7BG,IAAO,KAC6B9D,UAAU,CAAC,MAAM2D,GAAG,EAAE,CAACG,IAAI,CAACA,IAAI,CAAC,CAAC;AAExE;;;;;;;AAOA,OAAO,MAAMC,mBAAmB,GAAGA,CAAuBJ,GAA6B,EAAEG,IAAO,KAC9FJ,UAAU,CAACG,cAAc,CAACF,GAAG,EAAEG,IAAI,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,17 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `RegistryContext` module provides the Solid context used by Effect Atom
|
|
3
|
+
* hooks to share an `AtomRegistry` across an owner tree. The registry owns atom
|
|
4
|
+
* state, scheduling, and idle cleanup, so Solid components that read or write
|
|
5
|
+
* atoms coordinate through the same runtime instead of creating isolated
|
|
6
|
+
* registries.
|
|
7
|
+
*
|
|
8
|
+
* **Common tasks**
|
|
9
|
+
*
|
|
10
|
+
* - Use {@link RegistryProvider} to scope atom state to a Solid subtree
|
|
11
|
+
* - Seed atoms for tests, examples, 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
|
+
* - The provider creates a registry for the current Solid owner and disposes it
|
|
18
|
+
* with `onCleanup`
|
|
19
|
+
* - `initialValues` are applied when the provider creates the registry, not as
|
|
20
|
+
* reactive updates after creation
|
|
21
|
+
* - Overriding `scheduleTask` changes when atom work is flushed, so it should
|
|
22
|
+
* return a cancellation function that is safe to call during Solid cleanup
|
|
23
|
+
*
|
|
24
|
+
* @since 4.0.0
|
|
3
25
|
*/
|
|
4
26
|
import type * as Atom from "effect/unstable/reactivity/Atom";
|
|
5
27
|
import * as AtomRegistry from "effect/unstable/reactivity/AtomRegistry";
|
|
6
28
|
import type { JSX } from "solid-js";
|
|
7
29
|
/**
|
|
8
|
-
*
|
|
30
|
+
* A Solid context that carries the `AtomRegistry` used by atom hooks in the
|
|
31
|
+
* current owner tree.
|
|
32
|
+
*
|
|
9
33
|
* @category context
|
|
34
|
+
* @since 4.0.0
|
|
10
35
|
*/
|
|
11
36
|
export declare const RegistryContext: import("solid-js").Context<AtomRegistry.AtomRegistry>;
|
|
12
37
|
/**
|
|
13
|
-
*
|
|
38
|
+
* Creates an `AtomRegistry` for a Solid subtree, optionally seeding initial atom
|
|
39
|
+
* values and scheduler settings, and disposes the registry when the owner is
|
|
40
|
+
* cleaned up.
|
|
41
|
+
*
|
|
14
42
|
* @category context
|
|
43
|
+
* @since 4.0.0
|
|
15
44
|
*/
|
|
16
45
|
export declare const RegistryProvider: (options: {
|
|
17
46
|
readonly children?: JSX.Element | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegistryContext.d.ts","sourceRoot":"","sources":["../src/RegistryContext.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"RegistryContext.d.ts","sourceRoot":"","sources":["../src/RegistryContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,KAAK,IAAI,MAAM,iCAAiC,CAAA;AAC5D,OAAO,KAAK,YAAY,MAAM,yCAAyC,CAAA;AACvE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAGnC;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,uDAAgE,CAAA;AAE5F;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAAI,SAAS;IACxC,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,OAAO,GAAG,SAAS,CAAA;IAC3C,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,gBAcA,CAAA"}
|
package/dist/RegistryContext.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import * as AtomRegistry from "effect/unstable/reactivity/AtomRegistry";
|
|
2
2
|
import { createComponent, createContext, onCleanup } from "solid-js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* A Solid context that carries the `AtomRegistry` used by atom hooks in the
|
|
5
|
+
* current owner tree.
|
|
6
|
+
*
|
|
5
7
|
* @category context
|
|
8
|
+
* @since 4.0.0
|
|
6
9
|
*/
|
|
7
10
|
export const RegistryContext = /*#__PURE__*/createContext(/*#__PURE__*/AtomRegistry.make());
|
|
8
11
|
/**
|
|
9
|
-
*
|
|
12
|
+
* Creates an `AtomRegistry` for a Solid subtree, optionally seeding initial atom
|
|
13
|
+
* values and scheduler settings, and disposes the registry when the owner is
|
|
14
|
+
* cleaned up.
|
|
15
|
+
*
|
|
10
16
|
* @category context
|
|
17
|
+
* @since 4.0.0
|
|
11
18
|
*/
|
|
12
19
|
export const RegistryProvider = options => {
|
|
13
20
|
const registry = AtomRegistry.make({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegistryContext.js","names":["AtomRegistry","createComponent","createContext","onCleanup","RegistryContext","make","RegistryProvider","options","registry","scheduleTask","initialValues","timeoutResolution","defaultIdleTTL","dispose","Provider","value","children"],"sources":["../src/RegistryContext.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"file":"RegistryContext.js","names":["AtomRegistry","createComponent","createContext","onCleanup","RegistryContext","make","RegistryProvider","options","registry","scheduleTask","initialValues","timeoutResolution","defaultIdleTTL","dispose","Provider","value","children"],"sources":["../src/RegistryContext.ts"],"sourcesContent":[null],"mappings":"AA0BA,OAAO,KAAKA,YAAY,MAAM,yCAAyC;AAEvE,SAASC,eAAe,EAAEC,aAAa,EAAEC,SAAS,QAAQ,UAAU;AAEpE;;;;;;;AAOA,OAAO,MAAMC,eAAe,gBAAGF,aAAa,cAA4BF,YAAY,CAACK,IAAI,EAAE,CAAC;AAE5F;;;;;;;;AAQA,OAAO,MAAMC,gBAAgB,GAAIC,OAMhC,IAAI;EACH,MAAMC,QAAQ,GAAGR,YAAY,CAACK,IAAI,CAAC;IACjCI,YAAY,EAAEF,OAAO,CAACE,YAAY;IAClCC,aAAa,EAAEH,OAAO,CAACG,aAAa;IACpCC,iBAAiB,EAAEJ,OAAO,CAACI,iBAAiB;IAC5CC,cAAc,EAAEL,OAAO,CAACK,cAAc,IAAI;GAC3C,CAAC;EACFT,SAAS,CAAC,MAAMK,QAAQ,CAACK,OAAO,EAAE,CAAC;EACnC,OAAOZ,eAAe,CAACG,eAAe,CAACU,QAAQ,EAAE;IAC/CC,KAAK,EAAEP,QAAQ;IACf,IAAIQ,QAAQA,CAAA;MACV,OAAOT,OAAO,CAACS,QAAQ;IACzB;GACD,CAAC;AACJ,CAAC","ignoreList":[]}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/atom-solid",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.67",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "SolidJS bindings for the Effect Atom modules",
|
|
@@ -44,15 +44,15 @@
|
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"solid-js": ">=1 <2",
|
|
47
|
-
"effect": "^4.0.0-beta.
|
|
47
|
+
"effect": "^4.0.0-beta.67"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@solidjs/testing-library": "^0.8.0",
|
|
51
51
|
"@testing-library/dom": "^10.4.1",
|
|
52
52
|
"@testing-library/jest-dom": "^6.9.1",
|
|
53
|
-
"jsdom": "^29.
|
|
53
|
+
"jsdom": "^29.1.1",
|
|
54
54
|
"solid-js": "^1.9.12",
|
|
55
|
-
"effect": "^4.0.0-beta.
|
|
55
|
+
"effect": "^4.0.0-beta.67"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "tsc -b tsconfig.json && pnpm babel",
|
package/src/Hooks.ts
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `Hooks` module provides SolidJS hooks for reading, writing, mounting, and
|
|
3
|
+
* subscribing to Effect atoms through the current Solid atom registry.
|
|
4
|
+
*
|
|
5
|
+
* **Common tasks**
|
|
6
|
+
*
|
|
7
|
+
* - Read an atom as a Solid accessor with {@link useAtomValue}
|
|
8
|
+
* - Read and write a writable atom with {@link useAtom}
|
|
9
|
+
* - Write without subscribing to the value with {@link useAtomSet}
|
|
10
|
+
* - Refresh or mount atoms from components with {@link useAtomRefresh} and {@link useAtomMount}
|
|
11
|
+
* - Convert `AsyncResult` atoms into Solid resources with {@link useAtomResource}
|
|
12
|
+
* - Work with atom refs and nested ref properties with {@link useAtomRef}, {@link useAtomRefProp},
|
|
13
|
+
* and {@link useAtomRefPropValue}
|
|
14
|
+
*
|
|
15
|
+
* **Solid integration notes**
|
|
16
|
+
*
|
|
17
|
+
* Hooks in this module read the registry from {@link RegistryContext}, so they
|
|
18
|
+
* should be used under the matching provider for the atom graph you want to
|
|
19
|
+
* observe. Atom arguments are thunks so Solid can track dynamic atom selection;
|
|
20
|
+
* subscriptions are registered in Solid computations and disposed with
|
|
21
|
+
* `onCleanup` when the computation changes or the component unmounts.
|
|
22
|
+
*
|
|
23
|
+
* @since 4.0.0
|
|
3
24
|
*/
|
|
4
25
|
import * as Cause from "effect/Cause"
|
|
5
26
|
import * as Effect from "effect/Effect"
|
|
@@ -15,8 +36,15 @@ import { RegistryContext } from "./RegistryContext.ts"
|
|
|
15
36
|
const initialValuesSet = new WeakMap<AtomRegistry.AtomRegistry, WeakSet<Atom.Atom<any>>>()
|
|
16
37
|
|
|
17
38
|
/**
|
|
18
|
-
*
|
|
39
|
+
* Seeds initial atom values in the current Solid atom registry.
|
|
40
|
+
*
|
|
41
|
+
* **Details**
|
|
42
|
+
*
|
|
43
|
+
* Each atom is initialized at most once for a given registry, so subsequent
|
|
44
|
+
* computations do not overwrite values that have already been established.
|
|
45
|
+
*
|
|
19
46
|
* @category hooks
|
|
47
|
+
* @since 4.0.0
|
|
20
48
|
*/
|
|
21
49
|
export const useAtomInitialValues = (initialValues: Iterable<readonly [Atom.Atom<any>, any]>): void => {
|
|
22
50
|
const registry = useContext(RegistryContext)
|
|
@@ -34,18 +62,27 @@ export const useAtomInitialValues = (initialValues: Iterable<readonly [Atom.Atom
|
|
|
34
62
|
}
|
|
35
63
|
|
|
36
64
|
/**
|
|
37
|
-
*
|
|
65
|
+
* Subscribes to an atom in the current Solid registry and returns its value as
|
|
66
|
+
* a Solid accessor.
|
|
67
|
+
*
|
|
38
68
|
* @category hooks
|
|
69
|
+
* @since 4.0.0
|
|
39
70
|
*/
|
|
40
71
|
export const useAtomValue: {
|
|
41
72
|
/**
|
|
42
|
-
*
|
|
73
|
+
* Subscribes to an atom in the current Solid registry and returns its value as
|
|
74
|
+
* a Solid accessor.
|
|
75
|
+
*
|
|
43
76
|
* @category hooks
|
|
77
|
+
* @since 4.0.0
|
|
44
78
|
*/
|
|
45
79
|
<A>(atom: () => Atom.Atom<A>): Accessor<A>
|
|
46
80
|
/**
|
|
47
|
-
*
|
|
81
|
+
* Subscribes to an atom in the current Solid registry and returns its value as
|
|
82
|
+
* a Solid accessor.
|
|
83
|
+
*
|
|
48
84
|
* @category hooks
|
|
85
|
+
* @since 4.0.0
|
|
49
86
|
*/
|
|
50
87
|
<A, B>(atom: () => Atom.Atom<A>, f: (_: A) => B): Accessor<B>
|
|
51
88
|
} = <A>(atom: () => Atom.Atom<A>, f?: (_: A) => A): Accessor<A> => {
|
|
@@ -106,8 +143,11 @@ const flattenExit = <A, E>(exit: Exit.Exit<A, E>): A => {
|
|
|
106
143
|
}
|
|
107
144
|
|
|
108
145
|
/**
|
|
109
|
-
*
|
|
146
|
+
* Mounts an atom in the current Solid registry for the lifetime of the current
|
|
147
|
+
* Solid computation.
|
|
148
|
+
*
|
|
110
149
|
* @category hooks
|
|
150
|
+
* @since 4.0.0
|
|
111
151
|
*/
|
|
112
152
|
export const useAtomMount = <A>(atom: () => Atom.Atom<A>): void => {
|
|
113
153
|
const registry = useContext(RegistryContext)
|
|
@@ -115,8 +155,10 @@ export const useAtomMount = <A>(atom: () => Atom.Atom<A>): void => {
|
|
|
115
155
|
}
|
|
116
156
|
|
|
117
157
|
/**
|
|
118
|
-
*
|
|
158
|
+
* Returns a setter for a writable atom without subscribing to its value.
|
|
159
|
+
*
|
|
119
160
|
* @category hooks
|
|
161
|
+
* @since 4.0.0
|
|
120
162
|
*/
|
|
121
163
|
export const useAtomSet = <
|
|
122
164
|
R,
|
|
@@ -141,8 +183,10 @@ export const useAtomSet = <
|
|
|
141
183
|
}
|
|
142
184
|
|
|
143
185
|
/**
|
|
144
|
-
*
|
|
186
|
+
* Mounts an atom and returns a callback that refreshes the current atom.
|
|
187
|
+
*
|
|
145
188
|
* @category hooks
|
|
189
|
+
* @since 4.0.0
|
|
146
190
|
*/
|
|
147
191
|
export const useAtomRefresh = <A>(atom: () => Atom.Atom<A>): () => void => {
|
|
148
192
|
const registry = useContext(RegistryContext)
|
|
@@ -152,8 +196,11 @@ export const useAtomRefresh = <A>(atom: () => Atom.Atom<A>): () => void => {
|
|
|
152
196
|
}
|
|
153
197
|
|
|
154
198
|
/**
|
|
155
|
-
*
|
|
199
|
+
* Returns a Solid accessor for a writable atom together with a setter for
|
|
200
|
+
* updating it.
|
|
201
|
+
*
|
|
156
202
|
* @category hooks
|
|
203
|
+
* @since 4.0.0
|
|
157
204
|
*/
|
|
158
205
|
export const useAtom = <R, W, const Mode extends "value" | "promise" | "promiseExit" = never>(
|
|
159
206
|
atom: () => Atom.Writable<R, W>,
|
|
@@ -178,8 +225,10 @@ export const useAtom = <R, W, const Mode extends "value" | "promise" | "promiseE
|
|
|
178
225
|
}
|
|
179
226
|
|
|
180
227
|
/**
|
|
181
|
-
*
|
|
228
|
+
* Subscribes a callback to an atom in the current Solid registry.
|
|
229
|
+
*
|
|
182
230
|
* @category hooks
|
|
231
|
+
* @since 4.0.0
|
|
183
232
|
*/
|
|
184
233
|
export const useAtomSubscribe = <A>(
|
|
185
234
|
atom: () => Atom.Atom<A>,
|
|
@@ -193,8 +242,10 @@ export const useAtomSubscribe = <A>(
|
|
|
193
242
|
}
|
|
194
243
|
|
|
195
244
|
/**
|
|
196
|
-
*
|
|
245
|
+
* Converts an `AsyncResult` atom into a Solid resource.
|
|
246
|
+
*
|
|
197
247
|
* @category hooks
|
|
248
|
+
* @since 4.0.0
|
|
198
249
|
*/
|
|
199
250
|
export const useAtomResource = <A, E>(
|
|
200
251
|
atom: () => Atom.Atom<AsyncResult.AsyncResult<A, E>>,
|
|
@@ -216,8 +267,10 @@ export const useAtomResource = <A, E>(
|
|
|
216
267
|
const constUnresolvedPromise = new Promise<never>(() => {})
|
|
217
268
|
|
|
218
269
|
/**
|
|
219
|
-
*
|
|
270
|
+
* Subscribes to an atom ref and returns its value as a Solid accessor.
|
|
271
|
+
*
|
|
220
272
|
* @category hooks
|
|
273
|
+
* @since 4.0.0
|
|
221
274
|
*/
|
|
222
275
|
export const useAtomRef = <A>(ref: () => AtomRef.ReadonlyRef<A>): Accessor<A> => {
|
|
223
276
|
const [value, setValue] = createSignal(null as A)
|
|
@@ -230,8 +283,10 @@ export const useAtomRef = <A>(ref: () => AtomRef.ReadonlyRef<A>): Accessor<A> =>
|
|
|
230
283
|
}
|
|
231
284
|
|
|
232
285
|
/**
|
|
233
|
-
*
|
|
286
|
+
* Returns a Solid accessor for a property ref derived from an atom ref.
|
|
287
|
+
*
|
|
234
288
|
* @category hooks
|
|
289
|
+
* @since 4.0.0
|
|
235
290
|
*/
|
|
236
291
|
export const useAtomRefProp = <A, K extends keyof A>(
|
|
237
292
|
ref: () => AtomRef.AtomRef<A>,
|
|
@@ -239,8 +294,11 @@ export const useAtomRefProp = <A, K extends keyof A>(
|
|
|
239
294
|
): Accessor<AtomRef.AtomRef<A[K]>> => createMemo(() => ref().prop(prop))
|
|
240
295
|
|
|
241
296
|
/**
|
|
242
|
-
*
|
|
297
|
+
* Returns a Solid accessor for the value of a property ref derived from an atom
|
|
298
|
+
* ref.
|
|
299
|
+
*
|
|
243
300
|
* @category hooks
|
|
301
|
+
* @since 4.0.0
|
|
244
302
|
*/
|
|
245
303
|
export const useAtomRefPropValue = <A, K extends keyof A>(ref: () => AtomRef.AtomRef<A>, prop: K): Accessor<A[K]> =>
|
|
246
304
|
useAtomRef(useAtomRefProp(ref, prop))
|
package/src/RegistryContext.ts
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The `RegistryContext` module provides the Solid context used by Effect Atom
|
|
3
|
+
* hooks to share an `AtomRegistry` across an owner tree. The registry owns atom
|
|
4
|
+
* state, scheduling, and idle cleanup, so Solid components that read or write
|
|
5
|
+
* atoms coordinate through the same runtime instead of creating isolated
|
|
6
|
+
* registries.
|
|
7
|
+
*
|
|
8
|
+
* **Common tasks**
|
|
9
|
+
*
|
|
10
|
+
* - Use {@link RegistryProvider} to scope atom state to a Solid subtree
|
|
11
|
+
* - Seed atoms for tests, examples, 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
|
+
* - The provider creates a registry for the current Solid owner and disposes it
|
|
18
|
+
* with `onCleanup`
|
|
19
|
+
* - `initialValues` are applied when the provider creates the registry, not as
|
|
20
|
+
* reactive updates after creation
|
|
21
|
+
* - Overriding `scheduleTask` changes when atom work is flushed, so it should
|
|
22
|
+
* return a cancellation function that is safe to call during Solid cleanup
|
|
23
|
+
*
|
|
24
|
+
* @since 4.0.0
|
|
3
25
|
*/
|
|
4
26
|
import type * as Atom from "effect/unstable/reactivity/Atom"
|
|
5
27
|
import * as AtomRegistry from "effect/unstable/reactivity/AtomRegistry"
|
|
@@ -7,14 +29,21 @@ import type { JSX } from "solid-js"
|
|
|
7
29
|
import { createComponent, createContext, onCleanup } from "solid-js"
|
|
8
30
|
|
|
9
31
|
/**
|
|
10
|
-
*
|
|
32
|
+
* A Solid context that carries the `AtomRegistry` used by atom hooks in the
|
|
33
|
+
* current owner tree.
|
|
34
|
+
*
|
|
11
35
|
* @category context
|
|
36
|
+
* @since 4.0.0
|
|
12
37
|
*/
|
|
13
38
|
export const RegistryContext = createContext<AtomRegistry.AtomRegistry>(AtomRegistry.make())
|
|
14
39
|
|
|
15
40
|
/**
|
|
16
|
-
*
|
|
41
|
+
* Creates an `AtomRegistry` for a Solid subtree, optionally seeding initial atom
|
|
42
|
+
* values and scheduler settings, and disposes the registry when the owner is
|
|
43
|
+
* cleaned up.
|
|
44
|
+
*
|
|
17
45
|
* @category context
|
|
46
|
+
* @since 4.0.0
|
|
18
47
|
*/
|
|
19
48
|
export const RegistryProvider = (options: {
|
|
20
49
|
readonly children?: JSX.Element | undefined
|