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

Function applyForeignNodes

packages/core/src/render3/node_manipulation.ts:911–952  ·  view source on GitHub ↗
(
  renderer: Renderer,
  action: WalkTNodeTreeAction,
  lView: LView,
  parent: RElement | null,
  beforeNode: RNode | null,
)

Source from the content-addressed store, hash-verified

909}
910
911function applyForeignNodes(
912 renderer: Renderer,
913 action: WalkTNodeTreeAction,
914 lView: LView,
915 parent: RElement | null,
916 beforeNode: RNode | null,
917) {
918 const tView = lView[TVIEW];
919 const headTNode = tView.firstChild!;
920 const tailTNode = headTNode.next!;
921 const head = unwrapRNode(lView[headTNode.index]);
922 const tail = unwrapRNode(lView[tailTNode.index]);
923
924 const fragmentSlotIndex = tailTNode.index + 1;
925 let fragment = lView[fragmentSlotIndex] as any;
926
927 if (action === WalkTNodeTreeAction.Insert || action === WalkTNodeTreeAction.Create) {
928 if (parent !== null) {
929 if (fragment && fragment.hasChildNodes()) {
930 nativeInsertBefore(renderer, parent, fragment, beforeNode, true);
931 } else {
932 nativeInsertBefore(renderer, parent, head!, beforeNode, true);
933 nativeInsertBefore(renderer, parent, tail!, beforeNode, true);
934 }
935 }
936 } else if (action === WalkTNodeTreeAction.Detach) {
937 if (!fragment) {
938 fragment = document.createDocumentFragment();
939 lView[fragmentSlotIndex] = fragment;
940 }
941 if (head && head.parentNode === fragment) {
942 return;
943 }
944 let current: RNode | null = head;
945 while (current !== null) {
946 const next: RNode | null = current.nextSibling;
947 fragment.appendChild(current);
948 if (current === tail) break;
949 current = next;
950 }
951 }
952}
953
954/**
955 * `applyProjection` performs operation on the projection.

Callers 1

applyViewFunction · 0.85

Calls 3

unwrapRNodeFunction · 0.90
nativeInsertBeforeFunction · 0.90
appendChildMethod · 0.65

Tested by

no test coverage detected