From 48a9763c86c94714d3f68c2d74394cfac83ba297 Mon Sep 17 00:00:00 2001 From: David-Emmanuel DIVERNOIS Date: Tue, 4 Jun 2024 17:29:13 +0200 Subject: [PATCH] fix: it should not break a computed signal to watch it before getting its value --- src/graph.ts | 6 ------ tests/Signal/subtle/watcher.test.ts | 12 ++++++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/graph.ts b/src/graph.ts index 3b56975..24a93d9 100644 --- a/src/graph.ts +++ b/src/graph.ts @@ -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 diff --git a/tests/Signal/subtle/watcher.test.ts b/tests/Signal/subtle/watcher.test.ts index 11521e0..8eada4f 100644 --- a/tests/Signal/subtle/watcher.test.ts +++ b/tests/Signal/subtle/watcher.test.ts @@ -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); + }); });