From da4e51e4d600bb74e87c2eee7a07c0074fe3bec8 Mon Sep 17 00:00:00 2001 From: Flarnie Marchan Date: Fri, 4 May 2018 09:02:07 -0700 Subject: [PATCH] Rename methods exposed by `ReactScheduler` **what is the change?:** `rIC` -> `scheduleSerialCallback` We will later expose a second method called `scheduleDeferredCallback`, for different priority levels. `cIC` -> `cancelScheduledCallback` This method can be used to cancel callbacks scheduled at either serial or deferred priority. **why make this change?:** Originally this module contained a polyfill for `requestIdleCallback` and `cancelIdleCallback` but we are changing the behavior so it's no longer just a polyfill. The new names are more semantic and distinguish this from the original polyfill functionality. **test plan:** Ran the tests --- packages/react-art/src/ReactART.js | 2 +- packages/react-dom/src/client/ReactDOM.js | 4 ++-- packages/react-scheduler/src/ReactScheduler.js | 18 +++++++++--------- .../src/__tests__/ReactScheduler-test.js | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/react-art/src/ReactART.js b/packages/react-art/src/ReactART.js index 04478434e8b66..e1e9ac8563c91 100644 --- a/packages/react-art/src/ReactART.js +++ b/packages/react-art/src/ReactART.js @@ -468,7 +468,7 @@ const ARTRenderer = ReactFiberReconciler({ return emptyObject; }, - scheduleDeferredCallback: ReactScheduler.rIC, + scheduleDeferredCallback: ReactScheduler.scheduleSerialCallback, shouldSetTextContent(type, props) { return ( diff --git a/packages/react-dom/src/client/ReactDOM.js b/packages/react-dom/src/client/ReactDOM.js index 82032f1d1d212..030f736ac000d 100644 --- a/packages/react-dom/src/client/ReactDOM.js +++ b/packages/react-dom/src/client/ReactDOM.js @@ -984,8 +984,8 @@ const DOMRenderer = ReactFiberReconciler({ }, }, - scheduleDeferredCallback: ReactScheduler.rIC, - cancelDeferredCallback: ReactScheduler.cIC, + scheduleDeferredCallback: ReactScheduler.scheduleSerialCallback, + cancelDeferredCallback: ReactScheduler.cancelScheduledCallback, }); ReactGenericBatching.injection.injectRenderer(DOMRenderer); diff --git a/packages/react-scheduler/src/ReactScheduler.js b/packages/react-scheduler/src/ReactScheduler.js index b15e5f4428ee5..63818f20c3711 100644 --- a/packages/react-scheduler/src/ReactScheduler.js +++ b/packages/react-scheduler/src/ReactScheduler.js @@ -63,13 +63,13 @@ if (hasNativePerformanceNow) { } // TODO: There's no way to cancel, because Fiber doesn't atm. -let rIC: ( +let scheduleSerialCallback: ( callback: (deadline: Deadline, options?: {timeout: number}) => void, ) => number; -let cIC: (callbackID: number) => void; +let cancelScheduledCallback: (callbackID: number) => void; if (!ExecutionEnvironment.canUseDOM) { - rIC = function( + scheduleSerialCallback = function( frameCallback: (deadline: Deadline, options?: {timeout: number}) => void, ): number { return setTimeout(() => { @@ -81,7 +81,7 @@ if (!ExecutionEnvironment.canUseDOM) { }); }); }; - cIC = function(timeoutID: number) { + cancelScheduledCallback = function(timeoutID: number) { clearTimeout(timeoutID); }; } else { @@ -186,7 +186,7 @@ if (!ExecutionEnvironment.canUseDOM) { } }; - rIC = function( + scheduleSerialCallback = function( callback: (deadline: Deadline) => void, options?: {timeout: number}, ): number { @@ -199,19 +199,19 @@ if (!ExecutionEnvironment.canUseDOM) { if (!isAnimationFrameScheduled) { // If rAF didn't already schedule one, we need to schedule a frame. // TODO: If this rAF doesn't materialize because the browser throttles, we - // might want to still have setTimeout trigger rIC as a backup to ensure - // that we keep performing work. + // might want to still have setTimeout trigger scheduleSerialCallback as a + // backup to ensure that we keep performing work. isAnimationFrameScheduled = true; requestAnimationFrame(animationTick); } return 0; }; - cIC = function() { + cancelScheduledCallback = function() { scheduledRICCallback = null; isIdleScheduled = false; timeoutTime = -1; }; } -export {now, rIC, cIC}; +export {now, scheduleSerialCallback, cancelScheduledCallback}; diff --git a/packages/react-scheduler/src/__tests__/ReactScheduler-test.js b/packages/react-scheduler/src/__tests__/ReactScheduler-test.js index 1ed60b0fb318e..caa5b00ff5d46 100644 --- a/packages/react-scheduler/src/__tests__/ReactScheduler-test.js +++ b/packages/react-scheduler/src/__tests__/ReactScheduler-test.js @@ -41,10 +41,10 @@ describe('ReactScheduler', () => { ReactScheduler = require('react-scheduler'); }); - it('rIC calls the callback within the frame when not blocked', () => { - const {rIC} = ReactScheduler; + it('scheduleSerialCallback calls the callback within the frame when not blocked', () => { + const {scheduleSerialCallback} = ReactScheduler; const cb = jest.fn(); - rIC(cb); + scheduleSerialCallback(cb); jest.runAllTimers(); expect(cb.mock.calls.length).toBe(1); // should have ... TODO details on what we expect