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

Function findHighestPriorityRoot

code/communication/public/app.js:13694–13757  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13692 }
13693
13694 function findHighestPriorityRoot() {
13695 var highestPriorityWork = NoWork;
13696 var highestPriorityRoot = null;
13697 if (lastScheduledRoot !== null) {
13698 var previousScheduledRoot = lastScheduledRoot;
13699 var root = firstScheduledRoot;
13700 while (root !== null) {
13701 var remainingExpirationTime = root.remainingExpirationTime;
13702 if (remainingExpirationTime === NoWork) {
13703 // This root no longer has work. Remove it from the scheduler.
13704
13705 // TODO: This check is redudant, but Flow is confused by the branch
13706 // below where we set lastScheduledRoot to null, even though we break
13707 // from the loop right after.
13708 !(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;
13709 if (root === root.nextScheduledRoot) {
13710 // This is the only root in the list.
13711 root.nextScheduledRoot = null;
13712 firstScheduledRoot = lastScheduledRoot = null;
13713 break;
13714 } else if (root === firstScheduledRoot) {
13715 // This is the first root in the list.
13716 var next = root.nextScheduledRoot;
13717 firstScheduledRoot = next;
13718 lastScheduledRoot.nextScheduledRoot = next;
13719 root.nextScheduledRoot = null;
13720 } else if (root === lastScheduledRoot) {
13721 // This is the last root in the list.
13722 lastScheduledRoot = previousScheduledRoot;
13723 lastScheduledRoot.nextScheduledRoot = firstScheduledRoot;
13724 root.nextScheduledRoot = null;
13725 break;
13726 } else {
13727 previousScheduledRoot.nextScheduledRoot = root.nextScheduledRoot;
13728 root.nextScheduledRoot = null;
13729 }
13730 root = previousScheduledRoot.nextScheduledRoot;
13731 } else {
13732 if (highestPriorityWork === NoWork || remainingExpirationTime < highestPriorityWork) {
13733 // Update the priority, if it's higher
13734 highestPriorityWork = remainingExpirationTime;
13735 highestPriorityRoot = root;
13736 }
13737 if (root === lastScheduledRoot) {
13738 break;
13739 }
13740 previousScheduledRoot = root;
13741 root = root.nextScheduledRoot;
13742 }
13743 }
13744 }
13745
13746 // If the next root is the same as the previous root, this is a nested
13747 // update. To prevent an infinite loop, increment the nested update count.
13748 var previousFlushedRoot = nextFlushedRoot;
13749 if (previousFlushedRoot !== null && previousFlushedRoot === highestPriorityRoot && highestPriorityWork === Sync) {
13750 nestedUpdateCount++;
13751 } else {

Callers 1

performWorkFunction · 0.70

Calls 1

invariantFunction · 0.70

Tested by

no test coverage detected