Skip to content

Commit

Permalink
chore: review feedback fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonroberts committed Sep 23, 2024
1 parent 713e4d4 commit a26bbb3
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions modules/signals/src/state-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@angular/core';
import { Prettify } from './ts-helpers';

const STATE_WATCHERS = new WeakMap<object, Array<StateWatcher<any>>>();
const STATE_WATCHERS = new WeakMap<Signal<object>, Array<StateWatcher<any>>>();

export const STATE_SOURCE = Symbol('STATE_SOURCE');

Expand Down Expand Up @@ -78,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] as object) || [];
return STATE_WATCHERS.get(stateSource[STATE_SOURCE]) || [];
}

function notifyWatchers<State extends object>(
Expand All @@ -97,10 +97,7 @@ function addWatcher<State extends object>(
watcher: StateWatcher<State>
): void {
const watchers = getWatchers(stateSource);
STATE_WATCHERS.set(stateSource[STATE_SOURCE] as object, [
...watchers,
watcher,
]);
STATE_WATCHERS.set(stateSource[STATE_SOURCE], [...watchers, watcher]);
}

function removeWatcher<State extends object>(
Expand All @@ -109,7 +106,7 @@ function removeWatcher<State extends object>(
): void {
const watchers = getWatchers(stateSource);
STATE_WATCHERS.set(
stateSource[STATE_SOURCE] as object,
stateSource[STATE_SOURCE],
watchers.filter((w) => w !== watcher)
);
}

0 comments on commit a26bbb3

Please sign in to comment.