Skip to content

Commit

Permalink
fix: it should not break a computed signal to watch it before getting…
Browse files Browse the repository at this point in the history
… its value
  • Loading branch information
divdavem committed Sep 11, 2024
1 parent c6aa9ba commit 48a9763
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 0 additions & 6 deletions src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,6 @@ export function producerIncrementEpoch(): void {
* Ensure this producer's `version` is up-to-date.
*/
export function producerUpdateValueVersion(node: ReactiveNode): void {
if (consumerIsLive(node) && !node.dirty) {
// A live consumer will be marked dirty by producers, so a clean state means that its version
// is guaranteed to be up-to-date.
return;
}

if (!node.dirty && node.lastCleanEpoch === epoch) {
// Even non-live consumers can skip polling if they previously found themselves to be clean at
// the current epoch, since their dependencies could not possibly have changed (such a change
Expand Down
12 changes: 12 additions & 0 deletions tests/Signal/subtle/watcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,16 @@ describe('Watcher', () => {
signal.set(1);
expect(mockGetPending).toBeCalled();
});

it('should not break a computed signal to watch it before getting its value', () => {
const signal = new Signal.State(0);
const computedSignal = new Signal.Computed(() => signal.get());
const watcher = new Signal.subtle.Watcher(() => {});
expect(computedSignal.get()).toBe(0);
signal.set(1);
watcher.watch(computedSignal);
expect(computedSignal.get()).toBe(1);
watcher.unwatch(computedSignal);
expect(computedSignal.get()).toBe(1);
});
});

0 comments on commit 48a9763

Please sign in to comment.