@@ -11,6 +11,15 @@ const memo2 = <T>(create: () => T, dep1: object, dep2: object): T => {
11
11
12
12
const defaultFallback = ( ) => undefined
13
13
14
+ export function unwrap < Value , Args extends unknown [ ] , Result > (
15
+ anAtom : WritableAtom < Value , Args , Result >
16
+ ) : WritableAtom < Awaited < Value > | undefined , Args , Result >
17
+
18
+ export function unwrap < Value , Args extends unknown [ ] , Result , PendingValue > (
19
+ anAtom : WritableAtom < Value , Args , Result > ,
20
+ fallback : ( prev ?: Awaited < Value > ) => PendingValue
21
+ ) : WritableAtom < Awaited < Value > | PendingValue , Args , Result >
22
+
14
23
export function unwrap < Value > (
15
24
anAtom : Atom < Value >
16
25
) : Atom < Awaited < Value > | undefined >
@@ -20,18 +29,18 @@ export function unwrap<Value, PendingValue>(
20
29
fallback : ( prev ?: Awaited < Value > ) => PendingValue
21
30
) : Atom < Awaited < Value > | PendingValue >
22
31
23
- export function unwrap < Value , PendingValue > (
24
- anAtom : Atom < Value > ,
32
+ export function unwrap < Value , Args extends unknown [ ] , Result , PendingValue > (
33
+ anAtom : WritableAtom < Value , Args , Result > | Atom < Value > ,
25
34
fallback : ( prev ?: Awaited < Value > ) => PendingValue = defaultFallback as any
26
35
) {
27
36
return memo2 (
28
37
( ) => {
29
- type PromiseAndValue = { readonly p ?: Promise < Value > } & (
38
+ type PromiseAndValue = { readonly p ?: Promise < unknown > } & (
30
39
| { readonly v : Awaited < Value > }
31
40
| { readonly f : PendingValue }
32
41
)
33
- const promiseErrorCache = new WeakMap < Promise < Value > , unknown > ( )
34
- const promiseResultCache = new WeakMap < Promise < Value > , Awaited < Value > > ( )
42
+ const promiseErrorCache = new WeakMap < Promise < unknown > , unknown > ( )
43
+ const promiseResultCache = new WeakMap < Promise < unknown > , Awaited < Value > > ( )
35
44
const refreshAtom = atom ( 0 )
36
45
37
46
if ( import . meta. env ?. MODE !== 'production' ) {
@@ -89,7 +98,7 @@ export function unwrap<Value, PendingValue>(
89
98
return state . v
90
99
}
91
100
return state . f
92
- } )
101
+ } , ( anAtom as WritableAtom < Value , unknown [ ] , unknown > ) . write )
93
102
} ,
94
103
anAtom ,
95
104
fallback
0 commit comments