Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed ref-getter methods from "schedule" API #13561

Merged
merged 1 commit into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions fixtures/tracking/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ function checkSchedulerTrackingAPI() {
runTest(document.getElementById('checkSchedulerTrackingAPI'), () => {
if (
typeof ScheduleTracking === 'undefined' ||
typeof ScheduleTracking.__getInteractionsRef !== 'function' ||
typeof ScheduleTracking.__getSubscriberRef !== 'function' ||
typeof ScheduleTracking.unstable_clear !== 'function' ||
typeof ScheduleTracking.unstable_getCurrent !== 'function' ||
typeof ScheduleTracking.unstable_getThreadID !== 'function' ||
Expand All @@ -62,7 +60,7 @@ function checkSchedulerTrackingAPI() {
try {
let interactionsSet;
ScheduleTracking.unstable_track('test', 123, () => {
interactionsSet = ScheduleTracking.__getInteractionsRef().current;
interactionsSet = ScheduleTracking.unstable_getCurrent();
});
if (interactionsSet.size !== 1) {
throw null;
Expand Down
41 changes: 15 additions & 26 deletions packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@
import type {Fiber} from './ReactFiber';
import type {Batch, FiberRoot} from './ReactFiberRoot';
import type {ExpirationTime} from './ReactFiberExpirationTime';
import type {
Interaction,
InteractionsRef,
SubscriberRef,
} from 'schedule/src/Tracking';
import type {Interaction} from 'schedule/src/Tracking';

import {__getInteractionsRef, __getSubscriberRef} from 'schedule/tracking';
import {__interactionsRef, __subscriberRef} from 'schedule/tracking';
import {
invokeGuardedCallback,
hasCaughtError,
Expand Down Expand Up @@ -166,13 +162,6 @@ export type Thenable = {

const {ReactCurrentOwner} = ReactSharedInternals;

let interactionsRef: InteractionsRef = (null: any);
let subscriberRef: SubscriberRef = (null: any);
if (enableSchedulerTracking) {
interactionsRef = __getInteractionsRef();
subscriberRef = __getSubscriberRef();
}

let didWarnAboutStateTransition;
let didWarnSetStateChildContext;
let warnAboutUpdateOnUnmounted;
Expand Down Expand Up @@ -570,8 +559,8 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
if (enableSchedulerTracking) {
// Restore any pending interactions at this point,
// So that cascading work triggered during the render phase will be accounted for.
prevInteractions = interactionsRef.current;
interactionsRef.current = root.memoizedInteractions;
prevInteractions = __interactionsRef.current;
__interactionsRef.current = root.memoizedInteractions;

// We are potentially finished with the current batch of interactions.
// So we should clear them out of the pending interaction map.
Expand Down Expand Up @@ -766,12 +755,12 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
onCommit(root, earliestRemainingTimeAfterCommit);

if (enableSchedulerTracking) {
interactionsRef.current = prevInteractions;
__interactionsRef.current = prevInteractions;

let subscriber;

try {
subscriber = subscriberRef.current;
subscriber = __subscriberRef.current;
if (subscriber !== null && root.memoizedInteractions.size > 0) {
const threadID = computeThreadID(
committedExpirationTime,
Expand Down Expand Up @@ -1176,8 +1165,8 @@ function renderRoot(
if (enableSchedulerTracking) {
// We're about to start new tracked work.
// Restore pending interactions so cascading work triggered during the render phase will be accounted for.
prevInteractions = interactionsRef.current;
interactionsRef.current = root.memoizedInteractions;
prevInteractions = __interactionsRef.current;
__interactionsRef.current = root.memoizedInteractions;
}

// Check if we're starting from a fresh stack, or if we're resuming from
Expand Down Expand Up @@ -1220,7 +1209,7 @@ function renderRoot(
root.memoizedInteractions = interactions;

if (interactions.size > 0) {
const subscriber = subscriberRef.current;
const subscriber = __subscriberRef.current;
if (subscriber !== null) {
const threadID = computeThreadID(
expirationTime,
Expand Down Expand Up @@ -1305,7 +1294,7 @@ function renderRoot(

if (enableSchedulerTracking) {
// Tracked work is done for now; restore the previous interactions.
interactionsRef.current = prevInteractions;
__interactionsRef.current = prevInteractions;
}

// We're done performing work. Time to clean up.
Expand Down Expand Up @@ -1614,13 +1603,13 @@ function retrySuspendedRoot(
if (rootExpirationTime !== NoWork) {
if (enableSchedulerTracking) {
// Restore previous interactions so that new work is associated with them.
let prevInteractions = interactionsRef.current;
interactionsRef.current = root.memoizedInteractions;
let prevInteractions = __interactionsRef.current;
__interactionsRef.current = root.memoizedInteractions;
// Because suspense timeouts do not decrement the interaction count,
// Continued suspense work should also not increment the count.
storeInteractionsForExpirationTime(root, rootExpirationTime, false);
requestWork(root, rootExpirationTime);
interactionsRef.current = prevInteractions;
__interactionsRef.current = prevInteractions;
} else {
requestWork(root, rootExpirationTime);
}
Expand Down Expand Up @@ -1687,7 +1676,7 @@ function storeInteractionsForExpirationTime(
return;
}

const interactions = interactionsRef.current;
const interactions = __interactionsRef.current;
if (interactions.size > 0) {
const pendingInteractions = root.pendingInteractionMap.get(expirationTime);
if (pendingInteractions != null) {
Expand All @@ -1710,7 +1699,7 @@ function storeInteractionsForExpirationTime(
}
}

const subscriber = subscriberRef.current;
const subscriber = __subscriberRef.current;
if (subscriber !== null) {
const threadID = computeThreadID(
expirationTime,
Expand Down
8 changes: 4 additions & 4 deletions packages/react/src/ReactSharedInternals.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
unstable_scheduleWork,
} from 'schedule';
import {
__getInteractionsRef,
__getSubscriberRef,
__interactionsRef,
__subscriberRef,
unstable_clear,
unstable_getCurrent,
unstable_getThreadID,
Expand Down Expand Up @@ -44,8 +44,8 @@ if (__UMD__) {
unstable_scheduleWork,
},
ScheduleTracking: {
__getInteractionsRef,
__getSubscriberRef,
__interactionsRef,
__subscriberRef,
unstable_clear,
unstable_getCurrent,
unstable_getThreadID,
Expand Down
16 changes: 0 additions & 16 deletions packages/schedule/npm/umd/schedule-tracking.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,6 @@
? define(['react'], factory) // eslint-disable-line no-undef
: (global.ScheduleTracking = factory(global));
})(this, function(global) {
function __getInteractionsRef() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.__getInteractionsRef.apply(
this,
arguments
);
}

function __getSubscriberRef() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.__getSubscriberRef.apply(
this,
arguments
);
}

function unstable_clear() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_clear.apply(
this,
Expand Down Expand Up @@ -82,8 +68,6 @@
}

return Object.freeze({
__getInteractionsRef: __getInteractionsRef,
__getSubscriberRef: __getSubscriberRef,
unstable_clear: unstable_clear,
unstable_getCurrent: unstable_getCurrent,
unstable_getThreadID: unstable_getThreadID,
Expand Down
16 changes: 0 additions & 16 deletions packages/schedule/npm/umd/schedule-tracking.production.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,6 @@
? define(['react'], factory) // eslint-disable-line no-undef
: (global.ScheduleTracking = factory(global));
})(this, function(global) {
function __getInteractionsRef() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.__getInteractionsRef.apply(
this,
arguments
);
}

function __getSubscriberRef() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.__getSubscriberRef.apply(
this,
arguments
);
}

function unstable_clear() {
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ScheduleTracking.unstable_clear.apply(
this,
Expand Down Expand Up @@ -82,8 +68,6 @@
}

return Object.freeze({
__getInteractionsRef: __getInteractionsRef,
__getSubscriberRef: __getSubscriberRef,
unstable_clear: unstable_clear,
unstable_getCurrent: unstable_getCurrent,
unstable_getThreadID: unstable_getThreadID,
Expand Down
10 changes: 1 addition & 9 deletions packages/schedule/src/Tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,7 @@ if (enableSchedulerTracking) {
};
}

// These values are exported for libraries with advanced use cases (i.e. React).
// They should not typically be accessed directly.
export function __getInteractionsRef(): InteractionsRef {
return interactionsRef;
}

export function __getSubscriberRef(): SubscriberRef {
return subscriberRef;
}
export {interactionsRef as __interactionsRef, subscriberRef as __subscriberRef};

export function unstable_clear(callback: Function): any {
if (!enableSchedulerTracking) {
Expand Down
10 changes: 4 additions & 6 deletions packages/schedule/src/TrackingSubscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
* @flow
*/

import type {Interaction, Subscriber, SubscriberRef} from './Tracking';
import type {Interaction, Subscriber} from './Tracking';

import {enableSchedulerTracking} from 'shared/ReactFeatureFlags';
import {__getSubscriberRef} from 'schedule/tracking';
import {__subscriberRef} from 'schedule/tracking';

let subscriberRef: SubscriberRef = (null: any);
let subscribers: Set<Subscriber> = (null: any);
if (enableSchedulerTracking) {
subscriberRef = __getSubscriberRef();
subscribers = new Set();
}

Expand All @@ -24,7 +22,7 @@ export function unstable_subscribe(subscriber: Subscriber): void {
subscribers.add(subscriber);

if (subscribers.size === 1) {
subscriberRef.current = {
__subscriberRef.current = {
onInteractionScheduledWorkCompleted,
onInteractionTracked,
onWorkCanceled,
Expand All @@ -41,7 +39,7 @@ export function unstable_unsubscribe(subscriber: Subscriber): void {
subscribers.delete(subscriber);

if (subscribers.size === 0) {
subscriberRef.current = null;
__subscriberRef.current = null;
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions packages/schedule/src/__tests__/ScheduleUMDBundle-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@ describe('Scheduling UMD bundle', () => {
jest.resetModules();
});

function filterPrivateKeys(name) {
return !name.startsWith('_');
}

function validateForwardedAPIs(api, forwardedAPIs) {
const apiKeys = Object.keys(api).sort();
const apiKeys = Object.keys(api)
.filter(filterPrivateKeys)
.sort();
forwardedAPIs.forEach(forwardedAPI => {
expect(Object.keys(forwardedAPI).sort()).toEqual(apiKeys);
expect(
Object.keys(forwardedAPI)
.filter(filterPrivateKeys)
.sort(),
).toEqual(apiKeys);
});
}

Expand Down
8 changes: 4 additions & 4 deletions packages/schedule/src/__tests__/Tracking-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,11 @@ describe('Tracking', () => {

it('should expose the current set of interactions to be externally manipulated', () => {
SchedulerTracking.unstable_track('outer event', currentTime, () => {
expect(SchedulerTracking.__getInteractionsRef().current).toBe(
expect(SchedulerTracking.__interactionsRef.current).toBe(
SchedulerTracking.unstable_getCurrent(),
);

SchedulerTracking.__getInteractionsRef().current = new Set([
SchedulerTracking.__interactionsRef.current = new Set([
{name: 'override event'},
]);

Expand All @@ -315,7 +315,7 @@ describe('Tracking', () => {

it('should expose a subscriber ref to be externally manipulated', () => {
SchedulerTracking.unstable_track('outer event', currentTime, () => {
expect(SchedulerTracking.__getSubscriberRef()).toEqual({
expect(SchedulerTracking.__subscriberRef).toEqual({
current: null,
});
});
Expand Down Expand Up @@ -368,7 +368,7 @@ describe('Tracking', () => {

describe('advanced integration', () => {
it('should not create unnecessary objects', () => {
expect(SchedulerTracking.__getInteractionsRef()).toBe(null);
expect(SchedulerTracking.__interactionsRef).toBe(null);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ describe('TrackingSubscriptions', () => {
it('should lazily subscribe to tracking and unsubscribe again if there are no external subscribers', () => {
loadModules({enableSchedulerTracking: true, autoSubscribe: false});

expect(SchedulerTracking.__getSubscriberRef().current).toBe(null);
expect(SchedulerTracking.__subscriberRef.current).toBe(null);
SchedulerTracking.unstable_subscribe(firstSubscriber);
expect(SchedulerTracking.__getSubscriberRef().current).toBeDefined();
expect(SchedulerTracking.__subscriberRef.current).toBeDefined();
SchedulerTracking.unstable_subscribe(secondSubscriber);
expect(SchedulerTracking.__getSubscriberRef().current).toBeDefined();
expect(SchedulerTracking.__subscriberRef.current).toBeDefined();
SchedulerTracking.unstable_unsubscribe(secondSubscriber);
expect(SchedulerTracking.__getSubscriberRef().current).toBeDefined();
expect(SchedulerTracking.__subscriberRef.current).toBeDefined();
SchedulerTracking.unstable_unsubscribe(firstSubscriber);
expect(SchedulerTracking.__getSubscriberRef().current).toBe(null);
expect(SchedulerTracking.__subscriberRef.current).toBe(null);
});

describe('error handling', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/forks/ScheduleTracking.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import React from 'react';
const ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;

const {
__getInteractionsRef,
__getSubscriberRef,
__interactionsRef,
__subscriberRef,
unstable_clear,
unstable_getCurrent,
unstable_getThreadID,
Expand All @@ -24,8 +24,8 @@ const {
} = ReactInternals.ScheduleTracking;

export {
__getInteractionsRef,
__getSubscriberRef,
__interactionsRef,
__subscriberRef,
unstable_clear,
unstable_getCurrent,
unstable_getThreadID,
Expand Down