Skip to content
Permalink
Browse files

Refactor DOM plugin system to single module (#18025)

  • Loading branch information
trueadm committed Feb 14, 2020
1 parent 2d6be75 commit 9def56ec0e1e71928ee999f48c00b1803ed8772a

This file was deleted.

@@ -89,7 +89,7 @@ function publishEventForPlugin(
): boolean {
invariant(
!eventNameDispatchConfigs.hasOwnProperty(eventName),
'EventPluginHub: More than one plugin attempted to publish the same ' +
'EventPluginRegistry: More than one plugin attempted to publish the same ' +
'event name, `%s`.',
eventName,
);
@@ -133,7 +133,7 @@ function publishRegistrationName(
): void {
invariant(
!registrationNameModules[registrationName],
'EventPluginHub: More than one plugin attempted to publish the same ' +
'EventPluginRegistry: More than one plugin attempted to publish the same ' +
'registration name, `%s`.',
registrationName,
);
@@ -153,8 +153,6 @@ function publishRegistrationName(

/**
* Registers plugins so that they can extract and dispatch events.
*
* @see {EventPluginHub}
*/

/**
@@ -193,7 +191,6 @@ export const possibleRegistrationNames = __DEV__ ? {} : (null: any);
*
* @param {array} InjectedEventPluginOrder
* @internal
* @see {EventPluginHub.injection.injectEventPluginOrder}
*/
export function injectEventPluginOrder(
injectedEventPluginOrder: EventPluginOrder,
@@ -209,14 +206,13 @@ export function injectEventPluginOrder(
}

/**
* Injects plugins to be used by `EventPluginHub`. The plugin names must be
* Injects plugins to be used by plugin event system. The plugin names must be
* in the ordering injected by `injectEventPluginOrder`.
*
* Plugins can be injected as part of page initialization or on-the-fly.
*
* @param {object} injectedNamesToPlugins Map from names to plugin modules.
* @internal
* @see {EventPluginHub.injection.injectEventPluginsByName}
*/
export function injectEventPluginsByName(
injectedNamesToPlugins: NamesToPlugins,
@@ -11,7 +11,7 @@ import {
traverseEnterLeave,
} from 'shared/ReactTreeTraversal';

import {getListener} from './EventPluginHub';
import getListener from 'legacy-events/getListener';
import accumulateInto from './accumulateInto';
import forEachAccumulated from './forEachAccumulated';

@@ -282,7 +282,7 @@ to return true:wantsResponderID| |
+ + */

/**
* A note about event ordering in the `EventPluginHub`.
* A note about event ordering in the `EventPluginRegistry`.
*
* Suppose plugins are injected in the following order:
*
@@ -301,7 +301,7 @@ to return true:wantsResponderID| |
* - When returned from `extractEvents`, deferred-dispatched events contain an
* "accumulation" of deferred dispatches.
* - These deferred dispatches are accumulated/collected before they are
* returned, but processed at a later time by the `EventPluginHub` (hence the
* returned, but processed at a later time by the `EventPluginRegistry` (hence the
* name deferred).
*
* In the process of returning their deferred-dispatched events, event plugins
@@ -325,9 +325,9 @@ to return true:wantsResponderID| |
* - `R`s on-demand events (if any) (dispatched by `R` on-demand)
* - `S`s on-demand events (if any) (dispatched by `S` on-demand)
* - `C`s on-demand events (if any) (dispatched by `C` on-demand)
* - `R`s extracted events (if any) (dispatched by `EventPluginHub`)
* - `S`s extracted events (if any) (dispatched by `EventPluginHub`)
* - `C`s extracted events (if any) (dispatched by `EventPluginHub`)
* - `R`s extracted events (if any) (dispatched by `EventPluginRegistry`)
* - `S`s extracted events (if any) (dispatched by `EventPluginRegistry`)
* - `C`s extracted events (if any) (dispatched by `EventPluginRegistry`)
*
* In the case of `ResponderEventPlugin`: If the `startShouldSetResponder`
* on-demand dispatch returns `true` (and some other details are satisfied) the
@@ -336,9 +336,9 @@ to return true:wantsResponderID| |
* will appear as follows:
*
* - `startShouldSetResponder` (`ResponderEventPlugin` dispatches on-demand)
* - `touchStartCapture` (`EventPluginHub` dispatches as usual)
* - `touchStart` (`EventPluginHub` dispatches as usual)
* - `responderGrant/Reject` (`EventPluginHub` dispatches as usual)
* - `touchStartCapture` (`EventPluginRegistry` dispatches as usual)
* - `touchStart` (`EventPluginRegistry` dispatches as usual)
* - `responderGrant/Reject` (`EventPluginRegistry` dispatches as usual)
*/

function setResponderAndExtractTransfer(
@@ -211,7 +211,7 @@ describe('EventPluginRegistry', () => {
expect(function() {
EventPluginRegistry.injectEventPluginOrder(['one', 'two']);
}).toThrowError(
'EventPluginHub: More than one plugin attempted to publish the same ' +
'EventPluginRegistry: More than one plugin attempted to publish the same ' +
'registration name, `onPhotoCapture`.',
);
});
@@ -0,0 +1,74 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @flow
*/

import type {Fiber} from 'react-reconciler/src/ReactFiber';

import invariant from 'shared/invariant';

import {getFiberCurrentPropsFromNode} from './EventPluginUtils';

function isInteractive(tag) {
return (
tag === 'button' ||
tag === 'input' ||
tag === 'select' ||
tag === 'textarea'
);
}

function shouldPreventMouseEvent(name, type, props) {
switch (name) {
case 'onClick':
case 'onClickCapture':
case 'onDoubleClick':
case 'onDoubleClickCapture':
case 'onMouseDown':
case 'onMouseDownCapture':
case 'onMouseMove':
case 'onMouseMoveCapture':
case 'onMouseUp':
case 'onMouseUpCapture':
case 'onMouseEnter':
return !!(props.disabled && isInteractive(type));
default:
return false;
}
}

/**
* @param {object} inst The instance, which is the source of events.
* @param {string} registrationName Name of listener (e.g. `onClick`).
* @return {?function} The stored callback.
*/
export default function getListener(inst: Fiber, registrationName: string) {
let listener;

// TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
// live here; needs to be moved to a better place soon
const stateNode = inst.stateNode;
if (!stateNode) {
// Work in progress (ex: onload events in incremental mode).
return null;
}
const props = getFiberCurrentPropsFromNode(stateNode);
if (!props) {
// Work in progress.
return null;
}
listener = props[registrationName];
if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
return null;
}
invariant(
!listener || typeof listener === 'function',
'Expected `%s` listener to be a function, instead got a value of `%s` type.',
registrationName,
typeof listener,
);
return listener;
}
@@ -11,7 +11,7 @@

jest.mock('../events/isEventSupported');

describe('EventPluginHub', () => {
describe('InvalidEventListeners', () => {
let React;
let ReactTestUtils;

0 comments on commit 9def56e

Please sign in to comment.
You can’t perform that action at this time.