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

Function applyDeferBlockStateWithScheduling

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

* Extends the `applyDeferBlockState` with timer-based scheduling. * This function becomes available on a page if there are defer blocks * that use `after` or `minimum` parameters in the `@loading` or * `@placeholder` blocks.

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

Source from the content-addressed store, hash-verified

323 * `@placeholder` blocks.
324 */
325function applyDeferBlockStateWithScheduling(
326 newState: DeferBlockState,
327 lDetails: LDeferBlockDetails,
328 lContainer: LContainer,
329 tNode: TNode,
330 hostLView: LView<unknown>,
331) {
332 const now = Date.now();
333 const hostTView = hostLView[TVIEW];
334 const tDetails = getTDeferBlockDetails(hostTView, tNode);
335
336 if (lDetails[STATE_IS_FROZEN_UNTIL] === null || lDetails[STATE_IS_FROZEN_UNTIL] <= now) {
337 lDetails[STATE_IS_FROZEN_UNTIL] = null;
338
339 const loadingAfter = getLoadingBlockAfter(tDetails);
340 const inLoadingAfterPhase = lDetails[LOADING_AFTER_CLEANUP_FN] !== null;
341 if (newState === DeferBlockState.Loading && loadingAfter !== null && !inLoadingAfterPhase) {
342 // Trying to render loading, but it has an `after` config,
343 // so schedule an update action after a timeout.
344 lDetails[NEXT_DEFER_BLOCK_STATE] = newState;
345 const cleanupFn = scheduleDeferBlockUpdate(
346 loadingAfter,
347 lDetails,
348 tNode,
349 lContainer,
350 hostLView,
351 );
352 lDetails[LOADING_AFTER_CLEANUP_FN] = cleanupFn;
353 } else {
354 // If we transition to a complete or an error state and there is a pending
355 // operation to render loading after a timeout - invoke a cleanup operation,
356 // which stops the timer.
357 if (newState > DeferBlockState.Loading && inLoadingAfterPhase) {
358 lDetails[LOADING_AFTER_CLEANUP_FN]!();
359 lDetails[LOADING_AFTER_CLEANUP_FN] = null;
360 lDetails[NEXT_DEFER_BLOCK_STATE] = null;
361 }
362
363 applyDeferBlockState(newState, lDetails, lContainer, tNode, hostLView);
364
365 const duration = getMinimumDurationForState(tDetails, newState);
366 if (duration !== null) {
367 lDetails[STATE_IS_FROZEN_UNTIL] = now + duration;
368 scheduleDeferBlockUpdate(duration, lDetails, tNode, lContainer, hostLView);
369 }
370 }
371 } else {
372 // We are still rendering the previous state.
373 // Update the `NEXT_DEFER_BLOCK_STATE`, which would be
374 // picked up once it's time to transition to the next state.
375 lDetails[NEXT_DEFER_BLOCK_STATE] = newState;
376 }
377}
378
379/**
380 * Schedules an update operation after a specified timeout.

Callers

nothing calls this directly

Calls 5

getTDeferBlockDetailsFunction · 0.90
getLoadingBlockAfterFunction · 0.90
scheduleDeferBlockUpdateFunction · 0.85
applyDeferBlockStateFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…