Skip to content

Commit 8227e54

Browse files
authored
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.
1 parent ef294ed commit 8227e54

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

packages/react-scheduler/src/ReactScheduler.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
// The frame rate is dynamically adjusted.
3232

3333
import type {Deadline} from 'react-reconciler';
34+
type FrameCallbackType = Deadline => void;
3435
type CallbackConfigType = {|
35-
scheduledCallback: Deadline => void,
36+
scheduledCallback: FrameCallbackType,
3637
timeoutTime: number,
3738
callbackId: number, // used for cancelling
3839
|};
@@ -69,16 +70,18 @@ if (hasNativePerformanceNow) {
6970

7071
// TODO: There's no way to cancel, because Fiber doesn't atm.
7172
let scheduleWork: (
72-
callback: (deadline: Deadline, options?: {timeout: number}) => void,
73+
callback: FrameCallbackType,
74+
options?: {timeout: number},
7375
) => number;
7476
let cancelScheduledWork: (callbackID: number) => void;
7577

7678
if (!ExecutionEnvironment.canUseDOM) {
7779
scheduleWork = function(
78-
frameCallback: (deadline: Deadline, options?: {timeout: number}) => void,
80+
callback: FrameCallbackType,
81+
options?: {timeout: number},
7982
): number {
8083
return setTimeout(() => {
81-
frameCallback({
84+
callback({
8285
timeRemaining() {
8386
return Infinity;
8487
},
@@ -132,7 +135,10 @@ if (!ExecutionEnvironment.canUseDOM) {
132135
},
133136
};
134137

135-
const safelyCallScheduledCallback = function(callback, callbackId) {
138+
const safelyCallScheduledCallback = function(
139+
callback: FrameCallbackType,
140+
callbackId: number,
141+
) {
136142
if (!registeredCallbackIds[callbackId]) {
137143
// ignore cancelled callbacks
138144
return;
@@ -266,7 +272,7 @@ if (!ExecutionEnvironment.canUseDOM) {
266272
};
267273

268274
scheduleWork = function(
269-
callback: (deadline: Deadline) => void,
275+
callback: FrameCallbackType,
270276
options?: {timeout: number},
271277
): number {
272278
let timeoutTime = -1;

0 commit comments

Comments
 (0)