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

Function applyToElementOrContainer

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

* NOTE: for performance reasons, the possible actions are inlined within the function instead of * being passed as an argument.

(
  action: WalkTNodeTreeAction,
  renderer: Renderer,
  injector: Injector,
  parent: RElement | null,
  lNodeToHandle: RNode | LContainer | LView,
  tNode: TNode,
  beforeNode?: RNode | null,
  parentLView?: LView,
)

Source from the content-addressed store, hash-verified

114 * being passed as an argument.
115 */
116function applyToElementOrContainer(
117 action: WalkTNodeTreeAction,
118 renderer: Renderer,
119 injector: Injector,
120 parent: RElement | null,
121 lNodeToHandle: RNode | LContainer | LView,
122 tNode: TNode,
123 beforeNode?: RNode | null,
124 parentLView?: LView,
125) {
126 // If this slot was allocated for a text node dynamically created by i18n, the text node itself
127 // won't be created until i18nApply() in the update block, so this node should be skipped.
128 // For more info, see "ICU expressions should work inside an ngTemplateOutlet inside an ngFor"
129 // in `i18n_spec.ts`.
130 if (lNodeToHandle != null) {
131 let lContainer: LContainer | undefined;
132 let isComponent = false;
133 // We are expecting an RNode, but in the case of a component or LContainer the `RNode` is
134 // wrapped in an array which needs to be unwrapped. We need to know if it is a component and if
135 // it has LContainer so that we can process all of those cases appropriately.
136 if (isLContainer(lNodeToHandle)) {
137 lContainer = lNodeToHandle;
138 } else if (isLView(lNodeToHandle)) {
139 isComponent = true;
140 ngDevMode && assertDefined(lNodeToHandle[HOST], 'HOST must be defined for a component LView');
141 lNodeToHandle = lNodeToHandle[HOST]!;
142 }
143 const rNode: RNode = unwrapRNode(lNodeToHandle);
144 if (action === WalkTNodeTreeAction.Create && parent !== null) {
145 maybeQueueEnterAnimation(parentLView, parent, tNode, injector);
146 if (beforeNode == null) {
147 nativeAppendChild(renderer, parent, rNode);
148 } else {
149 nativeInsertBefore(renderer, parent, rNode, beforeNode || null, true);
150 }
151 } else if (action === WalkTNodeTreeAction.Insert && parent !== null) {
152 maybeQueueEnterAnimation(parentLView, parent, tNode, injector);
153 nativeInsertBefore(renderer, parent, rNode, beforeNode || null, true);
154 cancelLeavingNodes(tNode, rNode as HTMLElement, parentLView);
155 } else if (action === WalkTNodeTreeAction.Detach) {
156 if (parentLView?.[ANIMATIONS]?.leave?.has(tNode.index)) {
157 trackLeavingNodes(tNode, rNode as HTMLElement, parentLView);
158 }
159 reusedNodes.delete(rNode as HTMLElement);
160 runLeaveAnimationsWithCallback(
161 parentLView,
162 tNode,
163 injector,
164 (nodeHasLeaveAnimations: boolean) => {
165 if (reusedNodes.has(rNode as HTMLElement)) {
166 reusedNodes.delete(rNode as HTMLElement);
167 return;
168 }
169 // the nodeHasLeaveAnimations indicates to the renderer that the element needs to
170 // be removed synchronously and sets the requireSynchronousElementRemoval flag in
171 // the renderer.
172 nativeRemoveNode(renderer, rNode, isComponent, nodeHasLeaveAnimations);
173 },

Callers 3

applyNodesFunction · 0.85
applyProjectionRecursiveFunction · 0.85
applyContainerFunction · 0.85

Calls 14

isLContainerFunction · 0.90
isLViewFunction · 0.90
assertDefinedFunction · 0.90
unwrapRNodeFunction · 0.90
maybeQueueEnterAnimationFunction · 0.90
nativeAppendChildFunction · 0.90
nativeInsertBeforeFunction · 0.90
cancelLeavingNodesFunction · 0.90
trackLeavingNodesFunction · 0.90
nativeRemoveNodeFunction · 0.90
applyContainerFunction · 0.85

Tested by

no test coverage detected