@dxos/effect-atom-solid 0.0.0 → 0.8.4-main.21d9917

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.
Files changed (52) hide show
  1. package/dist/lib/browser/index.mjs +261 -0
  2. package/dist/lib/browser/index.mjs.map +7 -0
  3. package/dist/lib/browser/meta.json +1 -0
  4. package/dist/lib/node-esm/index.mjs +263 -0
  5. package/dist/lib/node-esm/index.mjs.map +7 -0
  6. package/dist/lib/node-esm/meta.json +1 -0
  7. package/dist/types/src/hooks/index.d.ts +11 -0
  8. package/dist/types/src/hooks/index.d.ts.map +1 -0
  9. package/dist/types/src/hooks/useAtom.d.ts +12 -0
  10. package/dist/types/src/hooks/useAtom.d.ts.map +1 -0
  11. package/dist/types/src/hooks/useAtom.test.d.ts +2 -0
  12. package/dist/types/src/hooks/useAtom.test.d.ts.map +1 -0
  13. package/dist/types/src/hooks/useAtomInitialValues.d.ts +6 -0
  14. package/dist/types/src/hooks/useAtomInitialValues.d.ts.map +1 -0
  15. package/dist/types/src/hooks/useAtomInitialValues.test.d.ts +2 -0
  16. package/dist/types/src/hooks/useAtomInitialValues.test.d.ts.map +1 -0
  17. package/dist/types/src/hooks/useAtomMount.d.ts +6 -0
  18. package/dist/types/src/hooks/useAtomMount.d.ts.map +1 -0
  19. package/dist/types/src/hooks/useAtomRef.d.ts +15 -0
  20. package/dist/types/src/hooks/useAtomRef.d.ts.map +1 -0
  21. package/dist/types/src/hooks/useAtomRefresh.d.ts +6 -0
  22. package/dist/types/src/hooks/useAtomRefresh.d.ts.map +1 -0
  23. package/dist/types/src/hooks/useAtomRefresh.test.d.ts +2 -0
  24. package/dist/types/src/hooks/useAtomRefresh.test.d.ts.map +1 -0
  25. package/dist/types/src/hooks/useAtomResource.d.ts +14 -0
  26. package/dist/types/src/hooks/useAtomResource.d.ts.map +1 -0
  27. package/dist/types/src/hooks/useAtomResource.test.d.ts +2 -0
  28. package/dist/types/src/hooks/useAtomResource.test.d.ts.map +1 -0
  29. package/dist/types/src/hooks/useAtomSet.d.ts +16 -0
  30. package/dist/types/src/hooks/useAtomSet.d.ts.map +1 -0
  31. package/dist/types/src/hooks/useAtomSet.test.d.ts +2 -0
  32. package/dist/types/src/hooks/useAtomSet.test.d.ts.map +1 -0
  33. package/dist/types/src/hooks/useAtomSubscribe.d.ts +8 -0
  34. package/dist/types/src/hooks/useAtomSubscribe.d.ts.map +1 -0
  35. package/dist/types/src/hooks/useAtomSubscribe.test.d.ts +2 -0
  36. package/dist/types/src/hooks/useAtomSubscribe.test.d.ts.map +1 -0
  37. package/dist/types/src/hooks/useAtomSuspense.d.ts +7 -0
  38. package/dist/types/src/hooks/useAtomSuspense.d.ts.map +1 -0
  39. package/dist/types/src/hooks/useAtomSuspense.test.d.ts +2 -0
  40. package/dist/types/src/hooks/useAtomSuspense.test.d.ts.map +1 -0
  41. package/dist/types/src/hooks/useAtomValue.d.ts +16 -0
  42. package/dist/types/src/hooks/useAtomValue.d.ts.map +1 -0
  43. package/dist/types/src/hooks/useAtomValue.test.d.ts +2 -0
  44. package/dist/types/src/hooks/useAtomValue.test.d.ts.map +1 -0
  45. package/dist/types/src/index.d.ts +9 -0
  46. package/dist/types/src/index.d.ts.map +1 -0
  47. package/dist/types/src/registry.d.ts +28 -0
  48. package/dist/types/src/registry.d.ts.map +1 -0
  49. package/dist/types/src/registry.test.d.ts +2 -0
  50. package/dist/types/src/registry.test.d.ts.map +1 -0
  51. package/dist/types/tsconfig.tsbuildinfo +1 -0
  52. package/package.json +7 -3
