Skip to content

Commit efa7461

Browse files
committed
refactor: rename async computed fields
1 parent 10f337c commit efa7461

File tree

5 files changed

+44
-51
lines changed

5 files changed

+44
-51
lines changed

packages/qwik/src/core/reactive-primitives/cleanup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function clearAsyncComputedSignal(
6464
if (effects) {
6565
effects.delete(effect);
6666
}
67-
const pendingEffects = producer.$pendingEffects$;
67+
const pendingEffects = producer.$loadingEffects$;
6868
if (pendingEffects) {
6969
pendingEffects.delete(effect);
7070
}

packages/qwik/src/core/reactive-primitives/impl/async-computed-signal-impl.ts

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { isDev } from '@qwik.dev/core/build';
21
import { qwikDebugToString } from '../../debug';
32
import type { Container } from '../../shared/types';
43
import { ChoreType } from '../../shared/util-chore-type';
@@ -28,11 +27,11 @@ export class AsyncComputedSignalImpl<T>
2827
extends ComputedSignalImpl<T, AsyncComputeQRL<T>>
2928
implements BackRef
3029
{
31-
$untrackedPending$: boolean = false;
32-
$untrackedFailed$: boolean = false;
30+
$untrackedLoading$: boolean = false;
31+
$untrackedError$: Error | null = null;
3332

34-
$pendingEffects$: null | Set<EffectSubscription> = null;
35-
$failedEffects$: null | Set<EffectSubscription> = null;
33+
$loadingEffects$: null | Set<EffectSubscription> = null;
34+
$errorEffects$: null | Set<EffectSubscription> = null;
3635
$destroy$: NoSerialize<() => void> | null;
3736
private $promiseValue$: T | null = null;
3837

@@ -43,59 +42,56 @@ export class AsyncComputedSignalImpl<T>
4342
}
4443

4544
/**
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
4746
* has resolved or rejected.
4847
*/
49-
get pending(): boolean {
48+
get loading(): boolean {
5049
return setupSignalValueAccess(
5150
this,
52-
() => (this.$pendingEffects$ ||= new Set()),
53-
() => this.untrackedPending
51+
() => (this.$loadingEffects$ ||= new Set()),
52+
() => this.untrackedLoading
5453
);
5554
}
5655

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;
6059
this.$container$?.$scheduler$(
6160
ChoreType.RECOMPUTE_AND_SCHEDULE_EFFECTS,
6261
null,
6362
this,
64-
this.$pendingEffects$
63+
this.$loadingEffects$
6564
);
6665
}
6766
}
6867

69-
get untrackedPending() {
70-
return this.$untrackedPending$;
68+
get untrackedLoading() {
69+
return this.$untrackedLoading$;
7170
}
7271

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 {
7874
return setupSignalValueAccess(
7975
this,
80-
() => (this.$failedEffects$ ||= new Set()),
81-
() => this.untrackedFailed
76+
() => (this.$errorEffects$ ||= new Set()),
77+
() => this.untrackedError
8278
);
8379
}
8480

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;
8884
this.$container$?.$scheduler$(
8985
ChoreType.RECOMPUTE_AND_SCHEDULE_EFFECTS,
9086
null,
9187
this,
92-
this.$failedEffects$
88+
this.$errorEffects$
9389
);
9490
}
9591
}
9692

97-
get untrackedFailed() {
98-
return this.$untrackedFailed$;
93+
get untrackedError() {
94+
return this.$untrackedError$;
9995
}
10096

10197
$computeIfNeeded$() {
@@ -113,20 +109,17 @@ export class AsyncComputedSignalImpl<T>
113109
cleanup,
114110
}) as T);
115111
if (isPromise(untrackedValue)) {
116-
this.untrackedPending = true;
117-
this.untrackedFailed = false;
112+
this.untrackedLoading = true;
113+
this.untrackedError = null;
118114
throw untrackedValue
119115
.then((promiseValue) => {
120116
this.$promiseValue$ = promiseValue;
121-
this.untrackedPending = false;
117+
this.untrackedLoading = false;
118+
this.untrackedError = null;
122119
})
123120
.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;
130123
});
131124
}
132125
this.$promiseValue$ = null;

packages/qwik/src/core/reactive-primitives/signal.public.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface ReadonlySignal<T = unknown> {
1616
/** @public */
1717
export interface AsyncComputedReadonlySignal<T = unknown> extends ReadonlySignal<T> {
1818
// TODO: enable later this, after the scheduler changes for "streaming" signals values
19-
// pending: boolean;
20-
// failed: boolean;
19+
// loading: boolean;
20+
// error: Error | null;
2121
}
2222

2323
/**

packages/qwik/src/core/shared/shared-serialization.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,15 @@ const inflate = (
297297
Array<EffectSubscription> | null,
298298
Array<EffectSubscription> | null,
299299
boolean,
300-
boolean,
300+
Error,
301301
unknown?,
302302
];
303303
asyncComputed.$computeQrl$ = d[0];
304304
asyncComputed.$effects$ = new Set(d[1]);
305-
asyncComputed.$pendingEffects$ = new Set(d[2]);
306-
asyncComputed.$failedEffects$ = new Set(d[3]);
307-
asyncComputed.$untrackedPending$ = d[4];
308-
asyncComputed.$untrackedFailed$ = d[5];
305+
asyncComputed.$loadingEffects$ = new Set(d[2]);
306+
asyncComputed.$errorEffects$ = new Set(d[3]);
307+
asyncComputed.$untrackedLoading$ = d[4];
308+
asyncComputed.$untrackedError$ = d[5];
309309
const hasValue = d.length > 6;
310310
if (hasValue) {
311311
asyncComputed.$untrackedValue$ = d[6];
@@ -1192,15 +1192,15 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
11921192
Set<EffectSubscription> | null,
11931193
Set<EffectSubscription> | null,
11941194
boolean,
1195-
boolean,
1195+
Error | null,
11961196
unknown?,
11971197
] = [
11981198
value.$computeQrl$,
11991199
value.$effects$,
1200-
value.$pendingEffects$,
1201-
value.$failedEffects$,
1202-
value.$untrackedPending$,
1203-
value.$untrackedFailed$,
1200+
value.$loadingEffects$,
1201+
value.$errorEffects$,
1202+
value.$untrackedLoading$,
1203+
value.$untrackedError$,
12041204
];
12051205
if (v !== NEEDS_COMPUTATION) {
12061206
out.push(v);

starters/apps/e2e/src/components/async-computed/async-computed.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const PendingComponent = component$(() => {
5757

5858
return (
5959
<div>
60-
{(double as any).pending ? "pending" : "not pending"}
60+
{(double as any).loading ? "loading" : "not loading"}
6161
<div class="result">double: {double.value}</div>
6262
<button id="increment" onClick$={() => count.value++}>
6363
Increment

0 commit comments

Comments
 (0)