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

Function applyDeferBlockState

packages/core/src/defer/rendering.ts:254–333  ·  view source on GitHub ↗

* Applies changes to the DOM to reflect a given state.

(
  newState: DeferBlockState,
  lDetails: LDeferBlockDetails,
  lContainer: LContainer,
  tNode: TNode,
  hostLView: LView<unknown>,
)

Source from the content-addressed store, hash-verified

252 * Applies changes to the DOM to reflect a given state.
253 */
254function applyDeferBlockState(
255 newState: DeferBlockState,
256 lDetails: LDeferBlockDetails,
257 lContainer: LContainer,
258 tNode: TNode,
259 hostLView: LView<unknown>,
260) {
261 profiler(ProfilerEvent.DeferBlockStateStart);
262
263 const stateTmplIndex = getTemplateIndexForState(newState, hostLView, tNode);
264
265 if (stateTmplIndex !== null) {
266 lDetails[DEFER_BLOCK_STATE] = newState;
267 const hostTView = hostLView[TVIEW];
268 const adjustedIndex = stateTmplIndex + HEADER_OFFSET;
269
270 // The TNode that represents a template that will activated in the defer block
271 const activeBlockTNode = getTNode(hostTView, adjustedIndex) as TContainerNode;
272
273 // There is only 1 view that can be present in an LContainer that
274 // represents a defer block, so always refer to the first one.
275 const viewIndex = 0;
276
277 removeLViewFromLContainer(lContainer, viewIndex);
278
279 let injector: Injector | undefined;
280 if (newState === DeferBlockState.Complete) {
281 // When we render a defer block in completed state, there might be
282 // newly loaded standalone components used within the block, which may
283 // import NgModules with providers. In order to make those providers
284 // available for components declared in that NgModule, we create an instance
285 // of an environment injector to host those providers and pass this injector
286 // to the logic that creates a view.
287 const tDetails = getTDeferBlockDetails(hostTView, tNode);
288 const providers = tDetails.providers;
289 if (providers && providers.length > 0) {
290 injector = createDeferBlockInjector(hostLView[INJECTOR], tDetails, providers);
291 }
292 }
293 const {dehydratedView, dehydratedViewIx} = findMatchingDehydratedViewForDeferBlock(
294 lContainer,
295 lDetails,
296 );
297
298 const embeddedLView = createAndRenderEmbeddedLView(hostLView, activeBlockTNode, null, {
299 injector,
300 dehydratedView,
301 });
302 addLViewToLContainer(
303 lContainer,
304 embeddedLView,
305 viewIndex,
306 shouldAddViewToDom(activeBlockTNode, dehydratedView),
307 );
308 markViewForRefresh(embeddedLView);
309
310 if (dehydratedViewIx > -1) {
311 // Erase dehydrated view info in a given LContainer, so that the view is not

Callers 1

Calls 13

profilerFunction · 0.90
getTemplateIndexForStateFunction · 0.90
getTNodeFunction · 0.90
getTDeferBlockDetailsFunction · 0.90
addLViewToLContainerFunction · 0.90
shouldAddViewToDomFunction · 0.90
markViewForRefreshFunction · 0.90
createDeferBlockInjectorFunction · 0.85
isArrayMethod · 0.80

Tested by

no test coverage detected