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

Function cleanUpView

packages/core/src/render3/node_manipulation.ts:335–382  ·  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

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