Skip to content

Commit

Permalink
Dedup conditional in ReactScheduler (facebook#12680)
Browse files Browse the repository at this point in the history
**what is the change?:**
We had a condition to set either 'performance.now' or 'Date.now' as the
'now' function.

Then later we had another conditional checking again if
'performance.now' was supported, and using it if so, otherwise falling
back to 'Date.now'.

More efficient to just use the 'now' shortcut defined above.

**why make this change?:**
Fewer lines, clearer code.

**test plan:**
Now that we have tests we can run them :)
  • Loading branch information
flarnie authored Apr 24, 2018
1 parent 09a14ea commit 9c77ffb
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions packages/react-scheduler/src/ReactScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,13 @@ if (!ExecutionEnvironment.canUseDOM) {
let previousFrameTime = 33;
let activeFrameTime = 33;

let frameDeadlineObject;
if (hasNativePerformanceNow) {
frameDeadlineObject = {
didTimeout: false,
timeRemaining() {
// We assume that if we have a performance timer that the rAF callback
// gets a performance timer value. Not sure if this is always true.
const remaining = frameDeadline - performance.now();
return remaining > 0 ? remaining : 0;
},
};
} else {
frameDeadlineObject = {
didTimeout: false,
timeRemaining() {
// Fallback to Date.now()
const remaining = frameDeadline - Date.now();
return remaining > 0 ? remaining : 0;
},
};
}
const frameDeadlineObject = {
didTimeout: false,
timeRemaining() {
const remaining = frameDeadline - now();
return remaining > 0 ? remaining : 0;
},
};

// We use the postMessage trick to defer idle work until after the repaint.
const messageKey =
Expand Down

0 comments on commit 9c77ffb

Please sign in to comment.