11"use client"
2+ import type { LazyArg } from "@effect/data/Function"
23import { pipe } from "@effect/data/Function"
34import * as Effect from "@effect/io/Effect"
45import * as Layer from "@effect/io/Layer"
56import type * as Runtime from "@effect/io/Runtime"
67import * as Scope from "@effect/io/Scope"
7- import type { UseResult } from "effect-react/hooks/useResult"
8- import { makeUseResult } from "effect-react/hooks/useResult"
9- import type { UseResultCallback } from "effect-react/hooks/useResultCallback"
10- import { makeUseResultCallback } from "effect-react/hooks/useResultCallback"
8+ import type * as Stream from "@effect/stream/Stream"
9+ import * as internalUseResult from "effect-react/internal/hooks/useResult"
10+ import * as internalUseResultCallback from "effect-react/internal/hooks/useResultCallback"
11+ import type * as ResultBag from "effect-react/ResultBag"
12+ import type { DependencyList } from "react"
1113import { createContext } from "react"
1214
13- export { RuntimeContext } from "effect-react/internal/runtimeContext"
15+ /**
16+ * @since 1.0.0
17+ * @category models
18+ */
19+ export type RuntimeContext < R > = React . Context < Runtime . Runtime < R > >
1420
21+ /**
22+ * @since 1.0.0
23+ * @category hooks
24+ */
25+ export type UseResult < R > = < R0 extends R , E , A > (
26+ evaluate : LazyArg < Stream . Stream < R0 , E , A > > ,
27+ deps : DependencyList
28+ ) => ResultBag . ResultBag < E , A >
29+
30+ /**
31+ * @since 1.0.0
32+ * @category hooks
33+ */
34+ export type UseResultCallback < R > = < Args extends Array < any > , R0 extends R , E , A > (
35+ f : ( ...args : Args ) => Stream . Stream < R0 , E , A >
36+ ) => readonly [ ResultBag . ResultBag < E , A > , ( ...args : Args ) => void ]
37+
38+ /**
39+ * @since 1.0.0
40+ * @category models
41+ */
1542export interface ReactEffectBag < R > {
1643 readonly RuntimeContext : React . Context < Runtime . Runtime < R > >
1744 readonly useResultCallback : UseResultCallback < R >
1845 readonly useResult : UseResult < R >
1946}
2047
48+ /**
49+ * @since 1.0.0
50+ * @category constructors
51+ */
2152export const makeFromLayer = < R , E > (
2253 layer : Layer . Layer < never , E , R >
2354) : ReactEffectBag < R > => {
@@ -33,29 +64,37 @@ export const makeFromLayer = <R, E>(
3364
3465 return {
3566 RuntimeContext,
36- useResultCallback : makeUseResultCallback ( RuntimeContext ) ,
37- useResult : makeUseResult ( RuntimeContext )
67+ useResultCallback : internalUseResultCallback . make ( RuntimeContext ) ,
68+ useResult : internalUseResult . make ( RuntimeContext )
3869 }
3970}
4071
72+ /**
73+ * @since 1.0.0
74+ * @category constructors
75+ */
4176export const makeFromRuntime = < R > (
4277 runtime : Runtime . Runtime < R >
4378) : ReactEffectBag < R > => {
4479 const RuntimeContext = createContext ( runtime )
4580
4681 return {
4782 RuntimeContext,
48- useResultCallback : makeUseResultCallback ( RuntimeContext ) ,
49- useResult : makeUseResult ( RuntimeContext )
83+ useResultCallback : internalUseResultCallback . make ( RuntimeContext ) ,
84+ useResult : internalUseResult . make ( RuntimeContext )
5085 }
5186}
5287
88+ /**
89+ * @since 1.0.0
90+ * @category constructors
91+ */
5392export const makeFromRuntimeContext = < R > (
5493 RuntimeContext : React . Context < Runtime . Runtime < R > >
5594) : ReactEffectBag < R > => {
5695 return {
5796 RuntimeContext,
58- useResultCallback : makeUseResultCallback ( RuntimeContext ) ,
59- useResult : makeUseResult ( RuntimeContext )
97+ useResultCallback : internalUseResultCallback . make ( RuntimeContext ) ,
98+ useResult : internalUseResult . make ( RuntimeContext )
6099 }
61100}
0 commit comments