From cae429ad6c903ea0be3984e8572d49f2a4ba248c Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Tue, 24 Sep 2024 12:27:01 -0500 Subject: [PATCH] fix(signals): remove usage of SIGNAL from @angular/core/primitives/signals package (#4530) --- modules/signals/spec/signal-store.spec.ts | 2 -- modules/signals/src/signal-store.ts | 5 +---- modules/signals/src/state-source.ts | 12 ++++-------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/modules/signals/spec/signal-store.spec.ts b/modules/signals/spec/signal-store.spec.ts index f1f0c54319..5db462aafb 100644 --- a/modules/signals/spec/signal-store.spec.ts +++ b/modules/signals/spec/signal-store.spec.ts @@ -47,7 +47,6 @@ describe('signalStore', () => { expect(isSignal(stateSource)).toBe(true); expect(stateSource()).toEqual({ foo: 'bar' }); - expect(typeof (stateSource as any).update === 'undefined').toBe(true); }); it('creates a store with readonly state source when protectedState option is true', () => { @@ -60,7 +59,6 @@ describe('signalStore', () => { expect(isSignal(stateSource)).toBe(true); expect(stateSource()).toEqual({ foo: 'bar' }); - expect(typeof (stateSource as any).update === 'undefined').toBe(true); }); it('creates a store with writable state source when protectedState option is false', () => { diff --git a/modules/signals/src/signal-store.ts b/modules/signals/src/signal-store.ts index 968ac78ef0..5d5da1505f 100644 --- a/modules/signals/src/signal-store.ts +++ b/modules/signals/src/signal-store.ts @@ -1357,10 +1357,7 @@ export function signalStore( const { stateSignals, computedSignals, methods, hooks } = innerStore; const storeMembers = { ...stateSignals, ...computedSignals, ...methods }; - (this as any)[STATE_SOURCE] = - config.protectedState === false - ? innerStore[STATE_SOURCE] - : innerStore[STATE_SOURCE].asReadonly(); + (this as any)[STATE_SOURCE] = innerStore[STATE_SOURCE]; for (const key in storeMembers) { (this as any)[key] = storeMembers[key]; diff --git a/modules/signals/src/state-source.ts b/modules/signals/src/state-source.ts index 940e2d5f81..4db6ec3a68 100644 --- a/modules/signals/src/state-source.ts +++ b/modules/signals/src/state-source.ts @@ -7,10 +7,9 @@ import { untracked, WritableSignal, } from '@angular/core'; -import { SIGNAL } from '@angular/core/primitives/signals'; import { Prettify } from './ts-helpers'; -const STATE_WATCHERS = new WeakMap>>(); +const STATE_WATCHERS = new WeakMap, Array>>(); export const STATE_SOURCE = Symbol('STATE_SOURCE'); @@ -79,7 +78,7 @@ export function watchState( function getWatchers( stateSource: StateSource ): Array> { - return STATE_WATCHERS.get(stateSource[STATE_SOURCE][SIGNAL] as object) || []; + return STATE_WATCHERS.get(stateSource[STATE_SOURCE]) || []; } function notifyWatchers( @@ -98,10 +97,7 @@ function addWatcher( watcher: StateWatcher ): void { const watchers = getWatchers(stateSource); - STATE_WATCHERS.set(stateSource[STATE_SOURCE][SIGNAL] as object, [ - ...watchers, - watcher, - ]); + STATE_WATCHERS.set(stateSource[STATE_SOURCE], [...watchers, watcher]); } function removeWatcher( @@ -110,7 +106,7 @@ function removeWatcher( ): void { const watchers = getWatchers(stateSource); STATE_WATCHERS.set( - stateSource[STATE_SOURCE][SIGNAL] as object, + stateSource[STATE_SOURCE], watchers.filter((w) => w !== watcher) ); }