Skip to content

Commit 2588985

Browse files
mturcothePunderWoman
authored andcommitted
feat(core): pass signal node to throwInvalidWriteToSignalErrorFn (#59600)
Updates the signature of the `throwInvalidWriteToSignalError` to take the signal node in question and pass it along to the throwInvalidWriteToSignalErrorFn handler function. This allows the handler to e.g. include the signal name in error messaging. PR Close #59600
1 parent 973033a commit 2588985

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

goldens/public-api/core/primitives/signals/index.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export function setAlternateWeakRefImpl(impl: unknown): void;
144144
export function setPostSignalSetFn(fn: (() => void) | null): (() => void) | null;
145145

146146
// @public (undocumented)
147-
export function setThrowInvalidWriteToSignalError(fn: () => never): void;
147+
export function setThrowInvalidWriteToSignalError(fn: <T>(node: SignalNode<T>) => never): void;
148148

149149
// @public
150150
export const SIGNAL: unique symbol;

packages/core/primitives/signals/src/errors.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9+
import type {SignalNode} from './signal';
10+
911
function defaultThrowError(): never {
1012
throw new Error();
1113
}
1214

13-
let throwInvalidWriteToSignalErrorFn = defaultThrowError;
15+
let throwInvalidWriteToSignalErrorFn: <T>(node: SignalNode<T>) => never = defaultThrowError;
1416

15-
export function throwInvalidWriteToSignalError() {
16-
throwInvalidWriteToSignalErrorFn();
17+
export function throwInvalidWriteToSignalError<T>(node: SignalNode<T>) {
18+
throwInvalidWriteToSignalErrorFn(node);
1719
}
1820

19-
export function setThrowInvalidWriteToSignalError(fn: () => never): void {
21+
export function setThrowInvalidWriteToSignalError(fn: <T>(node: SignalNode<T>) => never): void {
2022
throwInvalidWriteToSignalErrorFn = fn;
2123
}

packages/core/primitives/signals/src/signal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function signalGetFn<T>(this: SignalNode<T>): T {
7070

7171
export function signalSetFn<T>(node: SignalNode<T>, newValue: T) {
7272
if (!producerUpdatesAllowed()) {
73-
throwInvalidWriteToSignalError();
73+
throwInvalidWriteToSignalError(node);
7474
}
7575

7676
if (!node.equal(node.value, newValue)) {
@@ -81,7 +81,7 @@ export function signalSetFn<T>(node: SignalNode<T>, newValue: T) {
8181

8282
export function signalUpdateFn<T>(node: SignalNode<T>, updater: (value: T) => T): void {
8383
if (!producerUpdatesAllowed()) {
84-
throwInvalidWriteToSignalError();
84+
throwInvalidWriteToSignalError(node);
8585
}
8686

8787
signalSetFn(node, updater(node.value));

0 commit comments

Comments
 (0)