Skip to content

Commit

Permalink
fix: Resetting visited nodes of an effect
Browse files Browse the repository at this point in the history
  • Loading branch information
mnasyrov committed Oct 25, 2023
1 parent e8e1882 commit 03dc2e4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
7 changes: 0 additions & 7 deletions src/core/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { collectChanges, flushMicrotasks } from '../test/testUtils';
import { objectEquals } from './common';
import { compute } from './compute';
import { effect } from './effect';
import { SIGNAL_RUNTIME } from './runtime';
import { signal } from './signal';
import {
createStore,
Expand Down Expand Up @@ -184,9 +183,6 @@ describe('Concurrent Store updates', () => {
});

it('should trigger a listener in case a state was changed', async () => {
// FIXME
SIGNAL_RUNTIME.reset();

const store = signal<{
bar: number;
foo: number;
Expand All @@ -207,9 +203,6 @@ describe('Concurrent Store updates', () => {
});

it('should preserve order of pending updates during applying the current update', async () => {
// FIXME
SIGNAL_RUNTIME.reset();

const store = signal<{
x: number;
y: number;
Expand Down
9 changes: 9 additions & 0 deletions src/core/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export class Watch implements EffectNode, Runnable {
return;
}

dump('RUN watch ' + this.id);

const prevEffect = SIGNAL_RUNTIME.setCurrentEffect(this);

const isChanged =
Expand All @@ -100,6 +102,12 @@ export class Watch implements EffectNode, Runnable {

if (!isChanged) {
SIGNAL_RUNTIME.setCurrentEffect(prevEffect);

if (!prevEffect) {
dump('SIGNAL_RUNTIME.resetVisitedComputedNodes();');
SIGNAL_RUNTIME.resetVisitedComputedNodes();
}

return;
}

Expand All @@ -120,6 +128,7 @@ export class Watch implements EffectNode, Runnable {
);

if (!prevEffect) {
dump('SIGNAL_RUNTIME.resetVisitedComputedNodes();');
SIGNAL_RUNTIME.resetVisitedComputedNodes();
}

Expand Down
24 changes: 13 additions & 11 deletions src/test/dump.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function dump(message: string, value?: any): void {
// const clone =
// value === undefined ? undefined : JSON.parse(JSON.stringify(value));
//
// if (clone === undefined) {
// console.log(`!!! ${message}`);
// } else {
// console.log(`!!! ${message}`, clone);
// }
}
export const dump =
process.env.DEBUG_DUMP === 'true'
? (message: string, value?: any): void => {
const clone =
value === undefined ? undefined : JSON.parse(JSON.stringify(value));

if (clone === undefined) {
console.log(`!!! ${message}`);
} else {
console.log(`!!! ${message}`, clone);
}
}
: () => undefined;

0 comments on commit 03dc2e4

Please sign in to comment.