mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
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:
parent
1d4f81c8ee
commit
a67d82254f
3 changed files with 4 additions and 10 deletions
|
|
@ -16,8 +16,6 @@ export interface BaseEffectNode extends ReactiveNode {
|
|||
// (undocumented)
|
||||
fn: () => void;
|
||||
// (undocumented)
|
||||
hasRun: boolean;
|
||||
// (undocumented)
|
||||
run(): void;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue