@@ -43,12 +43,31 @@ export type AsyncStateStatus =
43
43
| 'success'
44
44
| 'error' ;
45
45
46
- export type AsyncState < R > = {
47
- status : AsyncStateStatus ;
48
- loading : boolean ;
49
- error : Error | undefined ;
50
- result : R | undefined ;
51
- } ;
46
+ export declare type AsyncState < R > =
47
+ | {
48
+ status : 'not-requested' ;
49
+ loading : false ;
50
+ result : undefined ;
51
+ error : undefined ;
52
+ }
53
+ | {
54
+ status : 'loading' ;
55
+ loading : true ;
56
+ error : undefined ;
57
+ result : undefined ;
58
+ }
59
+ | {
60
+ status : 'success' ;
61
+ loading : false ;
62
+ error : undefined ;
63
+ result : R ;
64
+ }
65
+ | {
66
+ status : 'error' ;
67
+ loading : false ;
68
+ error : Error ;
69
+ result : undefined ;
70
+ } ;
52
71
type SetLoading < R > = ( asyncState : AsyncState < R > ) => AsyncState < R > ;
53
72
type SetResult < R > = ( result : R , asyncState : AsyncState < R > ) => AsyncState < R > ;
54
73
type SetError < R > = ( error : Error , asyncState : AsyncState < R > ) => AsyncState < R > ;
@@ -135,7 +154,6 @@ const normalizeOptions = <R>(
135
154
type UseAsyncStateResult < R > = {
136
155
value : AsyncState < R > ;
137
156
set : Dispatch < SetStateAction < AsyncState < R > > > ;
138
- merge : ( value : Partial < AsyncState < R > > ) => void ;
139
157
reset : ( ) => void ;
140
158
setLoading : ( ) => void ;
141
159
setResult : ( r : R ) => void ;
@@ -167,19 +185,9 @@ const useAsyncState = <R extends {}>(
167
185
[ value , setValue ]
168
186
) ;
169
187
170
- const merge = useCallback (
171
- ( state : Partial < AsyncState < R > > ) =>
172
- setValue ( {
173
- ...value ,
174
- ...state ,
175
- } ) ,
176
- [ value , setValue ]
177
- ) ;
178
-
179
188
return {
180
189
value,
181
190
set : setValue ,
182
- merge,
183
191
reset,
184
192
setLoading,
185
193
setResult,
@@ -217,7 +225,6 @@ export type UseAsyncReturn<
217
225
Args extends any [ ] = UnknownArgs
218
226
> = AsyncState < R > & {
219
227
set : ( value : AsyncState < R > ) => void ;
220
- merge : ( value : Partial < AsyncState < R > > ) => void ;
221
228
reset : ( ) => void ;
222
229
execute : ( ...args : Args ) => Promise < R > ;
223
230
currentPromise : Promise < R > | null ;
@@ -298,7 +305,6 @@ const useAsyncInternal = <R = UnknownResult, Args extends any[] = UnknownArgs>(
298
305
return {
299
306
...AsyncState . value ,
300
307
set : AsyncState . set ,
301
- merge : AsyncState . merge ,
302
308
reset : AsyncState . reset ,
303
309
execute : executeAsyncOperationMemo ,
304
310
currentPromise : CurrentPromise . get ( ) ,
0 commit comments