Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(signals): remove usage of SIGNAL from @angular/core/primitives/signals package #4530

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions modules/signals/spec/signal-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down
5 changes: 1 addition & 4 deletions modules/signals/src/signal-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
7 changes: 3 additions & 4 deletions modules/signals/src/state-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
untracked,
WritableSignal,
} from '@angular/core';
import { SIGNAL } from '@angular/core/primitives/signals';
import { Prettify } from './ts-helpers';

const STATE_WATCHERS = new WeakMap<object, Array<StateWatcher<any>>>();
brandonroberts marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -79,7 +78,7 @@ export function watchState<State extends object>(
function getWatchers<State extends object>(
stateSource: StateSource<State>
): Array<StateWatcher<State>> {
return STATE_WATCHERS.get(stateSource[STATE_SOURCE][SIGNAL] as object) || [];
return STATE_WATCHERS.get(stateSource[STATE_SOURCE] as object) || [];
brandonroberts marked this conversation as resolved.
Show resolved Hide resolved
}

function notifyWatchers<State extends object>(
Expand All @@ -98,7 +97,7 @@ function addWatcher<State extends object>(
watcher: StateWatcher<State>
): void {
const watchers = getWatchers(stateSource);
STATE_WATCHERS.set(stateSource[STATE_SOURCE][SIGNAL] as object, [
STATE_WATCHERS.set(stateSource[STATE_SOURCE] as object, [
brandonroberts marked this conversation as resolved.
Show resolved Hide resolved
...watchers,
watcher,
]);
Expand All @@ -110,7 +109,7 @@ function removeWatcher<State extends object>(
): void {
const watchers = getWatchers(stateSource);
STATE_WATCHERS.set(
stateSource[STATE_SOURCE][SIGNAL] as object,
stateSource[STATE_SOURCE] as object,
brandonroberts marked this conversation as resolved.
Show resolved Hide resolved
watchers.filter((w) => w !== watcher)
);
}