Skip to content

Commit

Permalink
Add modern event system flag + rename legacy plugin module (#18073)
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm authored Feb 19, 2020
1 parent 4d9f850 commit 4912ba3
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let EventPluginRegistry;
let React;
let ReactDOM;
let ReactDOMComponentTree;
let DOMEventPluginSystem;
let listenToEvent;
let ReactDOMEventListener;
let ReactTestUtils;

Expand Down Expand Up @@ -54,8 +54,7 @@ function registerSimpleTestHandler() {
}

// We should probably remove this file at some point, it's just full of
// internal API usage. ReactBrowserEventEmitter was refactored out in
// #18056 too. The majority of this code lives in DOMEventPluginSystem.
// internal API usage.
describe('ReactBrowserEventEmitter', () => {
beforeEach(() => {
jest.resetModules();
Expand All @@ -66,7 +65,8 @@ describe('ReactBrowserEventEmitter', () => {
React = require('react');
ReactDOM = require('react-dom');
ReactDOMComponentTree = require('../client/ReactDOMComponentTree');
DOMEventPluginSystem = require('../events/DOMEventPluginSystem');
listenToEvent = require('../events/DOMLegacyEventPluginSystem')
.legacyListenToEvent;
ReactDOMEventListener = require('../events/ReactDOMEventListener');
ReactTestUtils = require('react-dom/test-utils');

Expand Down Expand Up @@ -350,15 +350,15 @@ describe('ReactBrowserEventEmitter', () => {

it('should listen to events only once', () => {
spyOnDevAndProd(EventTarget.prototype, 'addEventListener');
DOMEventPluginSystem.listenToEvent(ON_CLICK_KEY, document);
DOMEventPluginSystem.listenToEvent(ON_CLICK_KEY, document);
listenToEvent(ON_CLICK_KEY, document);
listenToEvent(ON_CLICK_KEY, document);
expect(EventTarget.prototype.addEventListener).toHaveBeenCalledTimes(1);
});

it('should work with event plugins without dependencies', () => {
spyOnDevAndProd(EventTarget.prototype, 'addEventListener');

DOMEventPluginSystem.listenToEvent(ON_CLICK_KEY, document);
listenToEvent(ON_CLICK_KEY, document);

expect(EventTarget.prototype.addEventListener.calls.argsFor(0)[0]).toBe(
'click',
Expand All @@ -368,7 +368,7 @@ describe('ReactBrowserEventEmitter', () => {
it('should work with event plugins with dependencies', () => {
spyOnDevAndProd(EventTarget.prototype, 'addEventListener');

DOMEventPluginSystem.listenToEvent(ON_CHANGE_KEY, document);
listenToEvent(ON_CHANGE_KEY, document);

const setEventListeners = [];
const listenCalls = EventTarget.prototype.addEventListener.calls.allArgs();
Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/src/client/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import {
enableDeprecatedFlareAPI,
enableTrustedTypesIntegration,
} from 'shared/ReactFeatureFlags';
import {listenToEvent} from '../events/DOMEventPluginSystem';
import {legacyListenToEvent} from '../events/DOMLegacyEventPluginSystem';

let didWarnInvalidHydration = false;
let didWarnShadyDOM = false;
Expand Down Expand Up @@ -272,7 +272,7 @@ function ensureListeningTo(
const doc = isDocumentOrFragment
? rootContainerElement
: rootContainerElement.ownerDocument;
listenToEvent(registrationName, doc);
legacyListenToEvent(registrationName, doc);
}

function getOwnerDocumentFromRootContainer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export function dispatchEventForPluginEventSystem(
* @param {string} registrationName Name of listener (e.g. `onClick`).
* @param {object} mountAt Container where to mount the listener
*/
export function listenToEvent(
export function legacyListenToEvent(
registrationName: string,
mountAt: Document | Element | Node,
): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/events/ReactDOMEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import {
DiscreteEvent,
} from 'shared/ReactTypes';
import {getEventPriorityForPluginSystem} from './DOMEventProperties';
import {dispatchEventForPluginEventSystem} from './DOMEventPluginSystem';
import {dispatchEventForPluginEventSystem} from './DOMLegacyEventPluginSystem';

const {
unstable_UserBlockingPriority: UserBlockingPriority,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/events/ReactDOMEventReplaying.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ import {
TOP_BLUR,
} from './DOMTopLevelEventTypes';
import {IS_REPLAYED} from 'legacy-events/EventSystemFlags';
import {listenToTopLevelEvent} from './DOMEventPluginSystem';
import {listenToTopLevelEvent} from './DOMLegacyEventPluginSystem';

type QueuedReplayableEvent = {|
blockedOn: null | Container | SuspenseInstance,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/events/SelectEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import getActiveElement from '../client/getActiveElement';
import {getNodeFromInstance} from '../client/ReactDOMComponentTree';
import {hasSelectionCapabilities} from '../client/ReactInputSelection';
import {DOCUMENT_NODE} from '../shared/HTMLNodeType';
import {isListeningToAllDependencies} from './DOMEventPluginSystem';
import {isListeningToAllDependencies} from './DOMLegacyEventPluginSystem';

const skipSelectionChangeEvent =
canUseDOM && 'documentMode' in document && document.documentMode <= 11;
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,6 @@ export const warnUnstableRenderSubtreeIntoContainer = false;

// Disables ReactDOM.unstable_createPortal
export const disableUnstableCreatePortal = false;

// Modern event system where events get registered at roots
export const enableModernEventSystem = false;
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const disableUnstableCreatePortal = false;
export const deferPassiveEffectCleanupDuringUnmount = false;
export const runAllPassiveEffectDestroysBeforeCreates = false;
export const isTestEnvironment = false;
export const enableModernEventSystem = false;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const disableUnstableCreatePortal = false;
export const deferPassiveEffectCleanupDuringUnmount = false;
export const runAllPassiveEffectDestroysBeforeCreates = false;
export const isTestEnvironment = false;
export const enableModernEventSystem = false;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.persistent.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const disableUnstableCreatePortal = false;
export const deferPassiveEffectCleanupDuringUnmount = false;
export const runAllPassiveEffectDestroysBeforeCreates = false;
export const isTestEnvironment = false;
export const enableModernEventSystem = false;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const disableUnstableCreatePortal = false;
export const deferPassiveEffectCleanupDuringUnmount = false;
export const runAllPassiveEffectDestroysBeforeCreates = false;
export const isTestEnvironment = true; // this should probably *never* change
export const enableModernEventSystem = false;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const disableUnstableCreatePortal = false;
export const deferPassiveEffectCleanupDuringUnmount = false;
export const runAllPassiveEffectDestroysBeforeCreates = false;
export const isTestEnvironment = true; // this should probably *never* change
export const enableModernEventSystem = false;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const disableUnstableCreatePortal = false;
export const deferPassiveEffectCleanupDuringUnmount = false;
export const runAllPassiveEffectDestroysBeforeCreates = false;
export const isTestEnvironment = true;
export const enableModernEventSystem = false;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.testing.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const disableUnstableCreatePortal = __EXPERIMENTAL__;
export const deferPassiveEffectCleanupDuringUnmount = false;
export const runAllPassiveEffectDestroysBeforeCreates = false;
export const isTestEnvironment = true;
export const enableModernEventSystem = false;

// Only used in www builds.
export function addUserTimingListener() {
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export const disableUnstableCreatePortal = __EXPERIMENTAL__;

export const isTestEnvironment = false;

export const enableModernEventSystem = false;

// Flow magic to verify the exports of this file match the original version.
// eslint-disable-next-line no-unused-vars
type Check<_X, Y: _X, X: Y = _X> = null;
Expand Down

0 comments on commit 4912ba3

Please sign in to comment.