Skip to content

Commit d28d827

Browse files
Merge pull request #16 from divdavem/watchBug
fix: it should not break a computed signal to watch it before getting its value
2 parents 670d062 + 48a9763 commit d28d827

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/graph.ts

-6
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,6 @@ export function producerIncrementEpoch(): void {
275275
* Ensure this producer's `version` is up-to-date.
276276
*/
277277
export function producerUpdateValueVersion(node: ReactiveNode): void {
278-
if (consumerIsLive(node) && !node.dirty) {
279-
// A live consumer will be marked dirty by producers, so a clean state means that its version
280-
// is guaranteed to be up-to-date.
281-
return;
282-
}
283-
284278
if (!node.dirty && node.lastCleanEpoch === epoch) {
285279
// Even non-live consumers can skip polling if they previously found themselves to be clean at
286280
// the current epoch, since their dependencies could not possibly have changed (such a change

tests/Signal/subtle/watcher.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,16 @@ describe('Watcher', () => {
178178
signal.set(1);
179179
expect(mockGetPending).toBeCalled();
180180
});
181+
182+
it('should not break a computed signal to watch it before getting its value', () => {
183+
const signal = new Signal.State(0);
184+
const computedSignal = new Signal.Computed(() => signal.get());
185+
const watcher = new Signal.subtle.Watcher(() => {});
186+
expect(computedSignal.get()).toBe(0);
187+
signal.set(1);
188+
watcher.watch(computedSignal);
189+
expect(computedSignal.get()).toBe(1);
190+
watcher.unwatch(computedSignal);
191+
expect(computedSignal.get()).toBe(1);
192+
});
181193
});

0 commit comments

Comments
 (0)