@samitouri / QOS-React / commits / 9c77ffb444

Dedup conditional in ReactScheduler (#12680)

**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 :)

Flarnie Marchan committed Apr 24, 2018 at 08:54 UTC 9c77ffb444598c32c8f92c8d79e406959a10445b
1 file changed +7 -21
packages/react-scheduler/src/ReactScheduler.js
+7 -21
@@ -100,27 +100,13 @@ if (!ExecutionEnvironment.canUseDOM) {
100 let previousFrameTime = 33;
101 let activeFrameTime = 33;
102
103 - let frameDeadlineObject;
104 - if (hasNativePerformanceNow) {
105 - frameDeadlineObject = {
106 - didTimeout: false,
107 - timeRemaining() {
108 - // We assume that if we have a performance timer that the rAF callback
109 - // gets a performance timer value. Not sure if this is always true.
110 - const remaining = frameDeadline - performance.now();
111 - return remaining > 0 ? remaining : 0;
112 - },
113 - };
114 - } else {
115 - frameDeadlineObject = {
116 - didTimeout: false,
117 - timeRemaining() {
118 - // Fallback to Date.now()
119 - const remaining = frameDeadline - Date.now();
120 - return remaining > 0 ? remaining : 0;
121 - },
122 - };
123 - }
103 + const frameDeadlineObject = {
104 + didTimeout: false,
105 + timeRemaining() {
106 + const remaining = frameDeadline - now();
107 + return remaining > 0 ? remaining : 0;
108 + },
109 + };
110
111 // We use the postMessage trick to defer idle work until after the repaint.
112 const messageKey =