@samitouri / QOS-React / commits / 8227e54ccf

Quick fix for ReactScheduler type inconsistency (#12828)

**what is the change?:** In some cases we had defined the 'callback' as taking two arguments, when really we meant to indicate the second argument passed to 'scheduleWork'. **why make this change?:** For correctness and to unblock something @gaearon is working on. A bit surprised Flow didn't catch this in the first place. **test plan:** Ran tests, flow, lint.

Flarnie Marchan committed May 16, 2018 at 08:07 UTC 8227e54ccf32f47e4c6bf5f30d08f84b8fed455d
1 file changed +12 -6
packages/react-scheduler/src/ReactScheduler.js
+12 -6
@@ -31,8 +31,9 @@
31 // The frame rate is dynamically adjusted.
32
33 import type {Deadline} from 'react-reconciler';
34 +type FrameCallbackType = Deadline => void;
35 type CallbackConfigType = {|
35 - scheduledCallback: Deadline => void,
36 + scheduledCallback: FrameCallbackType,
37 timeoutTime: number,
38 callbackId: number, // used for cancelling
39 |};
@@ -69,16 +70,18 @@ if (hasNativePerformanceNow) {
70
71 // TODO: There's no way to cancel, because Fiber doesn't atm.
72 let scheduleWork: (
72 - callback: (deadline: Deadline, options?: {timeout: number}) => void,
73 + callback: FrameCallbackType,
74 + options?: {timeout: number},
75 ) => number;
76 let cancelScheduledWork: (callbackID: number) => void;
77
78 if (!ExecutionEnvironment.canUseDOM) {
79 scheduleWork = function(
78 - frameCallback: (deadline: Deadline, options?: {timeout: number}) => void,
80 + callback: FrameCallbackType,
81 + options?: {timeout: number},
82 ): number {
83 return setTimeout(() => {
81 - frameCallback({
84 + callback({
85 timeRemaining() {
86 return Infinity;
87 },
@@ -132,7 +135,10 @@ if (!ExecutionEnvironment.canUseDOM) {
135 },
136 };
137
135 - const safelyCallScheduledCallback = function(callback, callbackId) {
138 + const safelyCallScheduledCallback = function(
139 + callback: FrameCallbackType,
140 + callbackId: number,
141 + ) {
142 if (!registeredCallbackIds[callbackId]) {
143 // ignore cancelled callbacks
144 return;
@@ -266,7 +272,7 @@ if (!ExecutionEnvironment.canUseDOM) {
272 };
273
274 scheduleWork = function(
269 - callback: (deadline: Deadline) => void,
275 + callback: FrameCallbackType,
276 options?: {timeout: number},
277 ): number {
278 let timeoutTime = -1;