Skip to content

Commit

Permalink
Quick fix for ReactScheduler type inconsistency (facebook#12828)
Browse files Browse the repository at this point in the history
**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.
  • Loading branch information
flarnie authored May 16, 2018
1 parent ef294ed commit 8227e54
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/react-scheduler/src/ReactScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
|};
Expand Down Expand Up @@ -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;
},
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -266,7 +272,7 @@ if (!ExecutionEnvironment.canUseDOM) {
};

scheduleWork = function(
callback: (deadline: Deadline) => void,
callback: FrameCallbackType,
options?: {timeout: number},
): number {
let timeoutTime = -1;
Expand Down

0 comments on commit 8227e54

Please sign in to comment.