@@ -0,0 +1,261 @@
1
+ // src/index.ts
2
+ import * as Atom from "@effect-atom/atom/Atom";
3
+ import * as Registry3 from "@effect-atom/atom/Registry";
4
+ import * as Result from "@effect-atom/atom/Result";
5
+ import * as AtomRef from "@effect-atom/atom/AtomRef";
6
+ import * as AtomHttpApi from "@effect-atom/atom/AtomHttpApi";
7
+ import * as AtomRpc from "@effect-atom/atom/AtomRpc";
8
+
9
+ // src/hooks/useAtomValue.ts
10
+ import * as AtomModule from "@effect-atom/atom/Atom";
11
+ import { createEffect, createMemo, createSignal, onCleanup as onCleanup2 } from "solid-js";
12
+
13
+ // src/registry.ts
14
+ import * as Registry from "@effect-atom/atom/Registry";
15
+ import * as GlobalValue from "effect/GlobalValue";
16
+ import { createContext, onCleanup, useContext } from "solid-js";
17
+ var defaultRegistry = GlobalValue.globalValue("@effect-atom/atom-solid/defaultRegistry", () => Registry.make());
18
+ var RegistryContext = createContext(defaultRegistry);
19
+ var useRegistry = () => {
20
+ return useContext(RegistryContext);
21
+ };
22
+ function RegistryProvider(props) {
23
+ const registry = props.registry ?? Registry.make({
24
+ scheduleTask: props.scheduleTask,
25
+ initialValues: props.initialValues,
26
+ timeoutResolution: props.timeoutResolution,
27
+ defaultIdleTTL: props.defaultIdleTTL ?? 400
28
+ });
29
+ onCleanup(() => {
30
+ const timeout = setTimeout(() => {
31
+ registry.dispose();
32
+ }, 500);
33
+ return () => clearTimeout(timeout);
34
+ });
35
+ return RegistryContext.Provider({
36
+ value: registry,
37
+ get children() {
38
+ return props.children;
39
+ }
40
+ });
41
+ }
42
+
43
+ // src/hooks/useAtomValue.ts
44
+ var access = (value) => typeof value === "function" ? value() : value;
45
+ function useAtomValue(atom, f) {
46
+ const registry = useRegistry();
47
+ const resolvedAtom = createMemo(() => {
48
+ const a = access(atom);
49
+ return f ? AtomModule.map(a, f) : a;
50
+ });
51
+ const [value, setValue] = createSignal(registry.get(resolvedAtom()));
52
+ createEffect(() => {
53
+ const currentAtom = resolvedAtom();
54
+ setValue(() => registry.get(currentAtom));
55
+ const unsubscribe = registry.subscribe(currentAtom, (nextValue) => {
56
+ setValue(() => nextValue);
57
+ }, {
58
+ immediate: true
59
+ });
60
+ onCleanup2(unsubscribe);
61
+ });
62
+ return value;
63
+ }
64
+
65
+ // src/hooks/useAtomSet.ts
66
+ import * as Registry2 from "@effect-atom/atom/Registry";
67
+ import * as Cause from "effect/Cause";
68
+ import * as Effect from "effect/Effect";
69
+ import * as Exit from "effect/Exit";
70
+ import { onCleanup as onCleanup3 } from "solid-js";
71
+ var flattenExit = (exit) => {
72
+ if (Exit.isSuccess(exit)) return exit.value;
73
+ throw Cause.squash(exit.cause);
74
+ };
75
+ function createSetAtom(registry, atom, options) {
76
+ if (options?.mode === "promise" || options?.mode === "promiseExit") {
77
+ return (value) => {
78
+ registry.set(atom, value);
79
+ const promise = Effect.runPromiseExit(Registry2.getResult(registry, atom, {
80
+ suspendOnWaiting: true
81
+ }));
82
+ return options.mode === "promise" ? promise.then(flattenExit) : promise;
83
+ };
84
+ }
85
+ return (value) => {
86
+ registry.set(atom, typeof value === "function" ? value(registry.get(atom)) : value);
87
+ };
88
+ }
89
+ function useAtomSet(atom, options) {
90
+ const registry = useRegistry();
91
+ const unmount = registry.mount(atom);
92
+ onCleanup3(unmount);
93
+ return createSetAtom(registry, atom, options);
94
+ }
95
+
96
+ // src/hooks/useAtom.ts
97
+ import { createSignal as createSignal2, onCleanup as onCleanup4 } from "solid-js";
98
+ function useAtom(atom, options) {
99
+ const registry = useRegistry();
100
+ const [value, setValue] = createSignal2(registry.get(atom));
101
+ const unsubscribe = registry.subscribe(atom, (nextValue) => {
102
+ setValue(() => nextValue);
103
+ }, {
104
+ immediate: true
105
+ });
106
+ onCleanup4(unsubscribe);
107
+ return [
108
+ value,
109
+ createSetAtom(registry, atom, options)
110
+ ];
111
+ }
112
+
113
+ // src/hooks/useAtomMount.ts
114
+ import { onCleanup as onCleanup5 } from "solid-js";
115
+ function useAtomMount(atom) {
116
+ const registry = useRegistry();
117
+ const unmount = registry.mount(atom);
118
+ onCleanup5(unmount);
119
+ }
120
+
121
+ // src/hooks/useAtomRefresh.ts
122
+ import { onCleanup as onCleanup6 } from "solid-js";
123
+ function useAtomRefresh(atom) {
124
+ const registry = useRegistry();
125
+ const unmount = registry.mount(atom);
126
+ onCleanup6(unmount);
127
+ return () => registry.refresh(atom);
128
+ }
129
+
130
+ // src/hooks/useAtomSubscribe.ts
131
+ import { onCleanup as onCleanup7 } from "solid-js";
132
+ function useAtomSubscribe(atom, f, options) {
133
+ const registry = useRegistry();
134
+ const unsubscribe = registry.subscribe(atom, f, options);
135
+ onCleanup7(unsubscribe);
136
+ }
137
+
138
+ // src/hooks/useAtomRef.ts
139
+ import { createMemo as createMemo2, createSignal as createSignal3, onCleanup as onCleanup8 } from "solid-js";
140
+ function useAtomRef(ref) {
141
+ const [value, setValue] = createSignal3(ref.value);
142
+ const unsubscribe = ref.subscribe((next) => {
143
+ setValue(() => next);
144
+ });
145
+ onCleanup8(unsubscribe);
146
+ return value;
147
+ }
148
+ function useAtomRefProp(ref, prop) {
149
+ return createMemo2(() => ref.prop(prop))();
150
+ }
151
+ function useAtomRefPropValue(ref, prop) {
152
+ return useAtomRef(useAtomRefProp(ref, prop));
153
+ }
154
+
155
+ // src/hooks/useAtomResource.ts
156
+ import * as Cause2 from "effect/Cause";
157
+ import { createMemo as createMemo3, createSignal as createSignal4, onCleanup as onCleanup9 } from "solid-js";
158
+ function useAtomResource(atom) {
159
+ const registry = useRegistry();
160
+ const [result, setResult] = createSignal4(registry.get(atom));
161
+ const unsubscribe = registry.subscribe(atom, (nextValue) => {
162
+ setResult(() => nextValue);
163
+ }, {
164
+ immediate: true
165
+ });
166
+ onCleanup9(unsubscribe);
167
+ const value = createMemo3(() => {
168
+ const r = result();
169
+ return r._tag === "Success" ? r.value : void 0;
170
+ });
171
+ const error = createMemo3(() => {
172
+ const r = result();
173
+ return r._tag === "Failure" ? Cause2.squash(r.cause) : void 0;
174
+ });
175
+ const loading = createMemo3(() => {
176
+ const r = result();
177
+ return r._tag === "Initial" || r.waiting;
178
+ });
179
+ return {
180
+ value,
181
+ error,
182
+ loading,
183
+ result
184
+ };
185
+ }
186
+
187
+ // src/hooks/useAtomSuspense.ts
188
+ import { createResource, onCleanup as onCleanup10 } from "solid-js";
189
+ function useAtomSuspense(atom) {
190
+ const registry = useRegistry();
191
+ const [data, { mutate, refetch }] = createResource(async () => {
192
+ const current = registry.get(atom);
193
+ if (current._tag === "Success") {
194
+ return current.value;
195
+ }
196
+ if (current._tag === "Failure") {
197
+ throw current.cause;
198
+ }
199
+ return new Promise((resolve, reject) => {
200
+ const unsubscribe2 = registry.subscribe(atom, (next) => {
201
+ if (next._tag === "Success") {
202
+ unsubscribe2();
203
+ resolve(next.value);
204
+ } else if (next._tag === "Failure") {
205
+ unsubscribe2();
206
+ reject(next.cause);
207
+ }
208
+ });
209
+ });
210
+ });
211
+ const unsubscribe = registry.subscribe(atom, (next) => {
212
+ if (next._tag === "Success") {
213
+ mutate(() => next.value);
214
+ } else if (next._tag === "Failure") {
215
+ void refetch();
216
+ } else if (next._tag === "Initial" || next.waiting) {
217
+ void refetch();
218
+ }
219
+ });
220
+ onCleanup10(unsubscribe);
221
+ return () => {
222
+ const value = data();
223
+ if (value === void 0) {
224
+ }
225
+ return value;
226
+ };
227
+ }
228
+
229
+ // src/hooks/useAtomInitialValues.ts
230
+ function useAtomInitialValues(initialValues) {
231
+ const registry = useRegistry();
232
+ for (const [atom, value] of initialValues) {
233
+ registry.set(atom, value);
234
+ }
235
+ }
236
+ export {
237
+ Atom,
238
+ AtomHttpApi,
239
+ AtomRef,
240
+ AtomRpc,
241
+ Registry3 as Registry,
242
+ RegistryContext,
243
+ RegistryProvider,
244
+ Result,
245
+ createSetAtom,
246
+ defaultRegistry,
247
+ useAtom,
248
+ useAtomInitialValues,
249
+ useAtomMount,
250
+ useAtomRef,
251
+ useAtomRefProp,
252
+ useAtomRefPropValue,
253
+ useAtomRefresh,
254
+ useAtomResource,
255
+ useAtomSet,
256
+ useAtomSubscribe,
257
+ useAtomSuspense,
258
+ useAtomValue,
259
+ useRegistry
260
+ };
261
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/index.ts", "../../../src/hooks/useAtomValue.ts", "../../../src/registry.ts", "../../../src/hooks/useAtomSet.ts", "../../../src/hooks/useAtom.ts", "../../../src/hooks/useAtomMount.ts", "../../../src/hooks/useAtomRefresh.ts", "../../../src/hooks/useAtomSubscribe.ts", "../../../src/hooks/useAtomRef.ts", "../../../src/hooks/useAtomResource.ts", "../../../src/hooks/useAtomSuspense.ts", "../../../src/hooks/useAtomInitialValues.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport * as Atom from '@effect-atom/atom/Atom';\nexport * as Registry from '@effect-atom/atom/Registry';\nexport * as Result from '@effect-atom/atom/Result';\nexport * as AtomRef from '@effect-atom/atom/AtomRef';\nexport * as AtomHttpApi from '@effect-atom/atom/AtomHttpApi';\nexport * as AtomRpc from '@effect-atom/atom/AtomRpc';\n\nexport * from './hooks';\nexport * from './registry';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Atom from '@effect-atom/atom/Atom';\nimport * as AtomModule from '@effect-atom/atom/Atom';\nimport { type Accessor, createEffect, createMemo, createSignal, onCleanup } from 'solid-js';\n\nimport { useRegistry } from '../registry';\n\n/**\n * A value that may be a static value or a reactive accessor.\n */\ntype MaybeAccessor<T> = T | Accessor<T>;\n\n/**\n * Resolves a MaybeAccessor to its value.\n */\nconst access = <T>(value: MaybeAccessor<T>): T => (typeof value === 'function' ? (value as Accessor<T>)() : value);\n\n/**\n * Hook to read the value of an atom.\n * The returned accessor will update whenever the atom's value changes.\n * The atom parameter can be reactive (MaybeAccessor) - if the atom changes,\n * the hook will automatically unsubscribe from the old atom and subscribe to the new one.\n */\nexport function useAtomValue<A>(atom: MaybeAccessor<Atom.Atom<A>>): Accessor<A>;\nexport function useAtomValue<A, B>(atom: MaybeAccessor<Atom.Atom<A>>, f: (a: A) => B): Accessor<B>;\nexport function useAtomValue<A>(atom: MaybeAccessor<Atom.Atom<A>>, f?: (a: A) => A): Accessor<A> {\n const registry = useRegistry();\n\n // Resolve the atom reactively and apply mapping if provided.\n const resolvedAtom = createMemo(() => {\n const a = access(atom);\n return f ? AtomModule.map(a, f) : a;\n });\n\n const [value, setValue] = createSignal<A>(registry.get(resolvedAtom()));\n\n // Subscribe to atom changes reactively - re-subscribes when atom changes.\n createEffect(() => {\n const currentAtom = resolvedAtom();\n setValue(() => registry.get(currentAtom));\n\n const unsubscribe = registry.subscribe(\n currentAtom,\n (nextValue) => {\n setValue(() => nextValue);\n },\n { immediate: true },\n );\n\n onCleanup(unsubscribe);\n });\n\n return value;\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Atom from '@effect-atom/atom/Atom';\nimport * as Registry from '@effect-atom/atom/Registry';\nimport * as GlobalValue from 'effect/GlobalValue';\nimport { type Context, createContext, onCleanup, useContext } from 'solid-js';\n\n/**\n * Default registry instance\n */\nexport const defaultRegistry: Registry.Registry = GlobalValue.globalValue(\n '@effect-atom/atom-solid/defaultRegistry',\n () => Registry.make(),\n);\n\n/**\n * Solid context for the atom registry\n */\nexport const RegistryContext: Context<Registry.Registry> = createContext<Registry.Registry>(defaultRegistry);\n\n/**\n * Get the current registry from context\n */\nexport const useRegistry = (): Registry.Registry => {\n return useContext(RegistryContext);\n};\n\n/**\n * Provider component for custom registry\n */\nexport interface RegistryProviderProps {\n children: any;\n registry?: Registry.Registry;\n initialValues?: Iterable<readonly [Atom.Atom<any>, any]>;\n scheduleTask?: (f: () => void) => void;\n timeoutResolution?: number;\n defaultIdleTTL?: number;\n}\n\nexport function RegistryProvider(props: RegistryProviderProps) {\n const registry =\n props.registry ??\n Registry.make({\n scheduleTask: props.scheduleTask,\n initialValues: props.initialValues,\n timeoutResolution: props.timeoutResolution,\n defaultIdleTTL: props.defaultIdleTTL ?? 400,\n });\n\n onCleanup(() => {\n // Delay disposal to allow for component re-mounting\n const timeout = setTimeout(() => {\n registry.dispose();\n }, 500);\n return () => clearTimeout(timeout);\n });\n\n return RegistryContext.Provider({\n value: registry,\n get children() {\n return props.children;\n },\n });\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Atom from '@effect-atom/atom/Atom';\nimport * as Registry from '@effect-atom/atom/Registry';\nimport type * as Result from '@effect-atom/atom/Result';\nimport * as Cause from 'effect/Cause';\nimport * as Effect from 'effect/Effect';\nimport * as Exit from 'effect/Exit';\nimport { onCleanup } from 'solid-js';\n\nimport { useRegistry } from '../registry';\n\nconst flattenExit = <A, E>(exit: Exit.Exit<A, E>): A => {\n if (Exit.isSuccess(exit)) return exit.value;\n throw Cause.squash(exit.cause);\n};\n\nexport type SetAtomFn<R, W, Mode extends 'value' | 'promise' | 'promiseExit'> = 'promise' extends Mode\n ? (value: W) => Promise<Result.Result.Success<R>>\n : 'promiseExit' extends Mode\n ? (value: W) => Promise<Exit.Exit<Result.Result.Success<R>, Result.Result.Failure<R>>>\n : (value: W | ((value: R) => W)) => void;\n\nexport function createSetAtom<R, W, Mode extends 'value' | 'promise' | 'promiseExit' = never>(\n registry: Registry.Registry,\n atom: Atom.Writable<R, W>,\n options?: {\n readonly mode?: ([R] extends [Result.Result<any, any>] ? Mode : 'value') | undefined;\n },\n): SetAtomFn<R, W, Mode> {\n if (options?.mode === 'promise' || options?.mode === 'promiseExit') {\n return ((value: W) => {\n registry.set(atom, value);\n const promise = Effect.runPromiseExit(\n Registry.getResult(registry, atom as Atom.Atom<Result.Result<any, any>>, { suspendOnWaiting: true }),\n );\n return options!.mode === 'promise' ? promise.then(flattenExit) : promise;\n }) as SetAtomFn<R, W, Mode>;\n }\n return ((value: W | ((value: R) => W)) => {\n registry.set(atom, typeof value === 'function' ? (value as any)(registry.get(atom)) : value);\n }) as SetAtomFn<R, W, Mode>;\n}\n\n/**\n * Hook to get a setter function for an atom\n * Also mounts the atom in the registry\n */\nexport function useAtomSet<R, W, Mode extends 'value' | 'promise' | 'promiseExit' = never>(\n atom: Atom.Writable<R, W>,\n options?: {\n readonly mode?: ([R] extends [Result.Result<any, any>] ? Mode : 'value') | undefined;\n },\n): SetAtomFn<R, W, Mode> {\n const registry = useRegistry();\n\n // Mount the atom\n const unmount = registry.mount(atom);\n onCleanup(unmount);\n\n return createSetAtom(registry, atom, options);\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Atom from '@effect-atom/atom/Atom';\nimport type * as Result from '@effect-atom/atom/Result';\nimport { type Accessor, createSignal, onCleanup } from 'solid-js';\n\nimport { useRegistry } from '../registry';\n\nimport { type SetAtomFn, createSetAtom } from './useAtomSet';\n\n/**\n * Hook to both read and write an atom\n * Returns a tuple of [value accessor, setter function]\n */\nexport function useAtom<R, W, Mode extends 'value' | 'promise' | 'promiseExit' = never>(\n atom: Atom.Writable<R, W>,\n options?: {\n readonly mode?: ([R] extends [Result.Result<any, any>] ? Mode : 'value') | undefined;\n },\n): readonly [Accessor<R>, SetAtomFn<R, W, Mode>] {\n const registry = useRegistry();\n\n const [value, setValue] = createSignal<R>(registry.get(atom));\n\n // Subscribe to atom changes\n const unsubscribe = registry.subscribe(\n atom,\n (nextValue) => {\n setValue(() => nextValue);\n },\n { immediate: true },\n );\n\n onCleanup(unsubscribe);\n\n return [value, createSetAtom(registry, atom, options)] as const;\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Atom from '@effect-atom/atom/Atom';\nimport { onCleanup } from 'solid-js';\n\nimport { useRegistry } from '../registry';\n\n/**\n * Hook to mount an atom without reading its value\n */\nexport function useAtomMount<A>(atom: Atom.Atom<A>): void {\n const registry = useRegistry();\n const unmount = registry.mount(atom);\n onCleanup(unmount);\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Atom from '@effect-atom/atom/Atom';\nimport { onCleanup } from 'solid-js';\n\nimport { useRegistry } from '../registry';\n\n/**\n * Hook to get a refresh function for an atom\n */\nexport function useAtomRefresh<A>(atom: Atom.Atom<A>): () => void {\n const registry = useRegistry();\n\n const unmount = registry.mount(atom);\n onCleanup(unmount);\n\n return () => registry.refresh(atom);\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Atom from '@effect-atom/atom/Atom';\nimport { onCleanup } from 'solid-js';\n\nimport { useRegistry } from '../registry';\n\n/**\n * Hook to subscribe to atom changes with a callback\n */\nexport function useAtomSubscribe<A>(\n atom: Atom.Atom<A>,\n f: (value: A) => void,\n options?: { readonly immediate?: boolean },\n): void {\n const registry = useRegistry();\n\n const unsubscribe = registry.subscribe(atom, f, options);\n onCleanup(unsubscribe);\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as AtomRef from '@effect-atom/atom/AtomRef';\nimport { type Accessor, createMemo, createSignal, onCleanup } from 'solid-js';\n\n/**\n * Hook to read an AtomRef value\n */\nexport function useAtomRef<A>(ref: AtomRef.ReadonlyRef<A>): Accessor<A> {\n const [value, setValue] = createSignal<A>(ref.value);\n\n const unsubscribe = ref.subscribe((next) => {\n setValue(() => next);\n });\n\n onCleanup(unsubscribe);\n\n return value;\n}\n\n/**\n * Hook to get a prop accessor from an AtomRef\n */\nexport function useAtomRefProp<A, K extends keyof A>(ref: AtomRef.AtomRef<A>, prop: K): AtomRef.AtomRef<A[K]> {\n return createMemo(() => ref.prop(prop))();\n}\n\n/**\n * Hook to read a prop value from an AtomRef\n */\nexport function useAtomRefPropValue<A, K extends keyof A>(ref: AtomRef.AtomRef<A>, prop: K): Accessor<A[K]> {\n return useAtomRef(useAtomRefProp(ref, prop));\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Atom from '@effect-atom/atom/Atom';\nimport type * as Result from '@effect-atom/atom/Result';\nimport * as Cause from 'effect/Cause';\nimport { type Accessor, createMemo, createSignal, onCleanup } from 'solid-js';\n\nimport { useRegistry } from '../registry';\n\n/**\n * Resource-like hook for atoms that contain Result values\n * Automatically handles loading and error states\n */\nexport function useAtomResource<A, E>(\n atom: Atom.Atom<Result.Result<A, E>>,\n): {\n value: Accessor<A | undefined>;\n error: Accessor<E | undefined>;\n loading: Accessor<boolean>;\n result: Accessor<Result.Result<A, E>>;\n} {\n const registry = useRegistry();\n const [result, setResult] = createSignal<Result.Result<A, E>>(registry.get(atom));\n\n const unsubscribe = registry.subscribe(\n atom,\n (nextValue) => {\n setResult(() => nextValue);\n },\n { immediate: true },\n );\n\n onCleanup(unsubscribe);\n\n const value = createMemo(() => {\n const r = result();\n return r._tag === 'Success' ? r.value : undefined;\n });\n\n const error = createMemo(() => {\n const r = result();\n return r._tag === 'Failure' ? (Cause.squash(r.cause) as E) : undefined;\n });\n\n const loading = createMemo(() => {\n const r = result();\n return r._tag === 'Initial' || r.waiting;\n });\n\n return {\n value,\n error,\n loading,\n result,\n };\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Atom from '@effect-atom/atom/Atom';\nimport type * as Result from '@effect-atom/atom/Result';\nimport { createResource, onCleanup } from 'solid-js';\n\nimport { useRegistry } from '../registry';\n\n/**\n * Hook to read an atom value with Suspense support\n */\nexport function useAtomSuspense<A, E>(atom: Atom.Atom<Result.Result<A, E>>): () => A {\n const registry = useRegistry();\n\n const [data, { mutate, refetch }] = createResource(async () => {\n // Check if we already have a value\n const current = registry.get(atom);\n if (current._tag === 'Success') {\n return current.value;\n }\n if (current._tag === 'Failure') {\n throw current.cause;\n }\n\n // Wait for the next success or failure\n return new Promise<A>((resolve, reject) => {\n const unsubscribe = registry.subscribe(atom, (next) => {\n if (next._tag === 'Success') {\n unsubscribe();\n resolve(next.value);\n } else if (next._tag === 'Failure') {\n unsubscribe();\n reject(next.cause);\n }\n });\n // Note: We might want to handle cancellation if the resource is disposed?\n // But creating a promise that leaks isn't great.\n // Ideally we tie this to the component, but the promise itself is localized.\n });\n });\n\n // Subscribe to updates to keep the resource fresh\n const unsubscribe = registry.subscribe(atom, (next) => {\n if (next._tag === 'Success') {\n mutate(() => next.value);\n } else if (next._tag === 'Failure') {\n // If we encounter a failure, we trigger a refetch which will hit the fetcher\n // and throw the error (reject the promise)\n // Or we could try to mutate error state?\n // createResource doesn't have a direct 'setError'.\n // Refetching is the safe bet to re-enter the promise/error flow.\n void refetch();\n } else if (next._tag === 'Initial' || (next as any).waiting) {\n // If we go back to loading, refetch to suspend\n void refetch();\n }\n });\n\n onCleanup(unsubscribe);\n\n return () => {\n const value = data();\n if (value === undefined) {\n // This case handles when the resource is loading initially\n // createResource reads undefined (or initial value) when loading if strict mode isn't on for types,\n // but wrapping it ensures we signal \"read\" to Suspense.\n // However, data() itself should trigger Suspense if loading.\n // We assume standard Suspense behavior.\n }\n return value as A;\n };\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Atom from '@effect-atom/atom/Atom';\n\nimport { useRegistry } from '../registry';\n\n/**\n * Hook to initialize atoms with values\n */\nexport function useAtomInitialValues(initialValues: Iterable<readonly [Atom.Writable<any, any>, any]>): void {\n const registry = useRegistry();\n\n for (const [atom, value] of initialValues) {\n registry.set(atom, value);\n }\n}\n"],
5
+ "mappings": ";AAIA,YAAYA,UAAU;AACtB,YAAYC,eAAc;AAC1B,YAAYC,YAAY;AACxB,YAAYC,aAAa;AACzB,YAAYC,iBAAiB;AAC7B,YAAYC,aAAa;;;ACJzB,YAAYC,gBAAgB;AAC5B,SAAwBC,cAAcC,YAAYC,cAAcC,aAAAA,kBAAiB;;;ACDjF,YAAYC,cAAc;AAC1B,YAAYC,iBAAiB;AAC7B,SAAuBC,eAAeC,WAAWC,kBAAkB;AAK5D,IAAMC,kBAAiDC,wBAC5D,2CACA,MAAeC,cAAI,CAAA;AAMd,IAAMC,kBAA8CC,cAAiCJ,eAAAA;AAKrF,IAAMK,cAAc,MAAA;AACzB,SAAOC,WAAWH,eAAAA;AACpB;AAcO,SAASI,iBAAiBC,OAA4B;AAC3D,QAAMC,WACJD,MAAMC,YACGP,cAAK;IACZQ,cAAcF,MAAME;IACpBC,eAAeH,MAAMG;IACrBC,mBAAmBJ,MAAMI;IACzBC,gBAAgBL,MAAMK,kBAAkB;EAC1C,CAAA;AAEFC,YAAU,MAAA;AAER,UAAMC,UAAUC,WAAW,MAAA;AACzBP,eAASQ,QAAO;IAClB,GAAG,GAAA;AACH,WAAO,MAAMC,aAAaH,OAAAA;EAC5B,CAAA;AAEA,SAAOZ,gBAAgBgB,SA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AIF,MAAMC,KAAAA;EACrB;AACF;",
6
+ "names": ["Atom", "Registry", "Result", "AtomRef", "AtomHttpApi", "AtomRpc", "AtomModule", "createEffect", "createMemo", "createSignal", "onCleanup", "Registry", "GlobalValue", "createContext", "onCleanup", "useContext", "defaultRegistry", "globalValue", "make", "RegistryContext", "createContext", "useRegistry", "useContext", "RegistryProvider", "props", "registry", "scheduleTask", "initialValues", "timeoutResolution", "defaultIdleTTL", "onCleanup", "timeout", "setTimeout", "dispose", "clearTimeout", "Provider", "value", "children", "access", "value", "useAtomValue", "atom", "f", "registry", "useRegistry", "resolvedAtom", "createMemo", "a", "map", "setValue", "createSignal", "get", "createEffect", "currentAtom", "unsubscribe", "subscribe", "nextValue", "immediate", "onCleanup", "Registry", "Cause", "Effect", "Exit", "onCleanup", "flattenExit", "exit", "isSuccess", "value", "squash", "cause", "createSetAtom", "registry", "atom", "options", "mode", "set", "promise", "runPromiseExit", "getResult", "suspendOnWaiting", "then", "get", "useAtomSet", "useRegistry", "unmount", "mount", "onCleanup", "createSignal", "onCleanup", "useAtom", "atom", "options", "registry", "useRegistry", "value", "setValue", "createSignal", "get", "unsubscribe", "subscribe", "nextValue", "immediate", "onCleanup", "createSetAtom", "onCleanup", "useAtomMount", "atom", "registry", "useRegistry", "unmount", "mount", "onCleanup", "onCleanup", "useAtomRefresh", "atom", "registry", "useRegistry", "unmount", "mount", "onCleanup", "refresh", "onCleanup", "useAtomSubscribe", "atom", "f", "options", "registry", "useRegistry", "unsubscribe", "subscribe", "onCleanup", "createMemo", "createSignal", "onCleanup", "useAtomRef", "ref", "value", "setValue", "createSignal", "unsubscribe", "subscribe", "next", "onCleanup", "useAtomRefProp", "prop", "createMemo", "useAtomRefPropValue", "Cause", "createMemo", "createSignal", "onCleanup", "useAtomResource", "atom", "registry", "useRegistry", "result", "setResult", "createSignal", "get", "unsubscribe", "subscribe", "nextValue", "immediate", "onCleanup", "value", "createMemo", "r", "_tag", "undefined", "error", "squash", "cause", "loading", "waiting", "createResource", "onCleanup", "useAtomSuspense", "atom", "registry", "useRegistry", "data", "mutate", "refetch", "createResource", "current", "get", "_tag", "value", "cause", "Promise", "resolve", "reject", "unsubscribe", "subscribe", "next", "waiting", "onCleanup", "undefined", "useAtomInitialValues", "initialValues", "registry", "useRegistry", "atom", "value", "set"]
7
+ }
@@ -0,0 +1 @@
1
+ {"inputs":{"src/registry.ts":{"bytes":5259,"imports":[{"path":"@effect-atom/atom/Registry","kind":"import-statement","external":true},{"path":"effect/GlobalValue","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true}],"format":"esm"},"src/hooks/useAtomValue.ts":{"bytes":5052,"imports":[{"path":"@effect-atom/atom/Atom","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"src/registry.ts","kind":"import-statement","original":"../registry"}],"format":"esm"},"src/hooks/useAtomSet.ts":{"bytes":6190,"imports":[{"path":"@effect-atom/atom/Registry","kind":"import-statement","external":true},{"path":"effect/Cause","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Exit","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"src/registry.ts","kind":"import-statement","original":"../registry"}],"format":"esm"},"src/hooks/useAtom.ts":{"bytes":3228,"imports":[{"path":"solid-js","kind":"import-statement","external":true},{"path":"src/registry.ts","kind":"import-statement","original":"../registry"},{"path":"src/hooks/useAtomSet.ts","kind":"import-statement","original":"./useAtomSet"}],"format":"esm"},"src/hooks/useAtomMount.ts":{"bytes":1486,"imports":[{"path":"solid-js","kind":"import-statement","external":true},{"path":"src/registry.ts","kind":"import-statement","original":"../registry"}],"format":"esm"},"src/hooks/useAtomRefresh.ts":{"bytes":1652,"imports":[{"path":"solid-js","kind":"import-statement","external":true},{"path":"src/registry.ts","kind":"import-statement","original":"../registry"}],"format":"esm"},"src/hooks/useAtomSubscribe.ts":{"bytes":1772,"imports":[{"path":"solid-js","kind":"import-statement","external":true},{"path":"src/registry.ts","kind":"import-statement","original":"../registry"}],"format":"esm"},"src/hooks/useAtomRef.ts":{"bytes":2981,"imports":[{"path":"solid-js","kind":"import-statement","external":true}],"format":"esm"},"src/hooks/useAtomResource.ts":{"bytes":4553,"imports":[{"path":"effect/Cause","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"src/registry.ts","kind":"import-statement","original":"../registry"}],"format":"esm"},"src/hooks/useAtomSuspense.ts":{"bytes":8172,"imports":[{"path":"solid-js","kind":"import-statement","external":true},{"path":"src/registry.ts","kind":"import-statement","original":"../registry"}],"format":"esm"},"src/hooks/useAtomInitialValues.ts":{"bytes":1549,"imports":[{"path":"src/registry.ts","kind":"import-statement","original":"../registry"}],"format":"esm"},"src/hooks/index.ts":{"bytes":1397,"imports":[{"path":"src/hooks/useAtomValue.ts","kind":"import-statement","original":"./useAtomValue"},{"path":"src/hooks/useAtomSet.ts","kind":"import-statement","original":"./useAtomSet"},{"path":"src/hooks/useAtom.ts","kind":"import-statement","original":"./useAtom"},{"path":"src/hooks/useAtomMount.ts","kind":"import-statement","original":"./useAtomMount"},{"path":"src/hooks/useAtomRefresh.ts","kind":"import-statement","original":"./useAtomRefresh"},{"path":"src/hooks/useAtomSubscribe.ts","kind":"import-statement","original":"./useAtomSubscribe"},{"path":"src/hooks/useAtomRef.ts","kind":"import-statement","original":"./useAtomRef"},{"path":"src/hooks/useAtomResource.ts","kind":"import-statement","original":"./useAtomResource"},{"path":"src/hooks/useAtomSuspense.ts","kind":"import-statement","original":"./useAtomSuspense"},{"path":"src/hooks/useAtomInitialValues.ts","kind":"import-statement","original":"./useAtomInitialValues"}],"format":"esm"},"src/index.ts":{"bytes":1667,"imports":[{"path":"@effect-atom/atom/Atom","kind":"import-statement","external":true},{"path":"@effect-atom/atom/Registry","kind":"import-statement","external":true},{"path":"@effect-atom/atom/Result","kind":"import-statement","external":true},{"path":"@effect-atom/atom/AtomRef","kind":"import-statement","external":true},{"path":"@effect-atom/atom/AtomHttpApi","kind":"import-statement","external":true},{"path":"@effect-atom/atom/AtomRpc","kind":"import-statement","external":true},{"path":"src/hooks/index.ts","kind":"import-statement","original":"./hooks"},{"path":"src/registry.ts","kind":"import-statement","original":"./registry"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":22360},"dist/lib/browser/index.mjs":{"imports":[{"path":"@effect-atom/atom/Atom","kind":"import-statement","external":true},{"path":"@effect-atom/atom/Registry","kind":"import-statement","external":true},{"path":"@effect-atom/atom/Result","kind":"import-statement","external":true},{"path":"@effect-atom/atom/AtomRef","kind":"import-statement","external":true},{"path":"@effect-atom/atom/AtomHttpApi","kind":"import-statement","external":true},{"path":"@effect-atom/atom/AtomRpc","kind":"import-statement","external":true},{"path":"@effect-atom/atom/Atom","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"@effect-atom/atom/Registry","kind":"import-statement","external":true},{"path":"effect/GlobalValue","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"@effect-atom/atom/Registry","kind":"import-statement","external":true},{"path":"effect/Cause","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Exit","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"effect/Cause","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true},{"path":"solid-js","kind":"import-statement","external":true}],"exports":["Atom","AtomHttpApi","AtomRef","AtomRpc","Registry","RegistryContext","RegistryProvider","Result","createSetAtom","defaultRegistry","useAtom","useAtomInitialValues","useAtomMount","useAtomRef","useAtomRefProp","useAtomRefPropValue","useAtomRefresh","useAtomResource","useAtomSet","useAtomSubscribe","useAtomSuspense","useAtomValue","useRegistry"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":327},"src/hooks/useAtomValue.ts":{"bytesInOutput":781},"src/registry.ts":{"bytesInOutput":939},"src/hooks/index.ts":{"bytesInOutput":0},"src/hooks/useAtomSet.ts":{"bytesInOutput":1036},"src/hooks/useAtom.ts":{"bytesInOutput":441},"src/hooks/useAtomMount.ts":{"bytesInOutput":181},"src/hooks/useAtomRefresh.ts":{"bytesInOutput":222},"src/hooks/useAtomSubscribe.ts":{"bytesInOutput":221},"src/hooks/useAtomRef.ts":{"bytesInOutput":493},"src/hooks/useAtomResource.ts":{"bytesInOutput":867},"src/hooks/useAtomSuspense.ts":{"bytesInOutput":1140},"src/hooks/useAtomInitialValues.ts":{"bytesInOutput":165}},"bytes":7618}}}
@@ -0,0 +1,263 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+
3
+ // src/index.ts
4
+ import * as Atom from "@effect-atom/atom/Atom";
5
+ import * as Registry3 from "@effect-atom/atom/Registry";
6
+ import * as Result from "@effect-atom/atom/Result";
7
+ import * as AtomRef from "@effect-atom/atom/AtomRef";
8
+ import * as AtomHttpApi from "@effect-atom/atom/AtomHttpApi";
9
+ import * as AtomRpc from "@effect-atom/atom/AtomRpc";
10
+
11
+ // src/hooks/useAtomValue.ts
12
+ import * as AtomModule from "@effect-atom/atom/Atom";
13
+ import { createEffect, createMemo, createSignal, onCleanup as onCleanup2 } from "solid-js";
14
+
15
+ // src/registry.ts
16
+ import * as Registry from "@effect-atom/atom/Registry";
17
+ import * as GlobalValue from "effect/GlobalValue";
18
+ import { createContext, onCleanup, useContext } from "solid-js";
19
+ var defaultRegistry = GlobalValue.globalValue("@effect-atom/atom-solid/defaultRegistry", () => Registry.make());
20
+ var RegistryContext = createContext(defaultRegistry);
21
+ var useRegistry = () => {
22
+ return useContext(RegistryContext);
23
+ };
24
+ function RegistryProvider(props) {
25
+ const registry = props.registry ?? Registry.make({
26
+ scheduleTask: props.scheduleTask,
27
+ initialValues: props.initialValues,
28
+ timeoutResolution: props.timeoutResolution,
29
+ defaultIdleTTL: props.defaultIdleTTL ?? 400
30
+ });
31
+ onCleanup(() => {
32
+ const timeout = setTimeout(() => {
33
+ registry.dispose();
34
+ }, 500);
35
+ return () => clearTimeout(timeout);
36
+ });
37
+ return RegistryContext.Provider({
38
+ value: registry,
39
+ get children() {
40
+ return props.children;
41
+ }
42
+ });
43
+ }
44
+
45
+ // src/hooks/useAtomValue.ts
46
+ var access = (value) => typeof value === "function" ? value() : value;
47
+ function useAtomValue(atom, f) {
48
+ const registry = useRegistry();
49
+ const resolvedAtom = createMemo(() => {
50
+ const a = access(atom);
51
+ return f ? AtomModule.map(a, f) : a;
52
+ });
53
+ const [value, setValue] = createSignal(registry.get(resolvedAtom()));
54
+ createEffect(() => {
55
+ const currentAtom = resolvedAtom();
56
+ setValue(() => registry.get(currentAtom));
57
+ const unsubscribe = registry.subscribe(currentAtom, (nextValue) => {
58
+ setValue(() => nextValue);
59
+ }, {
60
+ immediate: true
61
+ });
62
+ onCleanup2(unsubscribe);
63
+ });
64
+ return value;
65
+ }
66
+
67
+ // src/hooks/useAtomSet.ts
68
+ import * as Registry2 from "@effect-atom/atom/Registry";
69
+ import * as Cause from "effect/Cause";
70
+ import * as Effect from "effect/Effect";
71
+ import * as Exit from "effect/Exit";
72
+ import { onCleanup as onCleanup3 } from "solid-js";
73
+ var flattenExit = (exit) => {
74
+ if (Exit.isSuccess(exit)) return exit.value;
75
+ throw Cause.squash(exit.cause);
76
+ };
77
+ function createSetAtom(registry, atom, options) {
78
+ if (options?.mode === "promise" || options?.mode === "promiseExit") {
79
+ return (value) => {
80
+ registry.set(atom, value);
81
+ const promise = Effect.runPromiseExit(Registry2.getResult(registry, atom, {
82
+ suspendOnWaiting: true
83
+ }));
84
+ return options.mode === "promise" ? promise.then(flattenExit) : promise;
85
+ };
86
+ }
87
+ return (value) => {
88
+ registry.set(atom, typeof value === "function" ? value(registry.get(atom)) : value);
89
+ };
90
+ }
91
+ function useAtomSet(atom, options) {
92
+ const registry = useRegistry();
93
+ const unmount = registry.mount(atom);
94
+ onCleanup3(unmount);
95
+ return createSetAtom(registry, atom, options);
96
+ }
97
+
98
+ // src/hooks/useAtom.ts
99
+ import { createSignal as createSignal2, onCleanup as onCleanup4 } from "solid-js";
100
+ function useAtom(atom, options) {
101
+ const registry = useRegistry();
102
+ const [value, setValue] = createSignal2(registry.get(atom));
103
+ const unsubscribe = registry.subscribe(atom, (nextValue) => {
104
+ setValue(() => nextValue);
105
+ }, {
106
+ immediate: true
107
+ });
108
+ onCleanup4(unsubscribe);
109
+ return [
110
+ value,
111
+ createSetAtom(registry, atom, options)
112
+ ];
113
+ }
114
+
115
+ // src/hooks/useAtomMount.ts
116
+ import { onCleanup as onCleanup5 } from "solid-js";
117
+ function useAtomMount(atom) {
118
+ const registry = useRegistry();
119
+ const unmount = registry.mount(atom);
120
+ onCleanup5(unmount);
121
+ }
122
+
123
+ // src/hooks/useAtomRefresh.ts
124
+ import { onCleanup as onCleanup6 } from "solid-js";
125
+ function useAtomRefresh(atom) {
126
+ const registry = useRegistry();
127
+ const unmount = registry.mount(atom);
128
+ onCleanup6(unmount);
129
+ return () => registry.refresh(atom);
130
+ }
131
+
132
+ // src/hooks/useAtomSubscribe.ts
133
+ import { onCleanup as onCleanup7 } from "solid-js";
134
+ function useAtomSubscribe(atom, f, options) {
135
+ const registry = useRegistry();
136
+ const unsubscribe = registry.subscribe(atom, f, options);
137
+ onCleanup7(unsubscribe);
138
+ }
139
+
140
+ // src/hooks/useAtomRef.ts
141
+ import { createMemo as createMemo2, createSignal as createSignal3, onCleanup as onCleanup8 } from "solid-js";
142
+ function useAtomRef(ref) {
143
+ const [value, setValue] = createSignal3(ref.value);
144
+ const unsubscribe = ref.subscribe((next) => {
145
+ setValue(() => next);
146
+ });
147
+ onCleanup8(unsubscribe);
148
+ return value;
149
+ }
150
+ function useAtomRefProp(ref, prop) {
151
+ return createMemo2(() => ref.prop(prop))();
152
+ }
153
+ function useAtomRefPropValue(ref, prop) {
154
+ return useAtomRef(useAtomRefProp(ref, prop));
155
+ }
156
+
157
+ // src/hooks/useAtomResource.ts
158
+ import * as Cause2 from "effect/Cause";
159
+ import { createMemo as createMemo3, createSignal as createSignal4, onCleanup as onCleanup9 } from "solid-js";
160
+ function useAtomResource(atom) {
161
+ const registry = useRegistry();
162
+ const [result, setResult] = createSignal4(registry.get(atom));
163
+ const unsubscribe = registry.subscribe(atom, (nextValue) => {
164
+ setResult(() => nextValue);
165
+ }, {
166
+ immediate: true
167
+ });
168
+ onCleanup9(unsubscribe);
169
+ const value = createMemo3(() => {
170
+ const r = result();
171
+ return r._tag === "Success" ? r.value : void 0;
172
+ });
173
+ const error = createMemo3(() => {
174
+ const r = result();
175
+ return r._tag === "Failure" ? Cause2.squash(r.cause) : void 0;
176
+ });
177
+ const loading = createMemo3(() => {
178
+ const r = result();
179
+ return r._tag === "Initial" || r.waiting;
180
+ });
181
+ return {
182
+ value,
183
+ error,
184
+ loading,
185
+ result
186
+ };
187
+ }
188
+
189
+ // src/hooks/useAtomSuspense.ts
190
+ import { createResource, onCleanup as onCleanup10 } from "solid-js";
191
+ function useAtomSuspense(atom) {
192
+ const registry = useRegistry();
193
+ const [data, { mutate, refetch }] = createResource(async () => {
194
+ const current = registry.get(atom);
195
+ if (current._tag === "Success") {
196
+ return current.value;
197
+ }
198
+ if (current._tag === "Failure") {
199
+ throw current.cause;
200
+ }
201
+ return new Promise((resolve, reject) => {
202
+ const unsubscribe2 = registry.subscribe(atom, (next) => {
203
+ if (next._tag === "Success") {
204
+ unsubscribe2();
205
+ resolve(next.value);
206
+ } else if (next._tag === "Failure") {
207
+ unsubscribe2();
208
+ reject(next.cause);
209
+ }
210
+ });
211
+ });
212
+ });
213
+ const unsubscribe = registry.subscribe(atom, (next) => {
214
+ if (next._tag === "Success") {
215
+ mutate(() => next.value);
216
+ } else if (next._tag === "Failure") {
217
+ void refetch();
218
+ } else if (next._tag === "Initial" || next.waiting) {
219
+ void refetch();
220
+ }
221
+ });
222
+ onCleanup10(unsubscribe);
223
+ return () => {
224
+ const value = data();
225
+ if (value === void 0) {
226
+ }
227
+ return value;
228
+ };
229
+ }
230
+
231
+ // src/hooks/useAtomInitialValues.ts
232
+ function useAtomInitialValues(initialValues) {
233
+ const registry = useRegistry();
234
+ for (const [atom, value] of initialValues) {
235
+ registry.set(atom, value);
236
+ }
237
+ }
238
+ export {
239
+ Atom,
240
+ AtomHttpApi,
241
+ AtomRef,
242
+ AtomRpc,
243
+ Registry3 as Registry,
244
+ RegistryContext,
245
+ RegistryProvider,
246
+ Result,
247
+ createSetAtom,
248
+ defaultRegistry,
249
+ useAtom,
250
+ useAtomInitialValues,
251
+ useAtomMount,
252
+ useAtomRef,
253
+ useAtomRefProp,
254
+ useAtomRefPropValue,
255
+ useAtomRefresh,
256
+ useAtomResource,
257
+ useAtomSet,
258
+ useAtomSubscribe,
259
+ useAtomSuspense,
260
+ useAtomValue,
261
+ useRegistry
262
+ };
263
+ //# sourceMappingURL=index.mjs.map