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

Function applyDeferBlockStateWithScheduling

packages/core/src/defer/rendering.ts:341–393  ·  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

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

Callers

nothing calls this directly

Calls 6

getTDeferBlockDetailsFunction · 0.90
getLoadingBlockAfterFunction · 0.90
scheduleDeferBlockUpdateFunction · 0.85
applyDeferBlockStateFunction · 0.85
nowMethod · 0.80

Tested by

no test coverage detected