MCPcopy Index your code
hub / github.com/microsoft/SandDance / ensureRootIsScheduled

Function ensureRootIsScheduled

docs/external/js/react-dom.development.js:21474–21538  ·  view source on GitHub ↗
(root)

Source from the content-addressed store, hash-verified

21472
21473
21474 function ensureRootIsScheduled(root) {
21475 var lastExpiredTime = root.lastExpiredTime;
21476
21477 if (lastExpiredTime !== NoWork) {
21478 // Special case: Expired work should flush synchronously.
21479 root.callbackExpirationTime = Sync;
21480 root.callbackPriority = ImmediatePriority;
21481 root.callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
21482 return;
21483 }
21484
21485 var expirationTime = getNextRootExpirationTimeToWorkOn(root);
21486 var existingCallbackNode = root.callbackNode;
21487
21488 if (expirationTime === NoWork) {
21489 // There's nothing to work on.
21490 if (existingCallbackNode !== null) {
21491 root.callbackNode = null;
21492 root.callbackExpirationTime = NoWork;
21493 root.callbackPriority = NoPriority;
21494 }
21495
21496 return;
21497 } // TODO: If this is an update, we already read the current time. Pass the
21498 // time as an argument.
21499
21500
21501 var currentTime = requestCurrentTimeForUpdate();
21502 var priorityLevel = inferPriorityFromExpirationTime(currentTime, expirationTime); // If there's an existing render task, confirm it has the correct priority and
21503 // expiration time. Otherwise, we'll cancel it and schedule a new one.
21504
21505 if (existingCallbackNode !== null) {
21506 var existingCallbackPriority = root.callbackPriority;
21507 var existingCallbackExpirationTime = root.callbackExpirationTime;
21508
21509 if ( // Callback must have the exact same expiration time.
21510 existingCallbackExpirationTime === expirationTime && // Callback must have greater or equal priority.
21511 existingCallbackPriority >= priorityLevel) {
21512 // Existing callback is sufficient.
21513 return;
21514 } // Need to schedule a new task.
21515 // TODO: Instead of scheduling a new task, we should be able to change the
21516 // priority of the existing one.
21517
21518
21519 cancelCallback(existingCallbackNode);
21520 }
21521
21522 root.callbackExpirationTime = expirationTime;
21523 root.callbackPriority = priorityLevel;
21524 var callbackNode;
21525
21526 if (expirationTime === Sync) {
21527 // Sync React callbacks are scheduled on a special internal queue
21528 callbackNode = scheduleSyncCallback(performSyncWorkOnRoot.bind(null, root));
21529 } else {
21530 callbackNode = scheduleCallback(priorityLevel, performConcurrentWorkOnRoot.bind(null, root), // Compute a task timeout based on the expiration time. This also affects
21531 // ordering because tasks are processed in timeout order.

Callers 9

scheduleUpdateOnFiberFunction · 0.85
performSyncWorkOnRootFunction · 0.85
commitRootImplFunction · 0.85
captureCommitPhaseErrorFunction · 0.85
pingSuspendedRootFunction · 0.85
retryTimedOutBoundaryFunction · 0.85

Calls 8

scheduleSyncCallbackFunction · 0.85
cancelCallbackFunction · 0.85
scheduleCallbackFunction · 0.85
expirationTimeToMsFunction · 0.85
nowFunction · 0.50

Tested by

no test coverage detected