From 8227e54ccf32f47e4c6bf5f30d08f84b8fed455d Mon Sep 17 00:00:00 2001 From: Flarnie Marchan Date: Wed, 16 May 2018 08:07:42 -0700 Subject: [PATCH] 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. --- packages/react-scheduler/src/ReactScheduler.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/react-scheduler/src/ReactScheduler.js b/packages/react-scheduler/src/ReactScheduler.js index 023a81a635..3d60a64e06 100644 --- a/packages/react-scheduler/src/ReactScheduler.js +++ b/packages/react-scheduler/src/ReactScheduler.js @@ -31,8 +31,9 @@ // The frame rate is dynamically adjusted. import type {Deadline} from 'react-reconciler'; +type FrameCallbackType = Deadline => void; type CallbackConfigType = {| - scheduledCallback: Deadline => void, + scheduledCallback: FrameCallbackType, timeoutTime: number, callbackId: number, // used for cancelling |}; @@ -69,16 +70,18 @@ if (hasNativePerformanceNow) { // TODO: There's no way to cancel, because Fiber doesn't atm. let scheduleWork: ( - callback: (deadline: Deadline, options?: {timeout: number}) => void, + callback: FrameCallbackType, + options?: {timeout: number}, ) => number; let cancelScheduledWork: (callbackID: number) => void; if (!ExecutionEnvironment.canUseDOM) { scheduleWork = function( - frameCallback: (deadline: Deadline, options?: {timeout: number}) => void, + callback: FrameCallbackType, + options?: {timeout: number}, ): number { return setTimeout(() => { - frameCallback({ + callback({ timeRemaining() { return Infinity; }, @@ -132,7 +135,10 @@ if (!ExecutionEnvironment.canUseDOM) { }, }; - const safelyCallScheduledCallback = function(callback, callbackId) { + const safelyCallScheduledCallback = function( + callback: FrameCallbackType, + callbackId: number, + ) { if (!registeredCallbackIds[callbackId]) { // ignore cancelled callbacks return; @@ -266,7 +272,7 @@ if (!ExecutionEnvironment.canUseDOM) { }; scheduleWork = function( - callback: (deadline: Deadline) => void, + callback: FrameCallbackType, options?: {timeout: number}, ): number { let timeoutTime = -1;