Skip to content

Commit 3856629

Browse files
refactor(core): pass signal equal function to primitives (#60364)
The signals primitives package understands the equals option now so we can pass it to the signal / computed creation methods instead of manually assigning the equality function on a reactive node. PR Close #60364
1 parent 8caf9d7 commit 3856629

File tree

3 files changed

+7
-16
lines changed

3 files changed

+7
-16
lines changed

packages/core/src/render3/reactivity/computed.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
import {createComputed, SIGNAL} from '@angular/core/primitives/signals';
1010

11-
import {performanceMarkFeature} from '../../util/performance';
12-
1311
import {Signal, ValueEqualityFn} from './api';
1412

1513
/**
@@ -31,10 +29,7 @@ export interface CreateComputedOptions<T> {
3129
* Create a computed `Signal` which derives a reactive value from an expression.
3230
*/
3331
export function computed<T>(computation: () => T, options?: CreateComputedOptions<T>): Signal<T> {
34-
const getter = createComputed(computation);
35-
if (options?.equal) {
36-
getter[SIGNAL].equal = options.equal;
37-
}
32+
const getter = createComputed(computation, options?.equal);
3833

3934
if (ngDevMode) {
4035
getter.toString = () => `[Computed: ${getter()}]`;

packages/core/src/render3/reactivity/linked_signal.ts

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

9-
import {signalAsReadonlyFn, WritableSignal} from './signal';
10-
import {Signal, ValueEqualityFn} from './api';
11-
import {performanceMarkFeature} from '../../util/performance';
129
import {
1310
ComputationFn,
1411
createLinkedSignal,
1512
LinkedSignalGetter,
1613
LinkedSignalNode,
17-
SIGNAL,
1814
linkedSignalSetFn,
1915
linkedSignalUpdateFn,
16+
SIGNAL,
2017
} from '@angular/core/primitives/signals';
18+
import {Signal, ValueEqualityFn} from './api';
19+
import {signalAsReadonlyFn, WritableSignal} from './signal';
2120

2221
const identityFn = <T>(v: T) => v;
2322

packages/core/src/render3/reactivity/signal.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import {
1515
signalUpdateFn,
1616
} from '@angular/core/primitives/signals';
1717

18-
import {performanceMarkFeature} from '../../util/performance';
19-
2018
import {isSignal, Signal, ValueEqualityFn} from './api';
2119

2220
/** Symbol used distinguish `WritableSignal` from other non-writable signals and functions. */
@@ -76,11 +74,10 @@ export interface CreateSignalOptions<T> {
7674
* Create a `Signal` that can be set or updated directly.
7775
*/
7876
export function signal<T>(initialValue: T, options?: CreateSignalOptions<T>): WritableSignal<T> {
79-
const signalFn = createSignal(initialValue) as SignalGetter<T> & WritableSignal<T>;
77+
const signalFn = createSignal(initialValue, options?.equal) as SignalGetter<T> &
78+
WritableSignal<T>;
79+
8080
const node = signalFn[SIGNAL];
81-
if (options?.equal) {
82-
node.equal = options.equal;
83-
}
8481

8582
signalFn.set = (newValue: T) => signalSetFn(node, newValue);
8683
signalFn.update = (updateFn: (value: T) => T) => signalUpdateFn(node, updateFn);

0 commit comments

Comments
 (0)