1
- import { isDev } from '@qwik.dev/core/build' ;
2
1
import { qwikDebugToString } from '../../debug' ;
3
2
import type { Container } from '../../shared/types' ;
4
3
import { ChoreType } from '../../shared/util-chore-type' ;
@@ -28,11 +27,11 @@ export class AsyncComputedSignalImpl<T>
28
27
extends ComputedSignalImpl < T , AsyncComputeQRL < T > >
29
28
implements BackRef
30
29
{
31
- $untrackedPending $ : boolean = false ;
32
- $untrackedFailed $ : boolean = false ;
30
+ $untrackedLoading $ : boolean = false ;
31
+ $untrackedError $ : Error | null = null ;
33
32
34
- $pendingEffects $ : null | Set < EffectSubscription > = null ;
35
- $failedEffects $ : null | Set < EffectSubscription > = null ;
33
+ $loadingEffects $ : null | Set < EffectSubscription > = null ;
34
+ $errorEffects $ : null | Set < EffectSubscription > = null ;
36
35
$destroy$ : NoSerialize < ( ) => void > | null ;
37
36
private $promiseValue$ : T | null = null ;
38
37
@@ -43,59 +42,56 @@ export class AsyncComputedSignalImpl<T>
43
42
}
44
43
45
44
/**
46
- * Pending is true if the signal is still waiting for the promise to resolve, false if the promise
45
+ * Loading is true if the signal is still waiting for the promise to resolve, false if the promise
47
46
* has resolved or rejected.
48
47
*/
49
- get pending ( ) : boolean {
48
+ get loading ( ) : boolean {
50
49
return setupSignalValueAccess (
51
50
this ,
52
- ( ) => ( this . $pendingEffects $ ||= new Set ( ) ) ,
53
- ( ) => this . untrackedPending
51
+ ( ) => ( this . $loadingEffects $ ||= new Set ( ) ) ,
52
+ ( ) => this . untrackedLoading
54
53
) ;
55
54
}
56
55
57
- set untrackedPending ( value : boolean ) {
58
- if ( value !== this . $untrackedPending $ ) {
59
- this . $untrackedPending $ = value ;
56
+ set untrackedLoading ( value : boolean ) {
57
+ if ( value !== this . $untrackedLoading $ ) {
58
+ this . $untrackedLoading $ = value ;
60
59
this . $container$ ?. $scheduler$ (
61
60
ChoreType . RECOMPUTE_AND_SCHEDULE_EFFECTS ,
62
61
null ,
63
62
this ,
64
- this . $pendingEffects $
63
+ this . $loadingEffects $
65
64
) ;
66
65
}
67
66
}
68
67
69
- get untrackedPending ( ) {
70
- return this . $untrackedPending $ ;
68
+ get untrackedLoading ( ) {
69
+ return this . $untrackedLoading $ ;
71
70
}
72
71
73
- /**
74
- * Failed is true if the signal failed to resolve, false if the promise has resolved or is still
75
- * pending.
76
- */
77
- get failed ( ) : boolean {
72
+ /** The error that occurred when the signal was resolved. */
73
+ get error ( ) : Error | null {
78
74
return setupSignalValueAccess (
79
75
this ,
80
- ( ) => ( this . $failedEffects $ ||= new Set ( ) ) ,
81
- ( ) => this . untrackedFailed
76
+ ( ) => ( this . $errorEffects $ ||= new Set ( ) ) ,
77
+ ( ) => this . untrackedError
82
78
) ;
83
79
}
84
80
85
- set untrackedFailed ( value : boolean ) {
86
- if ( value !== this . $untrackedFailed $ ) {
87
- this . $untrackedFailed $ = value ;
81
+ set untrackedError ( value : Error | null ) {
82
+ if ( value !== this . $untrackedError $ ) {
83
+ this . $untrackedError $ = value ;
88
84
this . $container$ ?. $scheduler$ (
89
85
ChoreType . RECOMPUTE_AND_SCHEDULE_EFFECTS ,
90
86
null ,
91
87
this ,
92
- this . $failedEffects $
88
+ this . $errorEffects $
93
89
) ;
94
90
}
95
91
}
96
92
97
- get untrackedFailed ( ) {
98
- return this . $untrackedFailed $ ;
93
+ get untrackedError ( ) {
94
+ return this . $untrackedError $ ;
99
95
}
100
96
101
97
$computeIfNeeded$ ( ) {
@@ -113,20 +109,17 @@ export class AsyncComputedSignalImpl<T>
113
109
cleanup,
114
110
} ) as T ) ;
115
111
if ( isPromise ( untrackedValue ) ) {
116
- this . untrackedPending = true ;
117
- this . untrackedFailed = false ;
112
+ this . untrackedLoading = true ;
113
+ this . untrackedError = null ;
118
114
throw untrackedValue
119
115
. then ( ( promiseValue ) => {
120
116
this . $promiseValue$ = promiseValue ;
121
- this . untrackedPending = false ;
117
+ this . untrackedLoading = false ;
118
+ this . untrackedError = null ;
122
119
} )
123
120
. catch ( ( err ) => {
124
- if ( isDev ) {
125
- console . error ( err ) ;
126
- }
127
- // TODO: should we store the error?
128
- // this.$promiseValue$ = err;
129
- this . untrackedFailed = true ;
121
+ this . untrackedLoading = false ;
122
+ this . untrackedError = err ;
130
123
} ) ;
131
124
}
132
125
this . $promiseValue$ = null ;
0 commit comments