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

Function applyForeignNodes

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

Source from the content-addressed store, hash-verified

933}
934
935function applyForeignNodes(
936 renderer: Renderer,
937 action: WalkTNodeTreeAction,
938 lView: LView,
939 parent: RElement | null,
940 beforeNode: RNode | null,
941) {
942 const tView = lView[TVIEW];
943 const headTNode = tView.firstChild!;
944 const tailTNode = headTNode.next!;
945 const head = unwrapRNode(lView[headTNode.index]);
946 const tail = unwrapRNode(lView[tailTNode.index]);
947
948 const fragmentSlotIndex = tailTNode.index + 1;
949 let fragment = lView[fragmentSlotIndex] as any;
950
951 if (action === WalkTNodeTreeAction.Insert || action === WalkTNodeTreeAction.Create) {
952 if (parent !== null) {
953 if (fragment && fragment.hasChildNodes()) {
954 nativeInsertBefore(renderer, parent, fragment, beforeNode, true);
955 } else {
956 nativeInsertBefore(renderer, parent, head!, beforeNode, true);
957 nativeInsertBefore(renderer, parent, tail!, beforeNode, true);
958 }
959 }
960 } else if (action === WalkTNodeTreeAction.Detach) {
961 if (!fragment) {
962 fragment = document.createDocumentFragment();
963 lView[fragmentSlotIndex] = fragment;
964 }
965 if (head && head.parentNode === fragment) {
966 return;
967 }
968 let current: RNode | null = head;
969 while (current !== null) {
970 const next: RNode | null = current.nextSibling;
971 fragment.appendChild(current);
972 if (current === tail) break;
973 current = next;
974 }
975 }
976}
977
978/**
979 * `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