@samitouri / QOS-React-2 / commits / 9a110ebd8c

Cleaned up 'schedule' API wrt interactions and subscriber ref: (#13561)

* Removed 'private' ref methods from UMD forwarding API * Replaced getters with exported constants since they were no longer referenced for UMD forwarding

Brian Vaughn committed Sep 5, 2018 at 07:29 UTC 9a110ebd8ce9f808a246a3c7f7b0cc13f78f13a6
11 files changed +50 -95
fixtures/tracking/script.js
+1 -3
@@ -48,8 +48,6 @@ function checkSchedulerTrackingAPI() {
48 runTest(document.getElementById('checkSchedulerTrackingAPI'), () => {
49 if (
50 typeof ScheduleTracking === 'undefined' ||
51 - typeof ScheduleTracking.__getInteractionsRef !== 'function' ||
52 - typeof ScheduleTracking.__getSubscriberRef !== 'function' ||
51 typeof ScheduleTracking.unstable_clear !== 'function' ||
52 typeof ScheduleTracking.unstable_getCurrent !== 'function' ||
53 typeof ScheduleTracking.unstable_getThreadID !== 'function' ||
@@ -62,7 +60,7 @@ function checkSchedulerTrackingAPI() {
60 try {
61 let interactionsSet;
62 ScheduleTracking.unstable_track('test', 123, () => {
65 - interactionsSet = ScheduleTracking.__getInteractionsRef().current;
63 + interactionsSet = ScheduleTracking.unstable_getCurrent();
64 });
65 if (interactionsSet.size !== 1) {
66 throw null;
packages/react-reconciler/src/ReactFiberScheduler.js
+15 -26
@@ -10,13 +10,9 @@
10 import type {Fiber} from './ReactFiber';
11 import type {Batch, FiberRoot} from './ReactFiberRoot';
12 import type {ExpirationTime} from './ReactFiberExpirationTime';
13 -import type {
14 - Interaction,
15 - InteractionsRef,
16 - SubscriberRef,
17 -} from 'schedule/src/Tracking';
13 +import type {Interaction} from 'schedule/src/Tracking';
14
19 -import {__getInteractionsRef, __getSubscriberRef} from 'schedule/tracking';
15 +import {__interactionsRef, __subscriberRef} from 'schedule/tracking';
16 import {
17 invokeGuardedCallback,
18 hasCaughtError,
@@ -166,13 +162,6 @@ export type Thenable = {
162
163 const {ReactCurrentOwner} = ReactSharedInternals;
164
169 -let interactionsRef: InteractionsRef = (null: any);
170 -let subscriberRef: SubscriberRef = (null: any);
171 -if (enableSchedulerTracking) {
172 - interactionsRef = __getInteractionsRef();
173 - subscriberRef = __getSubscriberRef();
174 -}
175 -
165 let didWarnAboutStateTransition;
166 let didWarnSetStateChildContext;
167 let warnAboutUpdateOnUnmounted;
@@ -570,8 +559,8 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
559 if (enableSchedulerTracking) {
560 // Restore any pending interactions at this point,
561 // So that cascading work triggered during the render phase will be accounted for.
573 - prevInteractions = interactionsRef.current;
574 - interactionsRef.current = root.memoizedInteractions;
562 + prevInteractions = __interactionsRef.current;
563 + __interactionsRef.current = root.memoizedInteractions;
564
565 // We are potentially finished with the current batch of interactions.
566 // So we should clear them out of the pending interaction map.
@@ -766,12 +755,12 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
755 onCommit(root, earliestRemainingTimeAfterCommit);
756
757 if (enableSchedulerTracking) {
769 - interactionsRef.current = prevInteractions;
758 + __interactionsRef.current = prevInteractions;
759
760 let subscriber;
761
762 try {
774 - subscriber = subscriberRef.current;
763 + subscriber = __subscriberRef.current;
764 if (subscriber !== null && root.memoizedInteractions.size > 0) {
765 const threadID = computeThreadID(
766 committedExpirationTime,
@@ -1176,8 +1165,8 @@ function renderRoot(
1165 if (enableSchedulerTracking) {
1166 // We're about to start new tracked work.
1167 // Restore pending interactions so cascading work triggered during the render phase will be accounted for.
1179 - prevInteractions = interactionsRef.current;
1180 - interactionsRef.current = root.memoizedInteractions;
1168 + prevInteractions = __interactionsRef.current;
1169 + __interactionsRef.current = root.memoizedInteractions;
1170 }
1171
1172 // Check if we're starting from a fresh stack, or if we're resuming from
@@ -1220,7 +1209,7 @@ function renderRoot(
1209 root.memoizedInteractions = interactions;
1210
1211 if (interactions.size > 0) {
1223 - const subscriber = subscriberRef.current;
1212 + const subscriber = __subscriberRef.current;
1213 if (subscriber !== null) {
1214 const threadID = computeThreadID(
1215 expirationTime,
@@ -1305,7 +1294,7 @@ function renderRoot(
1294
1295 if (enableSchedulerTracking) {
1296 // Tracked work is done for now; restore the previous interactions.
1308 - interactionsRef.current = prevInteractions;
1297 + __interactionsRef.current = prevInteractions;
1298 }
1299
1300 // We're done performing work. Time to clean up.
@@ -1614,13 +1603,13 @@ function retrySuspendedRoot(
1603 if (rootExpirationTime !== NoWork) {
1604 if (enableSchedulerTracking) {
1605 // Restore previous interactions so that new work is associated with them.
1617 - let prevInteractions = interactionsRef.current;
1618 - interactionsRef.current = root.memoizedInteractions;
1606 + let prevInteractions = __interactionsRef.current;
1607 + __interactionsRef.current = root.memoizedInteractions;
1608 // Because suspense timeouts do not decrement the interaction count,
1609 // Continued suspense work should also not increment the count.
1610 storeInteractionsForExpirationTime(root, rootExpirationTime, false);
1611 requestWork(root, rootExpirationTime);
1623 - interactionsRef.current = prevInteractions;
1612 + __interactionsRef.current = prevInteractions;
1613 } else {
1614 requestWork(root, rootExpirationTime);
1615 }
@@ -1687,7 +1676,7 @@ function storeInteractionsForExpirationTime(
1676 return;
1677 }
1678
1690 - const interactions = interactionsRef.current;
1679 + const interactions = __interactionsRef.current;
1680 if (interactions.size > 0) {
1681 const pendingInteractions = root.pendingInteractionMap.get(expirationTime);
1682 if (pendingInteractions != null) {
@@ -1710,7 +1699,7 @@ function storeInteractionsForExpirationTime(
1699 }
1700 }
1701
1713 - const subscriber = subscriberRef.current;
1702 + const subscriber = __subscriberRef.current;
1703 if (subscriber !== null) {
1704 const threadID = computeThreadID(
1705 expirationTime,
packages/react/src/ReactSharedInternals.js
+4 -4
@@ -12,8 +12,8 @@ import {
12 unstable_scheduleWork,
13 } from 'schedule';
14 import {
15 - __getInteractionsRef,
16 - __getSubscriberRef,
15 + __interactionsRef,
16 + __subscriberRef,
17 unstable_clear,
18 unstable_getCurrent,
19 unstable_getThreadID,
@@ -44,8 +44,8 @@ if (__UMD__) {
44 unstable_scheduleWork,
45 },
46 ScheduleTracking: {
47 - __getInteractionsRef,
48 - __getSubscriberRef,
47 + __interactionsRef,
48 + __subscriberRef,
49 unstable_clear,
50 unstable_getCurrent,
51 unstable_getThreadID,
packages/schedule/npm/umd/schedule-tracking.development.js
-16
@@ -16,20 +16,6 @@
16 ? define(['react'], factory) // eslint-disable-line no-undef
17 : (global.ScheduleTracking = factory(global));
18 })(this, function(global) {
19 - function __getInteractionsRef() {
20 - return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.__getInteractionsRef.apply(
21 - this,
22 - arguments
23 - );
24 - }
25 -
26 - function __getSubscriberRef() {
27 - return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.__getSubscriberRef.apply(
28 - this,
29 - arguments
30 - );
31 - }
32 -
19 function unstable_clear() {
20 return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_clear.apply(
21 this,
@@ -82,8 +68,6 @@
68 }
69
70 return Object.freeze({
85 - __getInteractionsRef: __getInteractionsRef,
86 - __getSubscriberRef: __getSubscriberRef,
71 unstable_clear: unstable_clear,
72 unstable_getCurrent: unstable_getCurrent,
73 unstable_getThreadID: unstable_getThreadID,
packages/schedule/npm/umd/schedule-tracking.production.min.js
-16
@@ -16,20 +16,6 @@
16 ? define(['react'], factory) // eslint-disable-line no-undef
17 : (global.ScheduleTracking = factory(global));
18 })(this, function(global) {
19 - function __getInteractionsRef() {
20 - return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.__getInteractionsRef.apply(
21 - this,
22 - arguments
23 - );
24 - }
25 -
26 - function __getSubscriberRef() {
27 - return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.__getSubscriberRef.apply(
28 - this,
29 - arguments
30 - );
31 - }
32 -
19 function unstable_clear() {
20 return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_clear.apply(
21 this,
@@ -82,8 +68,6 @@
68 }
69
70 return Object.freeze({
85 - __getInteractionsRef: __getInteractionsRef,
86 - __getSubscriberRef: __getSubscriberRef,
71 unstable_clear: unstable_clear,
72 unstable_getCurrent: unstable_getCurrent,
73 unstable_getThreadID: unstable_getThreadID,
packages/schedule/src/Tracking.js
+1 -9
@@ -79,15 +79,7 @@ if (enableSchedulerTracking) {
79 };
80 }
81
82 -// These values are exported for libraries with advanced use cases (i.e. React).
83 -// They should not typically be accessed directly.
84 -export function __getInteractionsRef(): InteractionsRef {
85 - return interactionsRef;
86 -}
87 -
88 -export function __getSubscriberRef(): SubscriberRef {
89 - return subscriberRef;
90 -}
82 +export {interactionsRef as __interactionsRef, subscriberRef as __subscriberRef};
83
84 export function unstable_clear(callback: Function): any {
85 if (!enableSchedulerTracking) {
packages/schedule/src/TrackingSubscriptions.js
+4 -6
@@ -7,15 +7,13 @@
7 * @flow
8 */
9
10 -import type {Interaction, Subscriber, SubscriberRef} from './Tracking';
10 +import type {Interaction, Subscriber} from './Tracking';
11
12 import {enableSchedulerTracking} from 'shared/ReactFeatureFlags';
13 -import {__getSubscriberRef} from 'schedule/tracking';
13 +import {__subscriberRef} from 'schedule/tracking';
14
15 -let subscriberRef: SubscriberRef = (null: any);
15 let subscribers: Set<Subscriber> = (null: any);
16 if (enableSchedulerTracking) {
18 - subscriberRef = __getSubscriberRef();
17 subscribers = new Set();
18 }
19
@@ -24,7 +22,7 @@ export function unstable_subscribe(subscriber: Subscriber): void {
22 subscribers.add(subscriber);
23
24 if (subscribers.size === 1) {
27 - subscriberRef.current = {
25 + __subscriberRef.current = {
26 onInteractionScheduledWorkCompleted,
27 onInteractionTracked,
28 onWorkCanceled,
@@ -41,7 +39,7 @@ export function unstable_unsubscribe(subscriber: Subscriber): void {
39 subscribers.delete(subscriber);
40
41 if (subscribers.size === 0) {
44 - subscriberRef.current = null;
42 + __subscriberRef.current = null;
43 }
44 }
45 }
packages/schedule/src/__tests__/ScheduleUMDBundle-test.internal.js
+12 -2
@@ -16,10 +16,20 @@ describe('Scheduling UMD bundle', () => {
16 jest.resetModules();
17 });
18
19 + function filterPrivateKeys(name) {
20 + return !name.startsWith('_');
21 + }
22 +
23 function validateForwardedAPIs(api, forwardedAPIs) {
20 - const apiKeys = Object.keys(api).sort();
24 + const apiKeys = Object.keys(api)
25 + .filter(filterPrivateKeys)
26 + .sort();
27 forwardedAPIs.forEach(forwardedAPI => {
22 - expect(Object.keys(forwardedAPI).sort()).toEqual(apiKeys);
28 + expect(
29 + Object.keys(forwardedAPI)
30 + .filter(filterPrivateKeys)
31 + .sort(),
32 + ).toEqual(apiKeys);
33 });
34 }
35
packages/schedule/src/__tests__/Tracking-test.internal.js
+4 -4
@@ -299,11 +299,11 @@ describe('Tracking', () => {
299
300 it('should expose the current set of interactions to be externally manipulated', () => {
301 SchedulerTracking.unstable_track('outer event', currentTime, () => {
302 - expect(SchedulerTracking.__getInteractionsRef().current).toBe(
302 + expect(SchedulerTracking.__interactionsRef.current).toBe(
303 SchedulerTracking.unstable_getCurrent(),
304 );
305
306 - SchedulerTracking.__getInteractionsRef().current = new Set([
306 + SchedulerTracking.__interactionsRef.current = new Set([
307 {name: 'override event'},
308 ]);
309
@@ -315,7 +315,7 @@ describe('Tracking', () => {
315
316 it('should expose a subscriber ref to be externally manipulated', () => {
317 SchedulerTracking.unstable_track('outer event', currentTime, () => {
318 - expect(SchedulerTracking.__getSubscriberRef()).toEqual({
318 + expect(SchedulerTracking.__subscriberRef).toEqual({
319 current: null,
320 });
321 });
@@ -368,7 +368,7 @@ describe('Tracking', () => {
368
369 describe('advanced integration', () => {
370 it('should not create unnecessary objects', () => {
371 - expect(SchedulerTracking.__getInteractionsRef()).toBe(null);
371 + expect(SchedulerTracking.__interactionsRef).toBe(null);
372 });
373 });
374 });
packages/schedule/src/__tests__/TrackingSubscriptions-test.internal.js
+5 -5
@@ -112,15 +112,15 @@ describe('TrackingSubscriptions', () => {
112 it('should lazily subscribe to tracking and unsubscribe again if there are no external subscribers', () => {
113 loadModules({enableSchedulerTracking: true, autoSubscribe: false});
114
115 - expect(SchedulerTracking.__getSubscriberRef().current).toBe(null);
115 + expect(SchedulerTracking.__subscriberRef.current).toBe(null);
116 SchedulerTracking.unstable_subscribe(firstSubscriber);
117 - expect(SchedulerTracking.__getSubscriberRef().current).toBeDefined();
117 + expect(SchedulerTracking.__subscriberRef.current).toBeDefined();
118 SchedulerTracking.unstable_subscribe(secondSubscriber);
119 - expect(SchedulerTracking.__getSubscriberRef().current).toBeDefined();
119 + expect(SchedulerTracking.__subscriberRef.current).toBeDefined();
120 SchedulerTracking.unstable_unsubscribe(secondSubscriber);
121 - expect(SchedulerTracking.__getSubscriberRef().current).toBeDefined();
121 + expect(SchedulerTracking.__subscriberRef.current).toBeDefined();
122 SchedulerTracking.unstable_unsubscribe(firstSubscriber);
123 - expect(SchedulerTracking.__getSubscriberRef().current).toBe(null);
123 + expect(SchedulerTracking.__subscriberRef.current).toBe(null);
124 });
125
126 describe('error handling', () => {
packages/shared/forks/ScheduleTracking.umd.js
+4 -4
@@ -12,8 +12,8 @@ import React from 'react';
12 const ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
13
14 const {
15 - __getInteractionsRef,
16 - __getSubscriberRef,
15 + __interactionsRef,
16 + __subscriberRef,
17 unstable_clear,
18 unstable_getCurrent,
19 unstable_getThreadID,
@@ -24,8 +24,8 @@ const {
24 } = ReactInternals.ScheduleTracking;
25
26 export {
27 - __getInteractionsRef,
28 - __getSubscriberRef,
27 + __interactionsRef,
28 + __subscriberRef,
29 unstable_clear,
30 unstable_getCurrent,
31 unstable_getThreadID,