Skip to content

Commit 5a8c96e

Browse files
committed
chore(core signals): cleanup
1 parent 764908e commit 5a8c96e

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

packages/qwik/src/core/signal/signal-api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import type { QRLInternal } from '../shared/qrl/qrl-class';
22
import type { QRL } from '../shared/qrl/qrl.public';
33
import { ComputedSignal, Signal, throwIfQRLNotResolved } from './signal';
44

5+
/** @internal */
56
export const createSignal = <T>(value?: T) => {
67
return new Signal(null, value);
78
};
89

10+
/** @internal */
911
export const createComputedSignal = <T>(qrl: QRL<() => T>) => {
1012
throwIfQRLNotResolved(qrl);
11-
return new ComputedSignal(null, qrl as QRLInternal<() => T>);
13+
return new ComputedSignal<T>(null, qrl as QRLInternal<() => T>);
1214
};

packages/qwik/src/core/signal/signal.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface InternalSignal<T = any> extends InternalReadonlySignal<T> {
4747
untrackedValue: T;
4848
}
4949

50-
export const throwIfQRLNotResolved = <T>(qrl: QRL<() => T>) => {
50+
export const throwIfQRLNotResolved = (qrl: QRL) => {
5151
const resolved = qrl.resolved;
5252
if (!resolved) {
5353
// When we are creating a signal using a use method, we need to ensure
@@ -205,7 +205,6 @@ export class Signal<T = any> implements ISignal<T> {
205205
}
206206
return this.untrackedValue;
207207
}
208-
209208
set value(value) {
210209
if (value !== this.$untrackedValue$) {
211210
DEBUG &&
@@ -374,6 +373,8 @@ export const triggerEffects = (
374373
DEBUG && log('done scheduling');
375374
};
376375

376+
type ComputeQRL<T> = QRLInternal<(prev: T | undefined) => T>;
377+
377378
/**
378379
* A signal which is computed from other signals.
379380
*
@@ -386,13 +387,13 @@ export class ComputedSignal<T> extends Signal<T> {
386387
* The computed functions must be executed synchronously (because of this we need to eagerly
387388
* resolve the QRL during the mark dirty phase so that any call to it will be synchronous). )
388389
*/
389-
$computeQrl$: QRLInternal<() => T>;
390+
$computeQrl$: ComputeQRL<T>;
390391
// We need a separate flag to know when the computation needs running because
391392
// we need the old value to know if effects need running after computation
392393
$invalid$: boolean = true;
393394
$forceRunEffects$: boolean = false;
394395

395-
constructor(container: Container | null, fn: QRLInternal<() => T>) {
396+
constructor(container: Container | null, fn: ComputeQRL<T>) {
396397
// The value is used for comparison when signals trigger, which can only happen
397398
// when it was calculated before. Therefore we can pass whatever we like.
398399
super(container, NEEDS_COMPUTATION);
@@ -459,14 +460,14 @@ export class ComputedSignal<T> extends Signal<T> {
459460
}
460461
}
461462

462-
// Getters don't get inherited
463-
get value() {
464-
return super.value;
465-
}
466-
463+
// Make this signal read-only
467464
set value(_: any) {
468465
throw qError(QError.computedReadOnly);
469466
}
467+
// Getters don't get inherited when overriding a setter
468+
get value() {
469+
return super.value;
470+
}
470471
}
471472

472473
export class WrappedSignal<T> extends Signal<T> implements Subscriber {
@@ -540,13 +541,12 @@ export class WrappedSignal<T> extends Signal<T> implements Subscriber {
540541
}
541542
return didChange;
542543
}
543-
544-
// Getters don't get inherited
545-
get value() {
546-
return super.value;
547-
}
548-
544+
// Make this signal read-only
549545
set value(_: any) {
550546
throw qError(QError.wrappedReadOnly);
551547
}
548+
// Getters don't get inherited when overriding a setter
549+
get value() {
550+
return super.value;
551+
}
552552
}

0 commit comments

Comments
 (0)