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

Function applyForeignNodes

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

Source from the content-addressed store, hash-verified

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