Skip to content

Commit cae429a

Browse files
authoredSep 24, 2024··
fix(signals): remove usage of SIGNAL from @angular/core/primitives/signals package (#4530)
1 parent 7ecd063 commit cae429a

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed
 

‎modules/signals/spec/signal-store.spec.ts

-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ describe('signalStore', () => {
4747

4848
expect(isSignal(stateSource)).toBe(true);
4949
expect(stateSource()).toEqual({ foo: 'bar' });
50-
expect(typeof (stateSource as any).update === 'undefined').toBe(true);
5150
});
5251

5352
it('creates a store with readonly state source when protectedState option is true', () => {
@@ -60,7 +59,6 @@ describe('signalStore', () => {
6059

6160
expect(isSignal(stateSource)).toBe(true);
6261
expect(stateSource()).toEqual({ foo: 'bar' });
63-
expect(typeof (stateSource as any).update === 'undefined').toBe(true);
6462
});
6563

6664
it('creates a store with writable state source when protectedState option is false', () => {

‎modules/signals/src/signal-store.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1357,10 +1357,7 @@ export function signalStore(
13571357
const { stateSignals, computedSignals, methods, hooks } = innerStore;
13581358
const storeMembers = { ...stateSignals, ...computedSignals, ...methods };
13591359

1360-
(this as any)[STATE_SOURCE] =
1361-
config.protectedState === false
1362-
? innerStore[STATE_SOURCE]
1363-
: innerStore[STATE_SOURCE].asReadonly();
1360+
(this as any)[STATE_SOURCE] = innerStore[STATE_SOURCE];
13641361

13651362
for (const key in storeMembers) {
13661363
(this as any)[key] = storeMembers[key];

‎modules/signals/src/state-source.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import {
77
untracked,
88
WritableSignal,
99
} from '@angular/core';
10-
import { SIGNAL } from '@angular/core/primitives/signals';
1110
import { Prettify } from './ts-helpers';
1211

13-
const STATE_WATCHERS = new WeakMap<object, Array<StateWatcher<any>>>();
12+
const STATE_WATCHERS = new WeakMap<Signal<object>, Array<StateWatcher<any>>>();
1413

1514
export const STATE_SOURCE = Symbol('STATE_SOURCE');
1615

@@ -79,7 +78,7 @@ export function watchState<State extends object>(
7978
function getWatchers<State extends object>(
8079
stateSource: StateSource<State>
8180
): Array<StateWatcher<State>> {
82-
return STATE_WATCHERS.get(stateSource[STATE_SOURCE][SIGNAL] as object) || [];
81+
return STATE_WATCHERS.get(stateSource[STATE_SOURCE]) || [];
8382
}
8483

8584
function notifyWatchers<State extends object>(
@@ -98,10 +97,7 @@ function addWatcher<State extends object>(
9897
watcher: StateWatcher<State>
9998
): void {
10099
const watchers = getWatchers(stateSource);
101-
STATE_WATCHERS.set(stateSource[STATE_SOURCE][SIGNAL] as object, [
102-
...watchers,
103-
watcher,
104-
]);
100+
STATE_WATCHERS.set(stateSource[STATE_SOURCE], [...watchers, watcher]);
105101
}
106102

107103
function removeWatcher<State extends object>(
@@ -110,7 +106,7 @@ function removeWatcher<State extends object>(
110106
): void {
111107
const watchers = getWatchers(stateSource);
112108
STATE_WATCHERS.set(
113-
stateSource[STATE_SOURCE][SIGNAL] as object,
109+
stateSource[STATE_SOURCE],
114110
watchers.filter((w) => w !== watcher)
115111
);
116112
}

0 commit comments

Comments
 (0)
Please sign in to comment.