package.esm2022.src.hydration.views.mjs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Angular - the core framework
/**
* @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.dev/license
*/
import { DEHYDRATED_VIEWS } from '../render3/interfaces/container';
import { removeDehydratedViews } from './cleanup';
import { MULTIPLIER, NUM_ROOT_NODES, TEMPLATE_ID, } from './interfaces';
import { siblingAfter } from './node_lookup_utils';
/**
* Given a current DOM node and a serialized information about the views
* in a container, walks over the DOM structure, collecting the list of
* dehydrated views.
*/
export function locateDehydratedViewsInContainer(currentRNode, serializedViews) {
const dehydratedViews = [];
for (const serializedView of serializedViews) {
// Repeats a view multiple times as needed, based on the serialized information
// (for example, for *ngFor-produced views).
for (let i = 0; i < (serializedView[MULTIPLIER] ?? 1); i++) {
const view = {
data: serializedView,
firstChild: null,
};
if (serializedView[NUM_ROOT_NODES] > 0) {
// Keep reference to the first node in this view,
// so it can be accessed while invoking template instructions.
view.firstChild = currentRNode;
// Move over to the next node after this view, which can
// either be a first node of the next view or an anchor comment
// node after the last view in a container.
currentRNode = siblingAfter(serializedView[NUM_ROOT_NODES], currentRNode);
}
dehydratedViews.push(view);
}
}
return [currentRNode, dehydratedViews];
}
/**
* Reference to a function that searches for a matching dehydrated views
* stored on a given lContainer.
* Returns `null` by default, when hydration is not enabled.
*/
let _findMatchingDehydratedViewImpl = () => null;
/**
* Retrieves the next dehydrated view from the LContainer and verifies that
* it matches a given template id (from the TView that was used to create this
* instance of a view). If the id doesn't match, that means that we are in an
* unexpected state and can not complete the reconciliation process. Thus,
* all dehydrated views from this LContainer are removed (including corresponding
* DOM nodes) and the rendering is performed as if there were no dehydrated views
* in this container.
*/
function findMatchingDehydratedViewImpl(lContainer, template) {
const views = lContainer[DEHYDRATED_VIEWS];
if (!template || views === null || views.length === 0) {
return null;
}
const view = views[0];
// Verify whether the first dehydrated view in the container matches
// the template id passed to this function (that originated from a TView
// that was used to create an instance of an embedded or component views.
if (view.data[TEMPLATE_ID] === template) {
// If the template id matches - extract the first view and return it.
return views.shift();
}
else {
// Otherwise, we are at the state when reconciliation can not be completed,
// thus we remove all dehydrated views within this container (remove them
// from internal data structures as well as delete associated elements from
// the DOM tree).
removeDehydratedViews(lContainer);
return null;
}
}
export function enableFindMatchingDehydratedViewImpl() {
_findMatchingDehydratedViewImpl = findMatchingDehydratedViewImpl;
}
export function findMatchingDehydratedView(lContainer, template) {
return _findMatchingDehydratedViewImpl(lContainer, template);
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmlld3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9jb3JlL3NyYy9oeWRyYXRpb24vdmlld3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUFDLGdCQUFnQixFQUFhLE1BQU0saUNBQWlDLENBQUM7QUFHN0UsT0FBTyxFQUFDLHFCQUFxQixFQUFDLE1BQU0sV0FBVyxDQUFDO0FBQ2hELE9BQU8sRUFFTCxVQUFVLEVBQ1YsY0FBYyxFQUVkLFdBQVcsR0FDWixNQUFNLGNBQWMsQ0FBQztBQUN0QixPQUFPLEVBQUMsWUFBWSxFQUFDLE1BQU0scUJBQXFCLENBQUM7QUFFakQ7Ozs7R0FJRztBQUNILE1BQU0sVUFBVSxnQ0FBZ0MsQ0FDOUMsWUFBbUIsRUFDbkIsZUFBMEM7SUFFMUMsTUFBTSxlQUFlLEdBQThCLEVBQUUsQ0FBQztJQUN0RCxLQUFLLE1BQU0sY0FBYyxJQUFJLGVBQWUsRUFBRSxDQUFDO1FBQzdDLCtFQUErRTtRQUMvRSw0Q0FBNEM7UUFDNUMsS0FBSyxJQUFJLENBQUMsR0FBRyxDQUFDLEVBQ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