MCPcopy Create free account
hub / github.com/angular/angular / phaseFn

Function phaseFn

packages/core/src/render3/reactivity/after_render_effect.ts:121–168  ·  view source on GitHub ↗
(this: AfterRenderPhaseEffectNode, previousValue?: unknown)

Source from the content-addressed store, hash-verified

119 this.sequence.scheduler.notify(NotificationSource.RenderHook);
120 },
121 phaseFn(this: AfterRenderPhaseEffectNode, previousValue?: unknown): unknown {
122 this.sequence.lastPhase = this.phase;
123
124 if (!this.dirty) {
125 return this.signal;
126 }
127
128 this.dirty = false;
129 if (this.value !== NOT_SET && !consumerPollProducersForChange(this)) {
130 // None of our producers report a change since the last time they were read, so no
131 // recomputation of our value is necessary.
132 return this.signal;
133 }
134
135 // Run any needed cleanup functions.
136 try {
137 for (const cleanupFn of this.cleanup ?? EMPTY_CLEANUP_SET) {
138 cleanupFn();
139 }
140 } finally {
141 // Even if a cleanup function errors, ensure it's cleared.
142 this.cleanup?.clear();
143 }
144
145 // Prepare to call the user's effect callback. If there was a previous phase, then it gave us
146 // its value as a `Signal`, otherwise `previousValue` will be `undefined`.
147 const args: unknown[] = [];
148 if (previousValue !== undefined) {
149 args.push(previousValue);
150 }
151 args.push(this.registerCleanupFn);
152
153 // Call the user's callback in our reactive context.
154 const prevConsumer = consumerBeforeComputation(this);
155 let newValue;
156 try {
157 newValue = this.userFn.apply(null, args as any);
158 } finally {
159 consumerAfterComputation(this, prevConsumer);
160 }
161
162 if (this.value === NOT_SET || !this.equal(this.value, newValue)) {
163 this.value = newValue;
164 this.version++;
165 }
166
167 return this.signal;
168 },
169}))();
170
171/**

Callers

nothing calls this directly

Calls 7

consumerAfterComputationFunction · 0.90
applyMethod · 0.65
cleanupFnFunction · 0.50
clearMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected