Skip to content

Commit

Permalink
[react-interactions] Rename Flare APIs to deprecated and remove from …
Browse files Browse the repository at this point in the history
…RN (#17644)
  • Loading branch information
trueadm authored Dec 18, 2019
1 parent e84327b commit 9fe1031
Show file tree
Hide file tree
Showing 63 changed files with 215 additions and 1,304 deletions.
4 changes: 2 additions & 2 deletions packages/legacy-events/ReactGenericBatching.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
restoreStateIfNeeded,
} from './ReactControlledComponent';

import {enableFlareAPI} from 'shared/ReactFeatureFlags';
import {enableDeprecatedFlareAPI} from 'shared/ReactFeatureFlags';
import {invokeGuardedCallbackAndCatchFirstError} from 'shared/ReactErrorUtils';

// Used as a way to call batchedUpdates when we don't have a reference to
Expand Down Expand Up @@ -118,7 +118,7 @@ export function flushDiscreteUpdatesIfNeeded(timeStamp: number) {
// behaviour as we had before this change, so the risks are low.
if (
!isInsideEventHandler &&
(!enableFlareAPI ||
(!enableDeprecatedFlareAPI ||
(timeStamp === 0 || lastFlushedEventTimeStamp !== timeStamp))
) {
lastFlushedEventTimeStamp = timeStamp;
Expand Down
4 changes: 2 additions & 2 deletions packages/react-art/src/ReactARTHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ export function unhideTextInstance(textInstance, text): void {
// Noop
}

export function mountResponderInstance(
export function DEPRECATED_mountResponderInstance(
responder: ReactEventResponder<any, any>,
responderInstance: ReactEventResponderInstance<any, any>,
props: Object,
Expand All @@ -436,7 +436,7 @@ export function mountResponderInstance(
throw new Error('Not yet implemented.');
}

export function unmountResponderInstance(
export function DEPRECATED_unmountResponderInstance(
responderInstance: ReactEventResponderInstance<any, any>,
): void {
throw new Error('Not yet implemented.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ describe('ReactHooksInspection', () => {
beforeEach(() => {
jest.resetModules();
const ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.enableFlareAPI = true;
ReactFeatureFlags.enableDeprecatedFlareAPI = true;
React = require('react');
ReactDebugTools = require('react-debug-tools');
});

it('should inspect a simple useResponder hook', () => {
const TestResponder = React.unstable_createResponder('TestResponder', {});
const TestResponder = React.DEPRECATED_createResponder('TestResponder', {});

function Foo(props) {
const listener = React.unstable_useResponder(TestResponder, {
const listener = React.DEPRECATED_useResponder(TestResponder, {
preventDefault: false,
});
return <div DEPRECATED_flareListeners={listener}>Hello world</div>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('ReactDOMServerPartialHydration', () => {

ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.enableSuspenseCallback = true;
ReactFeatureFlags.enableFlareAPI = true;
ReactFeatureFlags.enableDeprecatedFlareAPI = true;
ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;

React = require('react');
Expand Down Expand Up @@ -1885,13 +1885,16 @@ describe('ReactDOMServerPartialHydration', () => {
}

const onEvent = jest.fn();
const TestResponder = React.unstable_createResponder('TestEventResponder', {
targetEventTypes: ['click'],
onEvent,
});
const TestResponder = React.DEPRECATED_createResponder(
'TestEventResponder',
{
targetEventTypes: ['click'],
onEvent,
},
);

function Button() {
let listener = React.unstable_useResponder(TestResponder, {});
let listener = React.DEPRECATED_useResponder(TestResponder, {});
return <a DEPRECATED_flareListeners={listener}>Click me</a>;
}

Expand Down Expand Up @@ -2034,13 +2037,16 @@ describe('ReactDOMServerPartialHydration', () => {
let promise = new Promise(resolvePromise => (resolve = resolvePromise));

const onEvent = jest.fn();
const TestResponder = React.unstable_createResponder('TestEventResponder', {
targetEventTypes: ['click'],
onEvent,
});
const TestResponder = React.DEPRECATED_createResponder(
'TestEventResponder',
{
targetEventTypes: ['click'],
onEvent,
},
);

function Button() {
let listener = React.unstable_useResponder(TestResponder, {});
let listener = React.DEPRECATED_useResponder(TestResponder, {});
return <a DEPRECATED_flareListeners={listener}>Click me</a>;
}

Expand Down
16 changes: 8 additions & 8 deletions packages/react-dom/src/client/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {getCurrentFiberOwnerNameInDevOrNull} from 'react-reconciler/src/ReactCur
import {registrationNameModules} from 'legacy-events/EventPluginRegistry';
import {canUseDOM} from 'shared/ExecutionEnvironment';
import endsWith from 'shared/endsWith';
import {setListenToResponderEventTypes} from '../events/DOMEventResponderSystem';
import {setListenToResponderEventTypes} from '../events/DeprecatedDOMEventResponderSystem';

import {
getValueForAttribute,
Expand Down Expand Up @@ -88,7 +88,7 @@ import {validateProperties as validateUnknownProperties} from '../shared/ReactDO
import {toStringOrTrustedType} from './ToStringValue';

import {
enableFlareAPI,
enableDeprecatedFlareAPI,
enableTrustedTypesIntegration,
} from 'shared/ReactFeatureFlags';

Expand Down Expand Up @@ -342,7 +342,7 @@ function setInitialDOMProperties(
setTextContent(domElement, '' + nextProp);
}
} else if (
(enableFlareAPI && propKey === DEPRECATED_flareListeners) ||
(enableDeprecatedFlareAPI && propKey === DEPRECATED_flareListeners) ||
propKey === SUPPRESS_CONTENT_EDITABLE_WARNING ||
propKey === SUPPRESS_HYDRATION_WARNING
) {
Expand Down Expand Up @@ -709,7 +709,7 @@ export function diffProperties(
} else if (propKey === DANGEROUSLY_SET_INNER_HTML || propKey === CHILDREN) {
// Noop. This is handled by the clear text mechanism.
} else if (
(enableFlareAPI && propKey === DEPRECATED_flareListeners) ||
(enableDeprecatedFlareAPI && propKey === DEPRECATED_flareListeners) ||
propKey === SUPPRESS_CONTENT_EDITABLE_WARNING ||
propKey === SUPPRESS_HYDRATION_WARNING
) {
Expand Down Expand Up @@ -804,7 +804,7 @@ export function diffProperties(
(updatePayload = updatePayload || []).push(propKey, '' + nextProp);
}
} else if (
(enableFlareAPI && propKey === DEPRECATED_flareListeners) ||
(enableDeprecatedFlareAPI && propKey === DEPRECATED_flareListeners) ||
propKey === SUPPRESS_CONTENT_EDITABLE_WARNING ||
propKey === SUPPRESS_HYDRATION_WARNING
) {
Expand Down Expand Up @@ -1058,7 +1058,7 @@ export function diffHydratedProperties(
if (suppressHydrationWarning) {
// Don't bother comparing. We're ignoring all these warnings.
} else if (
(enableFlareAPI && propKey === DEPRECATED_flareListeners) ||
(enableDeprecatedFlareAPI && propKey === DEPRECATED_flareListeners) ||
propKey === SUPPRESS_CONTENT_EDITABLE_WARNING ||
propKey === SUPPRESS_HYDRATION_WARNING ||
// Controlled attributes are not validated
Expand Down Expand Up @@ -1298,7 +1298,7 @@ export function listenToEventResponderEventTypes(
eventTypes: Array<string>,
document: Document,
): void {
if (enableFlareAPI) {
if (enableDeprecatedFlareAPI) {
// Get the listening Map for this element. We use this to track
// what events we're listening to.
const listenerMap = getListenerMapForElement(document);
Expand Down Expand Up @@ -1346,6 +1346,6 @@ export function listenToEventResponderEventTypes(
}

// We can remove this once the event API is stable and out of a flag
if (enableFlareAPI) {
if (enableDeprecatedFlareAPI) {
setListenToResponderEventTypes(listenToEventResponderEventTypes);
}
20 changes: 10 additions & 10 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ import type {
import {
mountEventResponder,
unmountEventResponder,
dispatchEventForResponderEventSystem,
} from '../events/DOMEventResponderSystem';
DEPRECATED_dispatchEventForResponderEventSystem,
} from '../events/DeprecatedDOMEventResponderSystem';
import {retryIfBlockedOn} from '../events/ReactDOMEventReplaying';

export type Type = string;
Expand Down Expand Up @@ -111,7 +111,7 @@ type SelectionInformation = {|

import {
enableSuspenseServerRenderer,
enableFlareAPI,
enableDeprecatedFlareAPI,
enableFundamentalAPI,
} from 'shared/ReactFeatureFlags';
import {
Expand Down Expand Up @@ -212,7 +212,7 @@ export function resetAfterCommit(containerInfo: Container): void {
restoreSelection(selectionInformation);
ReactBrowserEventEmitterSetEnabled(eventsEnabled);
eventsEnabled = null;
if (enableFlareAPI) {
if (enableDeprecatedFlareAPI) {
const activeElementDetached = (selectionInformation: any)
.activeElementDetached;
if (activeElementDetached !== null) {
Expand Down Expand Up @@ -468,7 +468,7 @@ function dispatchBeforeDetachedBlur(target: HTMLElement): void {
const targetInstance = getClosestInstanceFromNode(target);
((selectionInformation: any): SelectionInformation).activeElementDetached = target;

dispatchEventForResponderEventSystem(
DEPRECATED_dispatchEventForResponderEventSystem(
'beforeblur',
targetInstance,
({
Expand All @@ -481,7 +481,7 @@ function dispatchBeforeDetachedBlur(target: HTMLElement): void {
}

function dispatchDetachedBlur(target: HTMLElement): void {
dispatchEventForResponderEventSystem(
DEPRECATED_dispatchEventForResponderEventSystem(
'blur',
null,
({
Expand All @@ -502,7 +502,7 @@ export function beforeRemoveInstance(
instance: Instance | TextInstance | SuspenseInstance,
): void {
if (
enableFlareAPI &&
enableDeprecatedFlareAPI &&
selectionInformation &&
instance === selectionInformation.focusedElem
) {
Expand Down Expand Up @@ -944,7 +944,7 @@ export function didNotFindHydratableSuspenseInstance(
}
}

export function mountResponderInstance(
export function DEPRECATED_mountResponderInstance(
responder: ReactDOMEventResponder,
responderInstance: ReactDOMEventResponderInstance,
responderProps: Object,
Expand All @@ -966,10 +966,10 @@ export function mountResponderInstance(
return responderInstance;
}

export function unmountResponderInstance(
export function DEPRECATED_unmountResponderInstance(
responderInstance: ReactDOMEventResponderInstance,
): void {
if (enableFlareAPI) {
if (enableDeprecatedFlareAPI) {
// TODO stop listening to targetEventTypes
unmountEventResponder(responderInstance);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
} from 'legacy-events/ReactGenericBatching';
import {enqueueStateRestore} from 'legacy-events/ReactControlledComponent';
import type {Fiber} from 'react-reconciler/src/ReactFiber';
import {enableFlareAPI} from 'shared/ReactFeatureFlags';
import {enableDeprecatedFlareAPI} from 'shared/ReactFeatureFlags';
import invariant from 'shared/invariant';

import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree';
Expand Down Expand Up @@ -164,7 +164,7 @@ const eventResponderContext: ReactDOMResponderContext = {
for (let i = 0; i < rootEventTypes.length; i++) {
const rootEventType = rootEventTypes[i];
const eventResponderInstance = ((currentInstance: any): ReactDOMEventResponderInstance);
registerRootEventType(rootEventType, eventResponderInstance);
DEPRECATED_registerRootEventType(rootEventType, eventResponderInstance);
}
},
removeRootEventTypes(rootEventTypes: Array<string>): void {
Expand Down Expand Up @@ -494,14 +494,14 @@ function validateResponderContext(): void {
);
}

export function dispatchEventForResponderEventSystem(
export function DEPRECATED_dispatchEventForResponderEventSystem(
topLevelType: string,
targetFiber: null | Fiber,
nativeEvent: AnyNativeEvent,
nativeEventTarget: Document | Element,
eventSystemFlags: EventSystemFlags,
): void {
if (enableFlareAPI) {
if (enableDeprecatedFlareAPI) {
const previousInstance = currentInstance;
const previousTimeStamp = currentTimeStamp;
const previousDocument = currentDocument;
Expand Down Expand Up @@ -539,11 +539,11 @@ export function addRootEventTypesForResponderInstance(
): void {
for (let i = 0; i < rootEventTypes.length; i++) {
const rootEventType = rootEventTypes[i];
registerRootEventType(rootEventType, responderInstance);
DEPRECATED_registerRootEventType(rootEventType, responderInstance);
}
}

function registerRootEventType(
function DEPRECATED_registerRootEventType(
rootEventType: string,
eventResponderInstance: ReactDOMEventResponderInstance,
): void {
Expand Down
12 changes: 6 additions & 6 deletions packages/react-dom/src/events/ReactDOMEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
flushDiscreteUpdatesIfNeeded,
} from 'legacy-events/ReactGenericBatching';
import {runExtractedPluginEventsInBatch} from 'legacy-events/EventPluginHub';
import {dispatchEventForResponderEventSystem} from './DOMEventResponderSystem';
import {DEPRECATED_dispatchEventForResponderEventSystem} from './DeprecatedDOMEventResponderSystem';
import {
isReplayableDiscreteEvent,
queueDiscreteEvent,
Expand Down Expand Up @@ -63,7 +63,7 @@ import SimpleEventPlugin from './SimpleEventPlugin';
import {getRawEventName} from './DOMTopLevelEventTypes';
import {passiveBrowserEventsSupported} from './checkPassiveEvents';

import {enableFlareAPI} from 'shared/ReactFeatureFlags';
import {enableDeprecatedFlareAPI} from 'shared/ReactFeatureFlags';
import {
UserBlockingEvent,
ContinuousEvent,
Expand Down Expand Up @@ -403,7 +403,7 @@ export function dispatchEvent(

// This is not replayable so we'll invoke it but without a target,
// in case the event system needs to trace it.
if (enableFlareAPI) {
if (enableDeprecatedFlareAPI) {
if (eventSystemFlags & PLUGIN_EVENT_SYSTEM) {
dispatchEventForPluginEventSystem(
topLevelType,
Expand All @@ -414,7 +414,7 @@ export function dispatchEvent(
}
if (eventSystemFlags & RESPONDER_EVENT_SYSTEM) {
// React Flare event system
dispatchEventForResponderEventSystem(
DEPRECATED_dispatchEventForResponderEventSystem(
(topLevelType: any),
null,
nativeEvent,
Expand Down Expand Up @@ -481,7 +481,7 @@ export function attemptToDispatchEvent(
}
}

if (enableFlareAPI) {
if (enableDeprecatedFlareAPI) {
if (eventSystemFlags & PLUGIN_EVENT_SYSTEM) {
dispatchEventForPluginEventSystem(
topLevelType,
Expand All @@ -492,7 +492,7 @@ export function attemptToDispatchEvent(
}
if (eventSystemFlags & RESPONDER_EVENT_SYSTEM) {
// React Flare event system
dispatchEventForResponderEventSystem(
DEPRECATED_dispatchEventForResponderEventSystem(
(topLevelType: any),
targetInst,
nativeEvent,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/src/events/ReactDOMEventReplaying.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
import type {FiberRoot} from 'react-reconciler/src/ReactFiberRoot';

import {
enableFlareAPI,
enableDeprecatedFlareAPI,
enableSelectiveHydration,
} from 'shared/ReactFeatureFlags';
import {
Expand Down Expand Up @@ -217,7 +217,7 @@ function trapReplayableEvent(
listenerMap: Map<DOMTopLevelEventType | string, null | (any => void)>,
) {
listenToTopLevel(topLevelType, document, listenerMap);
if (enableFlareAPI) {
if (enableDeprecatedFlareAPI) {
// Trap events for the responder system.
const topLevelTypeString = unsafeCastDOMTopLevelTypeToString(topLevelType);
const passiveEventKey = topLevelTypeString + '_passive';
Expand Down
Loading

0 comments on commit 9fe1031

Please sign in to comment.