1
1
"use client"
2
+ import type * as Context from "@effect/data/Context"
2
3
import type { LazyArg } from "@effect/data/Function"
3
4
import { pipe } from "@effect/data/Function"
4
5
import * as Effect from "@effect/io/Effect"
@@ -8,6 +9,8 @@ import * as Scope from "@effect/io/Scope"
8
9
import type * as Stream from "@effect/stream/Stream"
9
10
import * as internalUseResult from "effect-react/internal/hooks/useResult"
10
11
import * as internalUseResultCallback from "effect-react/internal/hooks/useResultCallback"
12
+ import * as internalUseService from "effect-react/internal/hooks/useService"
13
+ import * as internalUseValue from "effect-react/internal/hooks/useValue"
11
14
import type * as ResultBag from "effect-react/ResultBag"
12
15
import type { DependencyList } from "react"
13
16
import { createContext } from "react"
@@ -35,6 +38,22 @@ export type UseResultCallback<R> = <Args extends Array<any>, R0 extends R, E, A>
35
38
f : ( ...args : Args ) => Stream . Stream < R0 , E , A >
36
39
) => readonly [ ResultBag . ResultBag < E , A > , ( ...args : Args ) => void ]
37
40
41
+ /**
42
+ * @since 1.0.0
43
+ * @category hooks
44
+ */
45
+ export type UseValue < R > = < R0 extends R , A > (
46
+ stream : Stream . Stream < R0 , never , A > ,
47
+ initial : A ,
48
+ deps : DependencyList
49
+ ) => A
50
+
51
+ /**
52
+ * @since 1.0.0
53
+ * @category hooks
54
+ */
55
+ export type UseService < R > = < Tag extends Context . ValidTagsById < R > > ( tag : Tag ) => Context . Tag . Service < Tag >
56
+
38
57
/**
39
58
* @since 1.0.0
40
59
* @category models
@@ -43,6 +62,8 @@ export interface ReactEffectBag<R> {
43
62
readonly RuntimeContext : React . Context < Runtime . Runtime < R > >
44
63
readonly useResultCallback : UseResultCallback < R >
45
64
readonly useResult : UseResult < R >
65
+ readonly useValue : UseValue < R >
66
+ readonly useService : UseService < R >
46
67
}
47
68
48
69
/**
@@ -65,7 +86,9 @@ export const makeFromLayer = <R, E>(
65
86
return {
66
87
RuntimeContext,
67
88
useResultCallback : internalUseResultCallback . make ( RuntimeContext ) ,
68
- useResult : internalUseResult . make ( RuntimeContext )
89
+ useResult : internalUseResult . make ( RuntimeContext ) ,
90
+ useValue : internalUseValue . make ( RuntimeContext ) ,
91
+ useService : internalUseService . make ( RuntimeContext )
69
92
}
70
93
}
71
94
@@ -81,7 +104,9 @@ export const makeFromRuntime = <R>(
81
104
return {
82
105
RuntimeContext,
83
106
useResultCallback : internalUseResultCallback . make ( RuntimeContext ) ,
84
- useResult : internalUseResult . make ( RuntimeContext )
107
+ useResult : internalUseResult . make ( RuntimeContext ) ,
108
+ useValue : internalUseValue . make ( RuntimeContext ) ,
109
+ useService : internalUseService . make ( RuntimeContext )
85
110
}
86
111
}
87
112
@@ -95,6 +120,8 @@ export const makeFromRuntimeContext = <R>(
95
120
return {
96
121
RuntimeContext,
97
122
useResultCallback : internalUseResultCallback . make ( RuntimeContext ) ,
98
- useResult : internalUseResult . make ( RuntimeContext )
123
+ useResult : internalUseResult . make ( RuntimeContext ) ,
124
+ useValue : internalUseValue . make ( RuntimeContext ) ,
125
+ useService : internalUseService . make ( RuntimeContext )
99
126
}
100
127
}
0 commit comments