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: it should not break a computed signal to watch it before getting its value #16

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Changes from all 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
6 changes: 0 additions & 6 deletions src/graph.ts
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions tests/Signal/subtle/watcher.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
Loading
Oops, something went wrong.