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