refactor(core): use version>0 instead of hasRun (#62467)

this saves a field for effect and watch nodes

PR Close #62467
This commit is contained in:
Milo 2025-07-04 08:00:40 +00:00 committed by Jessica Janiuk
parent 1d4f81c8ee
commit a67d82254f
3 changed files with 4 additions and 10 deletions

View file

@ -16,8 +16,6 @@ export interface BaseEffectNode extends ReactiveNode {
// (undocumented)
fn: () => void;
// (undocumented)
hasRun: boolean;
// (undocumented)
run(): void;
}

View file

@ -27,7 +27,6 @@ export type EffectCleanupFn = () => void;
export type EffectCleanupRegisterFn = (cleanupFn: EffectCleanupFn) => void;
export interface BaseEffectNode extends ReactiveNode {
hasRun: boolean;
fn: () => void;
destroy(): void;
cleanup(): void;
@ -40,16 +39,15 @@ export const BASE_EFFECT_NODE: Omit<BaseEffectNode, 'fn' | 'destroy' | 'cleanup'
consumerIsAlwaysLive: true,
consumerAllowSignalWrites: true,
dirty: true,
hasRun: false,
kind: 'effect',
}))();
export function runEffect(node: BaseEffectNode) {
node.dirty = false;
if (node.hasRun && !consumerPollProducersForChange(node)) {
if (node.version > 0 && !consumerPollProducersForChange(node)) {
return;
}
node.hasRun = true;
node.version++;
const prevNode = consumerBeforeComputation(node);
try {
node.cleanup();

View file

@ -56,7 +56,6 @@ export interface Watch {
[SIGNAL]: WatchNode;
}
export interface WatchNode extends ReactiveNode {
hasRun: boolean;
fn: ((onCleanup: WatchCleanupRegisterFn) => void) | null;
schedule: ((watch: Watch) => void) | null;
cleanupFn: WatchCleanupFn;
@ -111,10 +110,10 @@ export function createWatch(
}
node.dirty = false;
if (node.hasRun && !consumerPollProducersForChange(node)) {
if (node.version > 0 && !consumerPollProducersForChange(node)) {
return;
}
node.hasRun = true;
node.version++;
const prevConsumer = consumerBeforeComputation(node);
try {
@ -152,7 +151,6 @@ const WATCH_NODE: Partial<WatchNode> = /* @__PURE__ */ (() => {
node.schedule(node.ref);
}
},
hasRun: false,
cleanupFn: NOOP_CLEANUP_FN,
};
})();