MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / findHighestPriorityRoot

Function findHighestPriorityRoot

code/new-context-api/public/app.js:13020–13083  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13018 }
13019
13020 function findHighestPriorityRoot() {
13021 var highestPriorityWork = NoWork;
13022 var highestPriorityRoot = null;
13023 if (lastScheduledRoot !== null) {
13024 var previousScheduledRoot = lastScheduledRoot;
13025 var root = firstScheduledRoot;
13026 while (root !== null) {
13027 var remainingExpirationTime = root.remainingExpirationTime;
13028 if (remainingExpirationTime === NoWork) {
13029 // This root no longer has work. Remove it from the scheduler.
13030
13031 // TODO: This check is redudant, but Flow is confused by the branch
13032 // below where we set lastScheduledRoot to null, even though we break
13033 // from the loop right after.
13034 !(previousScheduledRoot !== null && lastScheduledRoot !== null) ? invariant(false, 'Should have a previous and last root. This error is likely caused by a bug in React. Please file an issue.') : void 0;
13035 if (root === root.nextScheduledRoot) {
13036 // This is the only root in the list.
13037 root.nextScheduledRoot = null;
13038 firstScheduledRoot = lastScheduledRoot = null;
13039 break;
13040 } else if (root === firstScheduledRoot) {
13041 // This is the first root in the list.
13042 var next = root.nextScheduledRoot;
13043 firstScheduledRoot = next;
13044 lastScheduledRoot.nextScheduledRoot = next;
13045 root.nextScheduledRoot = null;
13046 } else if (root === lastScheduledRoot) {
13047 // This is the last root in the list.
13048 lastScheduledRoot = previousScheduledRoot;
13049 lastScheduledRoot.nextScheduledRoot = firstScheduledRoot;
13050 root.nextScheduledRoot = null;
13051 break;
13052 } else {
13053 previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot;
13054 root.nextScheduledRoot = null;
13055 }
13056 root = previousScheduledRoot.nextScheduledRoot;
13057 } else {
13058 if (highestPriorityWork === NoWork || remainingExpirationTime < highestPriorityWork) {
13059 // Update the priority, if it's higher
13060 highestPriorityWork = remainingExpirationTime;
13061 highestPriorityRoot = root;
13062 }
13063 if (root === lastScheduledRoot) {
13064 break;
13065 }
13066 previousScheduledRoot = root;
13067 root = root.nextScheduledRoot;
13068 }
13069 }
13070 }
13071
13072 // If the next root is the same as the previous root, this is a nested
13073 // update. To prevent an infinite loop, increment the nested update count.
13074 var previousFlushedRoot = nextFlushedRoot;
13075 if (previousFlushedRoot !== null && previousFlushedRoot === highestPriorityRoot && highestPriorityWork === Sync) {
13076 nestedUpdateCount++;
13077 } else {

Callers 1

performWorkFunction · 0.70

Calls 1

invariantFunction · 0.70

Tested by

no test coverage detected