/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { CONTAINER_HEADER_OFFSET, DEHYDRATED_VIEWS } from '../render3/interfaces/container'; import { isLContainer, isLView } from '../render3/interfaces/type_checks'; import { HEADER_OFFSET, HOST, PARENT, RENDERER, TVIEW } from '../render3/interfaces/view'; import { nativeRemoveNode } from '../render3/node_manipulation'; import { EMPTY_ARRAY } from '../util/empty'; import { validateSiblingNodeExists } from './error_handling'; import { NUM_ROOT_NODES } from './interfaces'; import { getLNodeForHydration } from './utils'; /** * Removes all dehydrated views from a given LContainer: * both in internal data structure, as well as removing * corresponding DOM nodes that belong to that dehydrated view. */ export function removeDehydratedViews(lContainer) { const views = lContainer[DEHYDRATED_VIEWS] ?? []; const parentLView = lContainer[PARENT]; const renderer = parentLView[RENDERER]; for (const view of views) { removeDehydratedView(view, renderer); ngDevMode && ngDevMode.dehydratedViewsRemoved++; } // Reset the value to an empty array to indicate that no // further processing of dehydrated views is needed for // this view container (i.e. do not trigger the lookup process // once again in case a `ViewContainerRef` is created later). lContainer[DEHYDRATED_VIEWS] = EMPTY_ARRAY; } /** * Helper function to remove all nodes from a dehydrated view. */ function removeDehydratedView(dehydratedView, renderer) { let nodesRemoved = 0; let currentRNode = dehydratedView.firstChild; if (currentRNode) { const numNodes = dehydratedView.data[NUM_ROOT_NODES]; while (nodesRemoved < numNodes) { ngDevMode && validateSiblingNodeExists(currentRNode); const nextSibling = currentRNode.nextSibling; nativeRemoveNode(renderer, currentRNode, false); currentRNode = nextSibling; nodesRemoved++; } } } /** * Walks over all views within this LContainer invokes dehydrated views * cleanup function for each one. */ function cleanupLContainer(lContainer) { removeDehydratedViews(lContainer); for (let i = CONTAINER_HEADER_OFFSET; i < lContainer.length; i++) { cleanupLView(lContainer[i]); } } /** * Walks over `LContainer`s and components registered within * this LView and invokes dehydrated views cleanup function for each one. */ function cleanupLView(lView) { const tView = lView[TVIEW]; for (let i = HEADER_OFFSET; i < tView.bindingStartIndex; i++) { if (isLContainer(lView[i])) { const lContainer = lView[i]; cleanupLContainer(lContainer); } else if (Array.isArray(lView[i])) { // This is a component, enter the `cleanupLView` recursively. cleanupLView(lView[i]); } } } /** * Walks over all views registered within the ApplicationRef and removes * all dehydrated views from all `LContainer`s along the way. */ export function cleanupDehydratedViews(appRef) { const viewRefs = appRef._views; for (const viewRef of viewRefs) { const lNode = getLNodeForHydration(viewRef); // An `lView` might be `null` if a `ViewRef` represents // an embedded view (not a component view). if (lNode !== null && lNode[HOST] !== null) { if (isLView(lNode)) { cleanupLView(lNode); } else { // Cleanup in the root component view const componentLView = lNode[HOST]; cleanupLView(componentLView); // Cleanup in all views within this view container cleanupLContainer(lNode); } ngDevMode && ngDevMode.dehydratedViewsCleanupRuns++; } } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xlYW51cC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvcmUvc3JjL2h5ZHJhdGlvbi9jbGVhbnVwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUdILE9BQU8sRUFBQyx1QkFBdUIsRUFBRSxnQkFBZ0IsRUFBYSxNQUFNLGlDQUFpQyxDQUFDO0FBR3RHLE9BQU8sRUFBQyxZQUFZLEVBQUUsT0FBTyxFQUFDLE1BQU0sbUNBQW1DLENBQUM7QUFDeEUsT0FBTyxFQUFDLGFBQWEsRUFBRSxJQUFJLEVBQVMsTUFBTSxFQUFFLFFBQVEsRUFBRSxLQUFLLEVBQUMsTUFBTSw0QkFBNEIsQ0FBQztBQUMvRixPQUFPLEVBQUMsZ0JBQWdCLEVBQUMsTUFBTSw4QkFBOEIsQ0FBQztBQUM5RCxPQUFPLEVBQUMsV0FBVyxFQUFDLE1BQU0sZUFBZSxDQUFDO0FBRTFD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