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

Function findHighestPriorityRoot

code/third-party/public/app.js:12892–12955  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12890 }
12891
12892 function findHighestPriorityRoot() {
12893 var highestPriorityWork = NoWork;
12894 var highestPriorityRoot = null;
12895 if (lastScheduledRoot !== null) {
12896 var previousScheduledRoot = lastScheduledRoot;
12897 var root = firstScheduledRoot;
12898 while (root !== null) {
12899 var remainingExpirationTime = root.remainingExpirationTime;
12900 if (remainingExpirationTime === NoWork) {
12901 // This root no longer has work. Remove it from the scheduler.
12902
12903 // TODO: This check is redudant, but Flow is confused by the branch
12904 // below where we set lastScheduledRoot to null, even though we break
12905 // from the loop right after.
12906 !(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;
12907 if (root === root.nextScheduledRoot) {
12908 // This is the only root in the list.
12909 root.nextScheduledRoot = null;
12910 firstScheduledRoot = lastScheduledRoot = null;
12911 break;
12912 } else if (root === firstScheduledRoot) {
12913 // This is the first root in the list.
12914 var next = root.nextScheduledRoot;
12915 firstScheduledRoot = next;
12916 lastScheduledRoot.nextScheduledRoot = next;
12917 root.nextScheduledRoot = null;
12918 } else if (root === lastScheduledRoot) {
12919 // This is the last root in the list.
12920 lastScheduledRoot = previousScheduledRoot;
12921 lastScheduledRoot.nextScheduledRoot = firstScheduledRoot;
12922 root.nextScheduledRoot = null;
12923 break;
12924 } else {
12925 previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot;
12926 root.nextScheduledRoot = null;
12927 }
12928 root = previousScheduledRoot.nextScheduledRoot;
12929 } else {
12930 if (highestPriorityWork === NoWork || remainingExpirationTime < highestPriorityWork) {
12931 // Update the priority, if it's higher
12932 highestPriorityWork = remainingExpirationTime;
12933 highestPriorityRoot = root;
12934 }
12935 if (root === lastScheduledRoot) {
12936 break;
12937 }
12938 previousScheduledRoot = root;
12939 root = root.nextScheduledRoot;
12940 }
12941 }
12942 }
12943
12944 // If the next root is the same as the previous root, this is a nested
12945 // update. To prevent an infinite loop, increment the nested update count.
12946 var previousFlushedRoot = nextFlushedRoot;
12947 if (previousFlushedRoot !== null && previousFlushedRoot === highestPriorityRoot && highestPriorityWork === Sync) {
12948 nestedUpdateCount++;
12949 } else {

Callers 1

performWorkFunction · 0.70

Calls 1

invariantFunction · 0.70

Tested by

no test coverage detected