MCPcopy Index your code
hub / github.com/angular/angular / deferBlockFinder

Function deferBlockFinder

packages/core/src/render3/util/control_flow.ts:68–158  ·  view source on GitHub ↗
({
  node,
  lView,
  tView,
  slotIdx,
}: ControlFlowBlockViewFinderConfig)

Source from the content-addressed store, hash-verified

66 * @returns
67 */
68const deferBlockFinder: ControlFlowBlockViewFinder = ({
69 node,
70 lView,
71 tView,
72 slotIdx,
73}: ControlFlowBlockViewFinderConfig) => {
74 const slot = lView[slotIdx];
75 if (!isLContainer(slot)) {
76 return null;
77 }
78
79 const lContainer = slot;
80
81 // An LContainer may represent an instance of a defer block, in which case
82 // we store it as a result. Otherwise, keep iterating over LContainer views and
83 // look for defer blocks.
84 const isLast = slotIdx === tView.bindingStartIndex - 1;
85
86 if (!isLast) {
87 const tNode = tView.data[slotIdx] as TNode;
88 const tDetails = getTDeferBlockDetails(tView, tNode);
89
90 if (isTDeferBlockDetails(tDetails)) {
91 const native = getNativeByTNode(tNode, lView);
92 const lDetails = getLDeferBlockDetails(lView, tNode);
93
94 // The LView from `getLContext` might be the view the element is placed in.
95 // Filter out defer blocks that aren't inside the specified root node.
96 if (!node.contains(native as Node)) {
97 return null;
98 }
99
100 const viewInjector = lView[INJECTOR];
101 const registry = viewInjector.get(DEHYDRATED_BLOCK_REGISTRY, null, {optional: true});
102
103 const renderedLView = getRendererLView(lContainer);
104 const rootNodes: Node[] = [];
105 const hydrationState = inferHydrationState(tDetails, lDetails, registry);
106
107 if (renderedLView !== null) {
108 collectNativeNodes(
109 renderedLView[TVIEW],
110 renderedLView,
111 renderedLView[TVIEW].firstChild,
112 rootNodes,
113 );
114 } else if (hydrationState === 'dehydrated') {
115 // We'll find the number of root nodes in the transfer state and
116 // collect that number of elements that precede the defer block comment node.
117
118 const transferState = viewInjector.get(TransferState);
119 const deferBlockParents = transferState.get(NGH_DEFER_BLOCKS_KEY, {});
120
121 const deferId = lDetails[SSR_UNIQUE_ID]!;
122 const deferData = deferBlockParents[deferId];
123 const numberOfRootNodes = deferData[NUM_ROOT_NODES];
124
125 let collectedNodeCount = 0;

Callers

nothing calls this directly

Calls 11

isLContainerFunction · 0.90
getTDeferBlockDetailsFunction · 0.90
isTDeferBlockDetailsFunction · 0.90
getNativeByTNodeFunction · 0.90
getLDeferBlockDetailsFunction · 0.90
collectNativeNodesFunction · 0.90
getRendererLViewFunction · 0.85
inferHydrationStateFunction · 0.85
stringifyStateFunction · 0.85
containsMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…