( newState: DeferBlockState, tNode: TNode, lContainer: LContainer, skipTimerScheduling = false, )
| 162 | * between states via `DeferFixture.render` method. |
| 163 | */ |
| 164 | export function renderDeferBlockState( |
| 165 | newState: DeferBlockState, |
| 166 | tNode: TNode, |
| 167 | lContainer: LContainer, |
| 168 | skipTimerScheduling = false, |
| 169 | ): void { |
| 170 | const hostLView = lContainer[PARENT]; |
| 171 | const hostTView = hostLView[TVIEW]; |
| 172 | |
| 173 | // Check if this view is not destroyed. Since the loading process was async, |
| 174 | // the view might end up being destroyed by the time rendering happens. |
| 175 | if (isDestroyed(hostLView)) return; |
| 176 | |
| 177 | // Make sure this TNode belongs to TView that represents host LView. |
| 178 | ngDevMode && assertTNodeForLView(tNode, hostLView); |
| 179 | |
| 180 | const lDetails = getLDeferBlockDetails(hostLView, tNode); |
| 181 | |
| 182 | ngDevMode && assertDefined(lDetails, 'Expected a defer block state defined'); |
| 183 | |
| 184 | const currentState = lDetails[DEFER_BLOCK_STATE]; |
| 185 | |
| 186 | const ssrState = lDetails[SSR_BLOCK_STATE]; |
| 187 | if (ssrState !== null && newState < ssrState) { |
| 188 | return; // trying to render a previous state, exit |
| 189 | } |
| 190 | |
| 191 | if ( |
| 192 | isValidStateChange(currentState, newState) && |
| 193 | isValidStateChange(lDetails[NEXT_DEFER_BLOCK_STATE] ?? -1, newState) |
| 194 | ) { |
| 195 | const tDetails = getTDeferBlockDetails(hostTView, tNode); |
| 196 | // Skips scheduling on the server since it can delay the server response. |
| 197 | const needsScheduling = |
| 198 | !skipTimerScheduling && |
| 199 | (typeof ngServerMode === 'undefined' || !ngServerMode) && |
| 200 | (getLoadingBlockAfter(tDetails) !== null || |
| 201 | getMinimumDurationForState(tDetails, DeferBlockState.Loading) !== null || |
| 202 | getMinimumDurationForState(tDetails, DeferBlockState.Placeholder)); |
| 203 | |
| 204 | if (ngDevMode && needsScheduling) { |
| 205 | assertDefined( |
| 206 | applyDeferBlockStateWithSchedulingImpl, |
| 207 | 'Expected scheduling function to be defined', |
| 208 | ); |
| 209 | } |
| 210 | |
| 211 | const applyStateFn = needsScheduling |
| 212 | ? applyDeferBlockStateWithSchedulingImpl! |
| 213 | : applyDeferBlockState; |
| 214 | try { |
| 215 | applyStateFn(newState, lDetails, lContainer, tNode, hostLView); |
| 216 | } catch (error: unknown) { |
| 217 | handleUncaughtError(hostLView, error); |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 |
no test coverage detected
searching dependent graphs…