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

Function cleanUpView

packages/core/src/render3/node_manipulation.ts:338–385  ·  view source on GitHub ↗

* Calls onDestroys hooks for all directives and pipes in a given view and then removes all * listeners. Listeners are removed as the last step so events delivered in the onDestroys hooks * can be propagated to @Output listeners. * * @param tView `TView` for the `LView` to clean up. * @param lVi

(tView: TView, lView: LView)

Source from the content-addressed store, hash-verified

336 * @param lView The LView to clean up
337 */
338function cleanUpView(tView: TView, lView: LView): void {
339 if (isDestroyed(lView)) {
340 return;
341 }
342
343 const prevConsumer = setActiveConsumer(null);
344 try {
345 // Usually the Attached flag is removed when the view is detached from its parent, however
346 // if it's a root view, the flag won't be unset hence why we're also removing on destroy.
347 lView[FLAGS] &= ~LViewFlags.Attached;
348
349 // Mark the LView as destroyed *before* executing the onDestroy hooks. An onDestroy hook
350 // runs arbitrary user code, which could include its own `viewRef.destroy()` (or similar). If
351 // We don't flag the view as destroyed before the hooks, this could lead to an infinite loop.
352 // This also aligns with the ViewEngine behavior. It also means that the onDestroy hook is
353 // really more of an "afterDestroy" hook if you think about it.
354 lView[FLAGS] |= LViewFlags.Destroyed;
355
356 lView[REACTIVE_TEMPLATE_CONSUMER] && consumerDestroy(lView[REACTIVE_TEMPLATE_CONSUMER]);
357
358 executeOnDestroys(tView, lView);
359 processCleanups(tView, lView);
360 // For component views only, the local renderer is destroyed at clean up time.
361 if (lView[TVIEW].type === TViewType.Component) {
362 lView[RENDERER].destroy();
363 }
364
365 const declarationContainer = lView[DECLARATION_LCONTAINER];
366 // we are dealing with an embedded view that is still inserted into a container
367 if (declarationContainer !== null && isLContainer(lView[PARENT])) {
368 // and this is a projected view
369 if (declarationContainer !== lView[PARENT]) {
370 detachMovedView(declarationContainer, lView);
371 }
372
373 // For embedded views still attached to a container: remove query result from this view.
374 const lQueries = lView[QUERIES];
375 if (lQueries !== null) {
376 lQueries.detachView(tView);
377 }
378 }
379
380 // Unregister the view once everything else has been cleaned up.
381 unregisterLView(lView);
382 } finally {
383 setActiveConsumer(prevConsumer);
384 }
385}
386
387/** Removes listeners and unsubscribes from output subscriptions */
388function processCleanups(tView: TView, lView: LView): void {

Callers 1

destroyViewTreeFunction · 0.85

Calls 10

isDestroyedFunction · 0.90
setActiveConsumerFunction · 0.90
consumerDestroyFunction · 0.90
isLContainerFunction · 0.90
unregisterLViewFunction · 0.90
executeOnDestroysFunction · 0.85
processCleanupsFunction · 0.85
detachMovedViewFunction · 0.85
destroyMethod · 0.65
detachViewMethod · 0.65

Tested by

no test coverage detected