@samitouri / QOS-React-2 / commits / 75b6921d64

Remove dead code from modern event system (#19233)

* Remove dead code from modern event system * Remove SSR dependency on EventPluginRegistry

Dan Abramov committed Jul 1, 2020 at 21:04 UTC 75b6921d6429cc2d7456bd66684263ae63dc6abb
38 files changed +237 -755
packages/react-dom/src/client/ReactDOM.js
+1 -8
@@ -11,7 +11,6 @@ import type {ReactNodeList} from 'shared/ReactTypes';
11 import type {Container} from './ReactDOMHostConfig';
12
13 import '../shared/checkReact';
14 -import './ReactDOMClientInjection';
14 import {
15 findDOMNode,
16 render,
@@ -39,10 +38,7 @@ import {
38 } from 'react-reconciler/src/ReactFiberReconciler';
39 import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal';
40 import {canUseDOM} from 'shared/ExecutionEnvironment';
42 -import {
43 - eventNameDispatchConfigs,
44 - injectEventPluginsByName,
45 -} from '../legacy-events/EventPluginRegistry';
41 +import {eventNameDispatchConfigs} from '../events/EventPluginRegistry';
42 import ReactVersion from 'shared/ReactVersion';
43 import invariant from 'shared/invariant';
44 import {
@@ -57,7 +53,6 @@ import {
53 getClosestInstanceFromNode,
54 } from './ReactDOMComponentTree';
55 import {restoreControlledState} from './ReactDOMComponent';
60 -import {dispatchEvent} from '../events/ReactDOMEventListener';
56 import {
57 setAttemptSynchronousHydration,
58 setAttemptUserBlockingHydration,
@@ -180,11 +175,9 @@ const Internals = {
175 getInstanceFromNode,
176 getNodeFromInstance,
177 getFiberCurrentPropsFromNode,
183 - injectEventPluginsByName,
178 eventNameDispatchConfigs,
179 enqueueStateRestore,
180 restoreStateIfNeeded,
187 - dispatchEvent,
181 flushPassiveEffects,
182 IsThisRendererActing,
183 ],
packages/react-dom/src/client/ReactDOMClientInjection.js deleted
-24
@@ -1,24 +0,0 @@
1 -/**
2 - * Copyright (c) Facebook, Inc. and its affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - */
7 -
8 -// TODO: remove this injection altogether.
9 -
10 -import ModernBeforeInputEventPlugin from '../events/plugins/ModernBeforeInputEventPlugin';
11 -import ModernChangeEventPlugin from '../events/plugins/ModernChangeEventPlugin';
12 -import ModernEnterLeaveEventPlugin from '../events/plugins/ModernEnterLeaveEventPlugin';
13 -import ModernSelectEventPlugin from '../events/plugins/ModernSelectEventPlugin';
14 -import ModernSimpleEventPlugin from '../events/plugins/ModernSimpleEventPlugin';
15 -
16 -import {injectEventPlugins} from '../legacy-events/EventPluginRegistry';
17 -
18 -injectEventPlugins([
19 - ModernSimpleEventPlugin,
20 - ModernEnterLeaveEventPlugin,
21 - ModernChangeEventPlugin,
22 - ModernSelectEventPlugin,
23 - ModernBeforeInputEventPlugin,
24 -]);
packages/react-dom/src/client/ReactDOMComponent.js
+8 -2
@@ -7,7 +7,10 @@
7 * @flow
8 */
9
10 -import {registrationNameModules} from '../legacy-events/EventPluginRegistry';
10 +import {
11 + registrationNameModules,
12 + possibleRegistrationNames,
13 +} from '../events/EventPluginRegistry';
14 import {canUseDOM} from 'shared/ExecutionEnvironment';
15 import invariant from 'shared/invariant';
16 import {
@@ -129,7 +132,10 @@ if (__DEV__) {
132 validatePropertiesInDevelopment = function(type, props) {
133 validateARIAProperties(type, props);
134 validateInputProperties(type, props);
132 - validateUnknownProperties(type, props, /* canUseEventSystem */ true);
135 + validateUnknownProperties(type, props, {
136 + registrationNameModules,
137 + possibleRegistrationNames,
138 + });
139 };
140
141 // IE 11 parses & normalizes the style attribute as opposed to other
packages/react-dom/src/client/ReactDOMComponentTree.js
+1 -1
@@ -17,7 +17,7 @@ import type {
17 SuspenseInstance,
18 Props,
19 } from './ReactDOMHostConfig';
20 -import type {DOMTopLevelEventType} from '../legacy-events/TopLevelEventTypes';
20 +import type {DOMTopLevelEventType} from '../events/TopLevelEventTypes';
21
22 import {
23 HostComponent,
packages/react-dom/src/client/ReactDOMEventHandle.js
+1 -1
@@ -7,7 +7,7 @@
7 * @flow
8 */
9
10 -import type {DOMTopLevelEventType} from '../legacy-events/TopLevelEventTypes';
10 +import type {DOMTopLevelEventType} from '../events/TopLevelEventTypes';
11 import type {EventPriority, ReactScopeInstance} from 'shared/ReactTypes';
12 import type {
13 ReactDOMEventHandle,
packages/react-dom/src/client/ReactDOMHostConfig.js
+1 -1
@@ -7,7 +7,7 @@
7 * @flow
8 */
9
10 -import type {TopLevelType} from '../legacy-events/TopLevelEventTypes';
10 +import type {TopLevelType} from '../events/TopLevelEventTypes';
11 import type {Fiber, FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
12 import type {
13 BoundingRect,
packages/react-dom/src/events/DOMEventProperties.js
+2 -2
@@ -11,11 +11,11 @@ import type {EventPriority} from 'shared/ReactTypes';
11 import type {
12 TopLevelType,
13 DOMTopLevelEventType,
14 -} from '../legacy-events/TopLevelEventTypes';
14 +} from '../events/TopLevelEventTypes';
15 import type {
16 DispatchConfig,
17 CustomDispatchConfig,
18 -} from '../legacy-events/ReactSyntheticEventType';
18 +} from '../events/ReactSyntheticEventType';
19
20 import * as DOMTopLevelEventTypes from './DOMTopLevelEventTypes';
21 import {
packages/react-dom/src/events/DOMModernPluginEventSystem.js
+6 -6
@@ -7,8 +7,8 @@
7 * @flow
8 */
9
10 -import type {AnyNativeEvent} from '../legacy-events/PluginModuleType';
11 -import type {DOMTopLevelEventType} from '../legacy-events/TopLevelEventTypes';
10 +import type {AnyNativeEvent} from '../events/PluginModuleType';
11 +import type {DOMTopLevelEventType} from '../events/TopLevelEventTypes';
12 import type {
13 ElementListenerMap,
14 ElementListenerMapEntry,
@@ -22,14 +22,14 @@ import type {
22 DispatchQueueItem,
23 DispatchQueueItemPhase,
24 DispatchQueueItemPhaseEntry,
25 -} from '../legacy-events/PluginModuleType';
25 +} from '../events/PluginModuleType';
26 import type {
27 ReactSyntheticEvent,
28 CustomDispatchConfig,
29 -} from '../legacy-events/ReactSyntheticEventType';
29 +} from '../events/ReactSyntheticEventType';
30
31 -import {registrationNameDependencies} from '../legacy-events/EventPluginRegistry';
32 -import {plugins} from '../legacy-events/EventPluginRegistry';
31 +import {registrationNameDependencies} from '../events/EventPluginRegistry';
32 +import {plugins} from '../events/EventPluginRegistry';
33 import {
34 PLUGIN_EVENT_SYSTEM,
35 LEGACY_FB_SUPPORT,
packages/react-dom/src/events/DOMTopLevelEventTypes.js
+2 -2
@@ -7,12 +7,12 @@
7 * @flow
8 */
9
10 -import type {DOMTopLevelEventType} from '../legacy-events/TopLevelEventTypes';
10 +import type {DOMTopLevelEventType} from '../events/TopLevelEventTypes';
11
12 import {
13 unsafeCastStringToDOMTopLevelType,
14 unsafeCastDOMTopLevelTypeToString,
15 -} from '../legacy-events/TopLevelEventTypes';
15 +} from '../events/TopLevelEventTypes';
16 import getVendorPrefixedEventName from './getVendorPrefixedEventName';
17
18 /**
packages/react-dom/src/events/DeprecatedDOMEventResponderSystem.js
+2 -2
@@ -12,7 +12,7 @@ import {
12 PASSIVE_NOT_SUPPORTED,
13 RESPONDER_EVENT_SYSTEM,
14 } from './EventSystemFlags';
15 -import type {AnyNativeEvent} from '../legacy-events/PluginModuleType';
15 +import type {AnyNativeEvent} from '../events/PluginModuleType';
16 import {
17 HostComponent,
18 ScopeComponent,
@@ -25,7 +25,7 @@ import type {
25 ReactDOMResponderContext,
26 ReactDOMResponderEvent,
27 } from '../shared/ReactDOMTypes';
28 -import type {DOMTopLevelEventType} from '../legacy-events/TopLevelEventTypes';
28 +import type {DOMTopLevelEventType} from '../events/TopLevelEventTypes';
29 import {
30 batchedEventUpdates,
31 discreteUpdates,
packages/react-dom/src/events/EventPluginRegistry.js new
+151
@@ -0,0 +1,151 @@
1 +/**
2 + * Copyright (c) Facebook, Inc. and its affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + *
7 + * @flow
8 + */
9 +
10 +import type {DispatchConfig} from './ReactSyntheticEventType';
11 +import type {
12 + AnyNativeEvent,
13 + LegacyPluginModule,
14 + ModernPluginModule,
15 +} from './PluginModuleType';
16 +import ModernBeforeInputEventPlugin from '../events/plugins/ModernBeforeInputEventPlugin';
17 +import ModernChangeEventPlugin from '../events/plugins/ModernChangeEventPlugin';
18 +import ModernEnterLeaveEventPlugin from '../events/plugins/ModernEnterLeaveEventPlugin';
19 +import ModernSelectEventPlugin from '../events/plugins/ModernSelectEventPlugin';
20 +import ModernSimpleEventPlugin from '../events/plugins/ModernSimpleEventPlugin';
21 +
22 +import invariant from 'shared/invariant';
23 +
24 +/**
25 + * Publishes an event so that it can be dispatched by the supplied plugin.
26 + *
27 + * @param {object} dispatchConfig Dispatch configuration for the event.
28 + * @param {object} PluginModule Plugin publishing the event.
29 + * @return {boolean} True if the event was successfully published.
30 + * @private
31 + */
32 +function publishEventForPlugin(
33 + dispatchConfig: DispatchConfig,
34 + pluginModule:
35 + | LegacyPluginModule<AnyNativeEvent>
36 + | ModernPluginModule<AnyNativeEvent>,
37 + eventName: string,
38 +): boolean {
39 + invariant(
40 + !eventNameDispatchConfigs.hasOwnProperty(eventName),
41 + 'EventPluginRegistry: More than one plugin attempted to publish the same ' +
42 + 'event name, `%s`.',
43 + eventName,
44 + );
45 + eventNameDispatchConfigs[eventName] = dispatchConfig;
46 +
47 + const phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
48 + if (phasedRegistrationNames) {
49 + for (const phaseName in phasedRegistrationNames) {
50 + if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
51 + const phasedRegistrationName = phasedRegistrationNames[phaseName];
52 + publishRegistrationName(
53 + phasedRegistrationName,
54 + pluginModule,
55 + eventName,
56 + );
57 + }
58 + }
59 + return true;
60 + } else if (dispatchConfig.registrationName) {
61 + publishRegistrationName(
62 + dispatchConfig.registrationName,
63 + pluginModule,
64 + eventName,
65 + );
66 + return true;
67 + }
68 + return false;
69 +}
70 +
71 +/**
72 + * Publishes a registration name that is used to identify dispatched events.
73 + *
74 + * @param {string} registrationName Registration name to add.
75 + * @param {object} PluginModule Plugin publishing the event.
76 + * @private
77 + */
78 +function publishRegistrationName(
79 + registrationName: string,
80 + pluginModule:
81 + | LegacyPluginModule<AnyNativeEvent>
82 + | ModernPluginModule<AnyNativeEvent>,
83 + eventName: string,
84 +): void {
85 + invariant(
86 + !registrationNameModules[registrationName],
87 + 'EventPluginRegistry: More than one plugin attempted to publish the same ' +
88 + 'registration name, `%s`.',
89 + registrationName,
90 + );
91 + registrationNameModules[registrationName] = pluginModule;
92 + registrationNameDependencies[registrationName] =
93 + pluginModule.eventTypes[eventName].dependencies;
94 +
95 + if (__DEV__) {
96 + const lowerCasedName = registrationName.toLowerCase();
97 + possibleRegistrationNames[lowerCasedName] = registrationName;
98 +
99 + if (registrationName === 'onDoubleClick') {
100 + possibleRegistrationNames.ondblclick = registrationName;
101 + }
102 + }
103 +}
104 +
105 +/**
106 + * Registers plugins so that they can extract and dispatch events.
107 + */
108 +
109 +/**
110 + * Ordered list of injected plugins.
111 + */
112 +export const plugins = [];
113 +
114 +/**
115 + * Mapping from event name to dispatch config
116 + */
117 +export const eventNameDispatchConfigs = {};
118 +
119 +/**
120 + * Mapping from registration name to plugin module
121 + */
122 +export const registrationNameModules = {};
123 +
124 +/**
125 + * Mapping from registration name to event name
126 + */
127 +export const registrationNameDependencies = {};
128 +
129 +/**
130 + * Mapping from lowercase registration names to the properly cased version,
131 + * used to warn in the case of missing event handlers. Available
132 + * only in __DEV__.
133 + * @type {Object}
134 + */
135 +export const possibleRegistrationNames = __DEV__ ? {} : (null: any);
136 +// Trust the developer to only use possibleRegistrationNames in __DEV__
137 +
138 +function injectEventPlugin(pluginModule: ModernPluginModule<any>): void {
139 + plugins.push(pluginModule);
140 + const publishedEvents = pluginModule.eventTypes;
141 + for (const eventName in publishedEvents) {
142 + publishEventForPlugin(publishedEvents[eventName], pluginModule, eventName);
143 + }
144 +}
145 +
146 +// TODO: remove top-level side effect.
147 +injectEventPlugin(ModernSimpleEventPlugin);
148 +injectEventPlugin(ModernEnterLeaveEventPlugin);
149 +injectEventPlugin(ModernChangeEventPlugin);
150 +injectEventPlugin(ModernSelectEventPlugin);
151 +injectEventPlugin(ModernBeforeInputEventPlugin);
packages/react-dom/src/events/PluginModuleType.js renamed
packages/react-dom/src/events/ReactDOMEventListener.js
+2 -2
@@ -7,11 +7,11 @@
7 * @flow
8 */
9
10 -import type {AnyNativeEvent} from '../legacy-events/PluginModuleType';
10 +import type {AnyNativeEvent} from '../events/PluginModuleType';
11 import type {EventPriority} from 'shared/ReactTypes';
12 import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
13 import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
14 -import type {DOMTopLevelEventType} from '../legacy-events/TopLevelEventTypes';
14 +import type {DOMTopLevelEventType} from '../events/TopLevelEventTypes';
15
16 // Intentionally not named imports because Rollup would use dynamic dispatch for
17 // CommonJS interop named imports.
packages/react-dom/src/events/ReactDOMEventReplaying.js
+3 -3
@@ -7,9 +7,9 @@
7 * @flow
8 */
9
10 -import type {AnyNativeEvent} from '../legacy-events/PluginModuleType';
10 +import type {AnyNativeEvent} from '../events/PluginModuleType';
11 import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
12 -import type {DOMTopLevelEventType} from '../legacy-events/TopLevelEventTypes';
12 +import type {DOMTopLevelEventType} from '../events/TopLevelEventTypes';
13 import type {ElementListenerMap} from '../client/ReactDOMComponentTree';
14 import type {EventSystemFlags} from './EventSystemFlags';
15 import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
@@ -35,7 +35,7 @@ import {
35 getClosestInstanceFromNode,
36 getEventListenerMap,
37 } from '../client/ReactDOMComponentTree';
38 -import {unsafeCastDOMTopLevelTypeToString} from '../legacy-events/TopLevelEventTypes';
38 +import {unsafeCastDOMTopLevelTypeToString} from '../events/TopLevelEventTypes';
39 import {HostRoot, SuspenseComponent} from 'react-reconciler/src/ReactWorkTags';
40
41 let attemptSynchronousHydration: (fiber: Object) => void;
packages/react-dom/src/events/ReactSyntheticEventType.js renamed
-6
@@ -33,12 +33,6 @@ export type CustomDispatchConfig = {|
33
34 export type ReactSyntheticEvent = {|
35 dispatchConfig: DispatchConfig | CustomDispatchConfig,
36 - getPooled: (
37 - dispatchConfig: DispatchConfig | CustomDispatchConfig,
38 - targetInst: Fiber,
39 - nativeTarget: Event,
40 - nativeEventTarget: EventTarget,
41 - ) => ReactSyntheticEvent,
36 isPersistent: () => boolean,
37 isPropagationStopped: () => boolean,
38 _dispatchInstances?: null | Array<Fiber | null> | Fiber,
packages/react-dom/src/events/SyntheticAnimationEvent.js
+1 -1
@@ -5,7 +5,7 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import SyntheticEvent from '../legacy-events/SyntheticEvent';
8 +import SyntheticEvent from '../events/SyntheticEvent';
9
10 /**
11 * @interface Event
packages/react-dom/src/events/SyntheticClipboardEvent.js
+1 -1
@@ -5,7 +5,7 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import SyntheticEvent from '../legacy-events/SyntheticEvent';
8 +import SyntheticEvent from '../events/SyntheticEvent';
9
10 /**
11 * @interface Event
packages/react-dom/src/events/SyntheticCompositionEvent.js
+1 -1
@@ -5,7 +5,7 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import SyntheticEvent from '../legacy-events/SyntheticEvent';
8 +import SyntheticEvent from '../events/SyntheticEvent';
9
10 /**
11 * @interface Event
packages/react-dom/src/events/SyntheticEvent.js renamed
-46
@@ -60,15 +60,6 @@ function SyntheticEvent(
60 nativeEvent,
61 nativeEventTarget,
62 ) {
63 - if (__DEV__) {
64 - // these have a getter/setter for warnings
65 - delete this.nativeEvent;
66 - delete this.preventDefault;
67 - delete this.stopPropagation;
68 - delete this.isDefaultPrevented;
69 - delete this.isPropagationStopped;
70 - }
71 -
63 this.dispatchConfig = dispatchConfig;
64 this._targetInst = targetInst;
65 this.nativeEvent = nativeEvent;
@@ -78,9 +69,6 @@ function SyntheticEvent(
69 if (!Interface.hasOwnProperty(propName)) {
70 continue;
71 }
81 - if (__DEV__) {
82 - delete this[propName]; // this has a getter/setter for warnings
83 - }
72 const normalize = Interface[propName];
73 if (normalize) {
74 this[propName] = normalize(nativeEvent);
@@ -157,14 +145,6 @@ Object.assign(SyntheticEvent.prototype, {
145 * @return {boolean} True if this should not be released, false otherwise.
146 */
147 isPersistent: functionThatReturnsTrue,
160 -
161 - /**
162 - * `PooledClass` looks for `destructor` on each instance it releases.
163 - */
164 - destructor: function() {
165 - // Modern event system doesn't use pooling.
166 - // TODO: remove calls to this.
167 - },
148 });
149
150 SyntheticEvent.Interface = EventInterface;
@@ -188,34 +168,8 @@ SyntheticEvent.extend = function(Interface) {
168
169 Class.Interface = Object.assign({}, Super.Interface, Interface);
170 Class.extend = Super.extend;
191 - addEventPoolingTo(Class);
171
172 return Class;
173 };
174
196 -addEventPoolingTo(SyntheticEvent);
197 -
198 -function createOrGetPooledEvent(
199 - dispatchConfig,
200 - targetInst,
201 - nativeEvent,
202 - nativeInst,
203 -) {
204 - const EventConstructor = this;
205 - // Modern event system doesn't use pooling.
206 - // TODO: remove this indirection.
207 - return new EventConstructor(
208 - dispatchConfig,
209 - targetInst,
210 - nativeEvent,
211 - nativeInst,
212 - );
213 -}
214 -
215 -function addEventPoolingTo(EventConstructor) {
216 - EventConstructor.getPooled = createOrGetPooledEvent;
217 - // Modern event system doesn't use pooling.
218 - // TODO: remove calls to this.
219 -}
220 -
175 export default SyntheticEvent;
packages/react-dom/src/events/SyntheticInputEvent.js
+1 -1
@@ -5,7 +5,7 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import SyntheticEvent from '../legacy-events/SyntheticEvent';
8 +import SyntheticEvent from '../events/SyntheticEvent';
9
10 /**
11 * @interface Event
packages/react-dom/src/events/SyntheticTransitionEvent.js
+1 -1
@@ -5,7 +5,7 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import SyntheticEvent from '../legacy-events/SyntheticEvent';
8 +import SyntheticEvent from '../events/SyntheticEvent';
9
10 /**
11 * @interface Event
packages/react-dom/src/events/SyntheticUIEvent.js
+1 -1
@@ -5,7 +5,7 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import SyntheticEvent from '../legacy-events/SyntheticEvent';
8 +import SyntheticEvent from '../events/SyntheticEvent';
9
10 const SyntheticUIEvent = SyntheticEvent.extend({
11 view: null,
packages/react-dom/src/events/TopLevelEventTypes.js renamed
+1 -12
@@ -7,17 +7,6 @@
7 * @flow
8 */
9
10 -export type RNTopLevelEventType =
11 - | 'topMouseDown'
12 - | 'topMouseMove'
13 - | 'topMouseUp'
14 - | 'topScroll'
15 - | 'topSelectionChange'
16 - | 'topTouchCancel'
17 - | 'topTouchEnd'
18 - | 'topTouchMove'
19 - | 'topTouchStart';
20 -
10 export opaque type DOMTopLevelEventType = string;
11
12 // Do not use the below two methods directly!
@@ -36,4 +25,4 @@ export function unsafeCastDOMTopLevelTypeToString(
25 return topLevelType;
26 }
27
39 -export type TopLevelType = DOMTopLevelEventType | RNTopLevelEventType;
28 +export type TopLevelType = DOMTopLevelEventType;
packages/react-dom/src/events/getEventModifierState.js
+1 -1
@@ -12,7 +12,7 @@
12 * @see http://www.w3.org/TR/DOM-Level-3-Events/#keys-Modifiers
13 */
14
15 -import type {AnyNativeEvent} from '../legacy-events/PluginModuleType';
15 +import type {AnyNativeEvent} from '../events/PluginModuleType';
16
17 const modifierKeyToProp = {
18 Alt: 'altKey',
packages/react-dom/src/events/plugins/ModernBeforeInputEventPlugin.js
+3 -3
@@ -5,7 +5,7 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import type {TopLevelType} from '../../legacy-events/TopLevelEventTypes';
8 +import type {TopLevelType} from '../../events/TopLevelEventTypes';
9
10 import {canUseDOM} from 'shared/ExecutionEnvironment';
11
@@ -259,7 +259,7 @@ function extractCompositionEvent(
259 }
260 }
261
262 - const event = SyntheticCompositionEvent.getPooled(
262 + const event = new SyntheticCompositionEvent(
263 eventType,
264 null,
265 nativeEvent,
@@ -429,7 +429,7 @@ function extractBeforeInputEvent(
429 return null;
430 }
431
432 - const event = SyntheticInputEvent.getPooled(
432 + const event = new SyntheticInputEvent(
433 eventTypes.beforeInput,
434 null,
435 nativeEvent,
packages/react-dom/src/events/plugins/ModernChangeEventPlugin.js
+2 -2
@@ -5,7 +5,7 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import SyntheticEvent from '../../legacy-events/SyntheticEvent';
8 +import SyntheticEvent from '../../events/SyntheticEvent';
9 import isTextInputElement from '../isTextInputElement';
10 import {canUseDOM} from 'shared/ExecutionEnvironment';
11
@@ -58,7 +58,7 @@ function createAndAccumulateChangeEvent(
58 nativeEvent,
59 target,
60 ) {
61 - const event = SyntheticEvent.getPooled(
61 + const event = new SyntheticEvent(
62 eventTypes.change,
63 null,
64 nativeEvent,
packages/react-dom/src/events/plugins/ModernEnterLeaveEventPlugin.js
+2 -2
@@ -145,7 +145,7 @@ const EnterLeaveEventPlugin = {
145 const fromNode = from == null ? win : getNodeFromInstance(from);
146 const toNode = to == null ? win : getNodeFromInstance(to);
147
148 - const leave = eventInterface.getPooled(
148 + const leave = new eventInterface(
149 leaveEventType,
150 from,
151 nativeEvent,
@@ -155,7 +155,7 @@ const EnterLeaveEventPlugin = {
155 leave.target = fromNode;
156 leave.relatedTarget = toNode;
157
158 - let enter = eventInterface.getPooled(
158 + let enter = new eventInterface(
159 enterEventType,
160 to,
161 nativeEvent,
packages/react-dom/src/events/plugins/ModernSelectEventPlugin.js
+2 -2
@@ -6,7 +6,7 @@
6 */
7
8 import {canUseDOM} from 'shared/ExecutionEnvironment';
9 -import SyntheticEvent from '../../legacy-events/SyntheticEvent';
9 +import SyntheticEvent from '../../events/SyntheticEvent';
10 import isTextInputElement from '../isTextInputElement';
11 import shallowEqual from 'shared/shallowEqual';
12
@@ -132,7 +132,7 @@ function constructSelectEvent(dispatchQueue, nativeEvent, nativeEventTarget) {
132 if (!lastSelection || !shallowEqual(lastSelection, currentSelection)) {
133 lastSelection = currentSelection;
134
135 - const syntheticEvent = SyntheticEvent.getPooled(
135 + const syntheticEvent = new SyntheticEvent(
136 eventTypes.select,
137 null,
138 nativeEvent,
packages/react-dom/src/events/plugins/ModernSimpleEventPlugin.js
+4 -4
@@ -10,15 +10,15 @@
10 import type {
11 TopLevelType,
12 DOMTopLevelEventType,
13 -} from '../../legacy-events/TopLevelEventTypes';
13 +} from '../../events/TopLevelEventTypes';
14 import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
15 import type {
16 ModernPluginModule,
17 DispatchQueue,
18 -} from '../../legacy-events/PluginModuleType';
18 +} from '../../events/PluginModuleType';
19 import type {EventSystemFlags} from '../EventSystemFlags';
20
21 -import SyntheticEvent from '../../legacy-events/SyntheticEvent';
21 +import SyntheticEvent from '../../events/SyntheticEvent';
22
23 import * as DOMTopLevelEventTypes from '../DOMTopLevelEventTypes';
24 import {
@@ -200,7 +200,7 @@ const SimpleEventPlugin: ModernPluginModule<MouseEvent> = {
200 EventConstructor = SyntheticEvent;
201 break;
202 }
203 - const event = EventConstructor.getPooled(
203 + const event = new EventConstructor(
204 dispatchConfig,
205 null,
206 nativeEvent,
packages/react-dom/src/legacy-events/EventPluginRegistry.js deleted
-270
@@ -1,270 +0,0 @@
1 -/**
2 - * Copyright (c) Facebook, Inc. and its affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @flow
8 - */
9 -
10 -import type {DispatchConfig} from './ReactSyntheticEventType';
11 -import type {
12 - AnyNativeEvent,
13 - PluginName,
14 - LegacyPluginModule,
15 - ModernPluginModule,
16 -} from './PluginModuleType';
17 -
18 -import invariant from 'shared/invariant';
19 -
20 -type NamesToPlugins = {
21 - [key: PluginName]:
22 - | LegacyPluginModule<AnyNativeEvent>
23 - | ModernPluginModule<AnyNativeEvent>,
24 - ...,
25 -};
26 -type EventPluginOrder = null | Array<PluginName>;
27 -
28 -/**
29 - * Injectable ordering of event plugins.
30 - */
31 -let eventPluginOrder: EventPluginOrder = null;
32 -
33 -/**
34 - * Injectable mapping from names to event plugin modules.
35 - */
36 -const namesToPlugins: NamesToPlugins = {};
37 -
38 -/**
39 - * Recomputes the plugin list using the injected plugins and plugin ordering.
40 - *
41 - * @private
42 - */
43 -function recomputePluginOrdering(): void {
44 - if (!eventPluginOrder) {
45 - // Wait until an `eventPluginOrder` is injected.
46 - return;
47 - }
48 - for (const pluginName in namesToPlugins) {
49 - const pluginModule = namesToPlugins[pluginName];
50 - const pluginIndex = eventPluginOrder.indexOf(pluginName);
51 - invariant(
52 - pluginIndex > -1,
53 - 'EventPluginRegistry: Cannot inject event plugins that do not exist in ' +
54 - 'the plugin ordering, `%s`.',
55 - pluginName,
56 - );
57 - if (plugins[pluginIndex]) {
58 - continue;
59 - }
60 - invariant(
61 - pluginModule.extractEvents,
62 - 'EventPluginRegistry: Event plugins must implement an `extractEvents` ' +
63 - 'method, but `%s` does not.',
64 - pluginName,
65 - );
66 - plugins[pluginIndex] = pluginModule;
67 - const publishedEvents = pluginModule.eventTypes;
68 - for (const eventName in publishedEvents) {
69 - invariant(
70 - publishEventForPlugin(
71 - publishedEvents[eventName],
72 - pluginModule,
73 - eventName,
74 - ),
75 - 'EventPluginRegistry: Failed to publish event `%s` for plugin `%s`.',
76 - eventName,
77 - pluginName,
78 - );
79 - }
80 - }
81 -}
82 -
83 -/**
84 - * Publishes an event so that it can be dispatched by the supplied plugin.
85 - *
86 - * @param {object} dispatchConfig Dispatch configuration for the event.
87 - * @param {object} PluginModule Plugin publishing the event.
88 - * @return {boolean} True if the event was successfully published.
89 - * @private
90 - */
91 -function publishEventForPlugin(
92 - dispatchConfig: DispatchConfig,
93 - pluginModule:
94 - | LegacyPluginModule<AnyNativeEvent>
95 - | ModernPluginModule<AnyNativeEvent>,
96 - eventName: string,
97 -): boolean {
98 - invariant(
99 - !eventNameDispatchConfigs.hasOwnProperty(eventName),
100 - 'EventPluginRegistry: More than one plugin attempted to publish the same ' +
101 - 'event name, `%s`.',
102 - eventName,
103 - );
104 - eventNameDispatchConfigs[eventName] = dispatchConfig;
105 -
106 - const phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
107 - if (phasedRegistrationNames) {
108 - for (const phaseName in phasedRegistrationNames) {
109 - if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
110 - const phasedRegistrationName = phasedRegistrationNames[phaseName];
111 - publishRegistrationName(
112 - phasedRegistrationName,
113 - pluginModule,
114 - eventName,
115 - );
116 - }
117 - }
118 - return true;
119 - } else if (dispatchConfig.registrationName) {
120 - publishRegistrationName(
121 - dispatchConfig.registrationName,
122 - pluginModule,
123 - eventName,
124 - );
125 - return true;
126 - }
127 - return false;
128 -}
129 -
130 -/**
131 - * Publishes a registration name that is used to identify dispatched events.
132 - *
133 - * @param {string} registrationName Registration name to add.
134 - * @param {object} PluginModule Plugin publishing the event.
135 - * @private
136 - */
137 -function publishRegistrationName(
138 - registrationName: string,
139 - pluginModule:
140 - | LegacyPluginModule<AnyNativeEvent>
141 - | ModernPluginModule<AnyNativeEvent>,
142 - eventName: string,
143 -): void {
144 - invariant(
145 - !registrationNameModules[registrationName],
146 - 'EventPluginRegistry: More than one plugin attempted to publish the same ' +
147 - 'registration name, `%s`.',
148 - registrationName,
149 - );
150 - registrationNameModules[registrationName] = pluginModule;
151 - registrationNameDependencies[registrationName] =
152 - pluginModule.eventTypes[eventName].dependencies;
153 -
154 - if (__DEV__) {
155 - const lowerCasedName = registrationName.toLowerCase();
156 - possibleRegistrationNames[lowerCasedName] = registrationName;
157 -
158 - if (registrationName === 'onDoubleClick') {
159 - possibleRegistrationNames.ondblclick = registrationName;
160 - }
161 - }
162 -}
163 -
164 -/**
165 - * Registers plugins so that they can extract and dispatch events.
166 - */
167 -
168 -/**
169 - * Ordered list of injected plugins.
170 - */
171 -export const plugins = [];
172 -
173 -/**
174 - * Mapping from event name to dispatch config
175 - */
176 -export const eventNameDispatchConfigs = {};
177 -
178 -/**
179 - * Mapping from registration name to plugin module
180 - */
181 -export const registrationNameModules = {};
182 -
183 -/**
184 - * Mapping from registration name to event name
185 - */
186 -export const registrationNameDependencies = {};
187 -
188 -/**
189 - * Mapping from lowercase registration names to the properly cased version,
190 - * used to warn in the case of missing event handlers. Available
191 - * only in __DEV__.
192 - * @type {Object}
193 - */
194 -export const possibleRegistrationNames = __DEV__ ? {} : (null: any);
195 -// Trust the developer to only use possibleRegistrationNames in __DEV__
196 -
197 -/**
198 - * Injects an ordering of plugins (by plugin name). This allows the ordering
199 - * to be decoupled from injection of the actual plugins so that ordering is
200 - * always deterministic regardless of packaging, on-the-fly injection, etc.
201 - *
202 - * @param {array} InjectedEventPluginOrder
203 - * @internal
204 - */
205 -export function injectEventPluginOrder(
206 - injectedEventPluginOrder: EventPluginOrder,
207 -): void {
208 - invariant(
209 - !eventPluginOrder,
210 - 'EventPluginRegistry: Cannot inject event plugin ordering more than ' +
211 - 'once. You are likely trying to load more than one copy of React.',
212 - );
213 - // Clone the ordering so it cannot be dynamically mutated.
214 - eventPluginOrder = Array.prototype.slice.call(injectedEventPluginOrder);
215 - recomputePluginOrdering();
216 -}
217 -
218 -/**
219 - * Injects plugins to be used by plugin event system. The plugin names must be
220 - * in the ordering injected by `injectEventPluginOrder`.
221 - *
222 - * Plugins can be injected as part of page initialization or on-the-fly.
223 - *
224 - * @param {object} injectedNamesToPlugins Map from names to plugin modules.
225 - * @internal
226 - */
227 -export function injectEventPluginsByName(
228 - injectedNamesToPlugins: NamesToPlugins,
229 -): void {
230 - let isOrderingDirty = false;
231 - for (const pluginName in injectedNamesToPlugins) {
232 - if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
233 - continue;
234 - }
235 - const pluginModule = injectedNamesToPlugins[pluginName];
236 - if (
237 - !namesToPlugins.hasOwnProperty(pluginName) ||
238 - namesToPlugins[pluginName] !== pluginModule
239 - ) {
240 - invariant(
241 - !namesToPlugins[pluginName],
242 - 'EventPluginRegistry: Cannot inject two different event plugins ' +
243 - 'using the same name, `%s`.',
244 - pluginName,
245 - );
246 - namesToPlugins[pluginName] = pluginModule;
247 - isOrderingDirty = true;
248 - }
249 - }
250 - if (isOrderingDirty) {
251 - recomputePluginOrdering();
252 - }
253 -}
254 -
255 -export function injectEventPlugins(
256 - eventPlugins: [ModernPluginModule<AnyNativeEvent>],
257 -): void {
258 - for (let i = 0; i < eventPlugins.length; i++) {
259 - const pluginModule = eventPlugins[i];
260 - plugins.push(pluginModule);
261 - const publishedEvents = pluginModule.eventTypes;
262 - for (const eventName in publishedEvents) {
263 - publishEventForPlugin(
264 - publishedEvents[eventName],
265 - pluginModule,
266 - eventName,
267 - );
268 - }
269 - }
270 -}
packages/react-dom/src/legacy-events/EventPluginUtils.js deleted
-172
@@ -1,172 +0,0 @@
1 -/**
2 - * Copyright (c) Facebook, Inc. and its affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - */
7 -
8 -import {invokeGuardedCallbackAndCatchFirstError} from 'shared/ReactErrorUtils';
9 -import invariant from 'shared/invariant';
10 -
11 -export let getFiberCurrentPropsFromNode = null;
12 -export let getInstanceFromNode = null;
13 -export let getNodeFromInstance = null;
14 -
15 -export function setComponentTree(
16 - getFiberCurrentPropsFromNodeImpl,
17 - getInstanceFromNodeImpl,
18 - getNodeFromInstanceImpl,
19 -) {
20 - getFiberCurrentPropsFromNode = getFiberCurrentPropsFromNodeImpl;
21 - getInstanceFromNode = getInstanceFromNodeImpl;
22 - getNodeFromInstance = getNodeFromInstanceImpl;
23 - if (__DEV__) {
24 - if (!getNodeFromInstance || !getInstanceFromNode) {
25 - console.error(
26 - 'EventPluginUtils.setComponentTree(...): Injected ' +
27 - 'module is missing getNodeFromInstance or getInstanceFromNode.',
28 - );
29 - }
30 - }
31 -}
32 -
33 -let validateEventDispatches;
34 -if (__DEV__) {
35 - validateEventDispatches = function(event) {
36 - const dispatchListeners = event._dispatchListeners;
37 - const dispatchInstances = event._dispatchInstances;
38 -
39 - const listenersIsArr = Array.isArray(dispatchListeners);
40 - const listenersLen = listenersIsArr
41 - ? dispatchListeners.length
42 - : dispatchListeners
43 - ? 1
44 - : 0;
45 -
46 - const instancesIsArr = Array.isArray(dispatchInstances);
47 - const instancesLen = instancesIsArr
48 - ? dispatchInstances.length
49 - : dispatchInstances
50 - ? 1
51 - : 0;
52 -
53 - if (instancesIsArr !== listenersIsArr || instancesLen !== listenersLen) {
54 - console.error('EventPluginUtils: Invalid `event`.');
55 - }
56 - };
57 -}
58 -
59 -/**
60 - * Dispatch the event to the listener.
61 - * @param {SyntheticEvent} event SyntheticEvent to handle
62 - * @param {function} listener Application-level callback
63 - * @param {*} inst Internal component instance
64 - */
65 -export function executeDispatch(event, listener, inst) {
66 - const type = event.type || 'unknown-event';
67 - event.currentTarget = getNodeFromInstance(inst);
68 - invokeGuardedCallbackAndCatchFirstError(type, listener, undefined, event);
69 - event.currentTarget = null;
70 -}
71 -
72 -/**
73 - * Standard/simple iteration through an event's collected dispatches.
74 - */
75 -export function executeDispatchesInOrder(event) {
76 - const dispatchListeners = event._dispatchListeners;
77 - const dispatchInstances = event._dispatchInstances;
78 - if (__DEV__) {
79 - validateEventDispatches(event);
80 - }
81 - if (Array.isArray(dispatchListeners)) {
82 - for (let i = 0; i < dispatchListeners.length; i++) {
83 - if (event.isPropagationStopped()) {
84 - break;
85 - }
86 - // Listeners and Instances are two parallel arrays that are always in sync.
87 - executeDispatch(event, dispatchListeners[i], dispatchInstances[i]);
88 - }
89 - } else if (dispatchListeners) {
90 - executeDispatch(event, dispatchListeners, dispatchInstances);
91 - }
92 - event._dispatchListeners = null;
93 - event._dispatchInstances = null;
94 -}
95 -
96 -/**
97 - * Standard/simple iteration through an event's collected dispatches, but stops
98 - * at the first dispatch execution returning true, and returns that id.
99 - *
100 - * @return {?string} id of the first dispatch execution who's listener returns
101 - * true, or null if no listener returned true.
102 - */
103 -function executeDispatchesInOrderStopAtTrueImpl(event) {
104 - const dispatchListeners = event._dispatchListeners;
105 - const dispatchInstances = event._dispatchInstances;
106 - if (__DEV__) {
107 - validateEventDispatches(event);
108 - }
109 - if (Array.isArray(dispatchListeners)) {
110 - for (let i = 0; i < dispatchListeners.length; i++) {
111 - if (event.isPropagationStopped()) {
112 - break;
113 - }
114 - // Listeners and Instances are two parallel arrays that are always in sync.
115 - if (dispatchListeners[i](event, dispatchInstances[i])) {
116 - return dispatchInstances[i];
117 - }
118 - }
119 - } else if (dispatchListeners) {
120 - if (dispatchListeners(event, dispatchInstances)) {
121 - return dispatchInstances;
122 - }
123 - }
124 - return null;
125 -}
126 -
127 -/**
128 - * @see executeDispatchesInOrderStopAtTrueImpl
129 - */
130 -export function executeDispatchesInOrderStopAtTrue(event) {
131 - const ret = executeDispatchesInOrderStopAtTrueImpl(event);
132 - event._dispatchInstances = null;
133 - event._dispatchListeners = null;
134 - return ret;
135 -}
136 -
137 -/**
138 - * Execution of a "direct" dispatch - there must be at most one dispatch
139 - * accumulated on the event or it is considered an error. It doesn't really make
140 - * sense for an event with multiple dispatches (bubbled) to keep track of the
141 - * return values at each dispatch execution, but it does tend to make sense when
142 - * dealing with "direct" dispatches.
143 - *
144 - * @return {*} The return value of executing the single dispatch.
145 - */
146 -export function executeDirectDispatch(event) {
147 - if (__DEV__) {
148 - validateEventDispatches(event);
149 - }
150 - const dispatchListener = event._dispatchListeners;
151 - const dispatchInstance = event._dispatchInstances;
152 - invariant(
153 - !Array.isArray(dispatchListener),
154 - 'executeDirectDispatch(...): Invalid `event`.',
155 - );
156 - event.currentTarget = dispatchListener
157 - ? getNodeFromInstance(dispatchInstance)
158 - : null;
159 - const res = dispatchListener ? dispatchListener(event) : null;
160 - event.currentTarget = null;
161 - event._dispatchListeners = null;
162 - event._dispatchInstances = null;
163 - return res;
164 -}
165 -
166 -/**
167 - * @param {SyntheticEvent} event
168 - * @return {boolean} True iff number of dispatches accumulated is greater than 0.
169 - */
170 -export function hasDispatches(event) {
171 - return !!event._dispatchListeners;
172 -}
packages/react-dom/src/legacy-events/accumulateInto.js deleted
-57
@@ -1,57 +0,0 @@
1 -/**
2 - * Copyright (c) Facebook, Inc. and its affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @flow
8 - */
9 -
10 -import invariant from 'shared/invariant';
11 -
12 -/**
13 - * Accumulates items that must not be null or undefined into the first one. This
14 - * is used to conserve memory by avoiding array allocations, and thus sacrifices
15 - * API cleanness. Since `current` can be null before being passed in and not
16 - * null after this function, make sure to assign it back to `current`:
17 - *
18 - * `a = accumulateInto(a, b);`
19 - *
20 - * This API should be sparingly used. Try `accumulate` for something cleaner.
21 - *
22 - * @return {*|array<*>} An accumulation of items.
23 - */
24 -
25 -function accumulateInto<T>(
26 - current: ?(Array<T> | T),
27 - next: T | Array<T>,
28 -): T | Array<T> {
29 - invariant(
30 - next != null,
31 - 'accumulateInto(...): Accumulated items must not be null or undefined.',
32 - );
33 -
34 - if (current == null) {
35 - return next;
36 - }
37 -
38 - // Both are not empty. Warning: Never call x.concat(y) when you are not
39 - // certain that x is an Array (x could be a string with concat method).
40 - if (Array.isArray(current)) {
41 - if (Array.isArray(next)) {
42 - current.push.apply(current, next);
43 - return current;
44 - }
45 - current.push(next);
46 - return current;
47 - }
48 -
49 - if (Array.isArray(next)) {
50 - // A bit too dangerous to mutate `next`.
51 - return [current].concat(next);
52 - }
53 -
54 - return [current, next];
55 -}
56 -
57 -export default accumulateInto;
packages/react-dom/src/legacy-events/forEachAccumulated.js deleted
-31
@@ -1,31 +0,0 @@
1 -/**
2 - * Copyright (c) Facebook, Inc. and its affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @flow
8 - */
9 -
10 -/**
11 - * @param {array} arr an "accumulation" of items which is either an Array or
12 - * a single item. Useful when paired with the `accumulate` module. This is a
13 - * simple utility that allows us to reason about a collection of items, but
14 - * handling the case when there is exactly one item (and we do not need to
15 - * allocate an array).
16 - * @param {function} cb Callback invoked with each element or a collection.
17 - * @param {?} [scope] Scope used as `this` in a callback.
18 - */
19 -function forEachAccumulated<T>(
20 - arr: ?(Array<T> | T),
21 - cb: (elem: T) => void,
22 - scope: ?any,
23 -) {
24 - if (Array.isArray(arr)) {
25 - arr.forEach(cb, scope);
26 - } else if (arr) {
27 - cb.call(scope, arr);
28 - }
29 -}
30 -
31 -export default forEachAccumulated;
packages/react-dom/src/server/ReactPartialRenderer.js
+1 -1
@@ -114,7 +114,7 @@ if (__DEV__) {
114 validatePropertiesInDevelopment = function(type, props) {
115 validateARIAProperties(type, props);
116 validateInputProperties(type, props);
117 - validateUnknownProperties(type, props, /* canUseEventSystem */ false);
117 + validateUnknownProperties(type, props, null);
118 };
119
120 describeStackFrame = function(element): string {
packages/react-dom/src/shared/ReactDOMTypes.js
+1 -1
@@ -14,7 +14,7 @@ import type {
14 EventPriority,
15 ReactScopeInstance,
16 } from 'shared/ReactTypes';
17 -import type {DOMTopLevelEventType} from '../legacy-events/TopLevelEventTypes';
17 +import type {DOMTopLevelEventType} from '../events/TopLevelEventTypes';
18
19 type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | Touch;
20
packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js
+10 -16
@@ -5,11 +5,6 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import {
9 - registrationNameModules,
10 - possibleRegistrationNames,
11 -} from '../legacy-events/EventPluginRegistry';
12 -
8 import {
9 ATTRIBUTE_NAME_CHAR,
10 BOOLEAN,
@@ -30,7 +25,7 @@ if (__DEV__) {
25 const rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
26 const rARIACamel = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
27
33 - validateProperty = function(tagName, name, value, canUseEventSystem) {
28 + validateProperty = function(tagName, name, value, eventRegistry) {
29 if (hasOwnProperty.call(warnedProperties, name) && warnedProperties[name]) {
30 return true;
31 }
@@ -47,7 +42,11 @@ if (__DEV__) {
42 }
43
44 // We can't rely on the event system being injected on the server.
50 - if (canUseEventSystem) {
45 + if (eventRegistry != null) {
46 + const {
47 + registrationNameModules,
48 + possibleRegistrationNames,
49 + } = eventRegistry;
50 if (registrationNameModules.hasOwnProperty(name)) {
51 return true;
52 }
@@ -240,16 +239,11 @@ if (__DEV__) {
239 };
240 }
241
243 -const warnUnknownProperties = function(type, props, canUseEventSystem) {
242 +const warnUnknownProperties = function(type, props, eventRegistry) {
243 if (__DEV__) {
244 const unknownProps = [];
245 for (const key in props) {
247 - const isValid = validateProperty(
248 - type,
249 - key,
250 - props[key],
251 - canUseEventSystem,
252 - );
246 + const isValid = validateProperty(type, key, props[key], eventRegistry);
247 if (!isValid) {
248 unknownProps.push(key);
249 }
@@ -278,9 +272,9 @@ const warnUnknownProperties = function(type, props, canUseEventSystem) {
272 }
273 };
274
281 -export function validateProperties(type, props, canUseEventSystem) {
275 +export function validateProperties(type, props, eventRegistry) {
276 if (isCustomComponent(type, props)) {
277 return;
278 }
285 - warnUnknownProperties(type, props, canUseEventSystem);
279 + warnUnknownProperties(type, props, eventRegistry);
280 }
packages/react-dom/src/test-utils/ReactTestUtils.js
+24 -67
@@ -15,12 +15,10 @@ import {
15 HostComponent,
16 HostText,
17 } from 'react-reconciler/src/ReactWorkTags';
18 -import SyntheticEvent from '../legacy-events/SyntheticEvent';
18 +import SyntheticEvent from '../events/SyntheticEvent';
19 import invariant from 'shared/invariant';
20 import {ELEMENT_NODE} from '../shared/HTMLNodeType';
21 import act from './ReactTestUtilsAct';
22 -import forEachAccumulated from '../legacy-events/forEachAccumulated';
23 -import accumulateInto from '../legacy-events/accumulateInto';
22 import {
23 rethrowCaughtError,
24 invokeGuardedCallbackAndCatchFirstError,
@@ -32,13 +30,12 @@ const [
30 /* eslint-disable no-unused-vars */
31 getNodeFromInstance,
32 getFiberCurrentPropsFromNode,
35 - injectEventPluginsByName,
33 /* eslint-enable no-unused-vars */
34 eventNameDispatchConfigs,
35 enqueueStateRestore,
39 - restoreStateIfNeeded /* eslint-disable no-unused-vars */, // TODO: remove.
40 - ,
41 - /* dispatchEvent */ flushPassiveEffects,
36 + restoreStateIfNeeded,
37 + /* eslint-disable no-unused-vars */
38 + flushPassiveEffects,
39 IsThisRendererActing,
40 /* eslint-enable no-unused-vars */
41 ] = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events;
@@ -386,12 +383,6 @@ function executeDispatchesInOrder(event) {
383 event._dispatchInstances = null;
384 }
385
389 -/**
390 - * Internal queue of events that have accumulated their dispatches and are
391 - * waiting to have their dispatches executed.
392 - */
393 -let eventQueue: ?(Array<ReactSyntheticEvent> | ReactSyntheticEvent) = null;
394 -
386 /**
387 * Dispatches an event and releases it back into the pool, unless persistent.
388 *
@@ -408,36 +399,6 @@ const executeDispatchesAndRelease = function(event: ReactSyntheticEvent) {
399 }
400 };
401
411 -const executeDispatchesAndReleaseTopLevel = function(e) {
412 - return executeDispatchesAndRelease(e);
413 -};
414 -
415 -function runEventsInBatch(
416 - events: Array<ReactSyntheticEvent> | ReactSyntheticEvent | null,
417 -) {
418 - if (events !== null) {
419 - eventQueue = accumulateInto(eventQueue, events);
420 - }
421 -
422 - // Set `eventQueue` to null before processing it so that we can tell if more
423 - // events get enqueued while processing.
424 - const processingEventQueue = eventQueue;
425 - eventQueue = null;
426 -
427 - if (!processingEventQueue) {
428 - return;
429 - }
430 -
431 - forEachAccumulated(processingEventQueue, executeDispatchesAndReleaseTopLevel);
432 - invariant(
433 - !eventQueue,
434 - 'processEventQueue(): Additional events were enqueued while processing ' +
435 - 'an event queue. Support for this has not yet been implemented.',
436 - );
437 - // This would be a good time to rethrow if any of the event handlers threw.
438 - rethrowCaughtError();
439 -}
440 -
402 function isInteractive(tag) {
403 return (
404 tag === 'button' ||
@@ -541,11 +502,14 @@ function accumulateDispatches(inst, ignoredDirection, event) {
502 const registrationName = event.dispatchConfig.registrationName;
503 const listener = getListener(inst, registrationName);
504 if (listener) {
544 - event._dispatchListeners = accumulateInto(
545 - event._dispatchListeners,
546 - listener,
547 - );
548 - event._dispatchInstances = accumulateInto(event._dispatchInstances, inst);
505 + if (event._dispatchListeners == null) {
506 + event._dispatchListeners = [];
507 + }
508 + if (event._dispatchInstances == null) {
509 + event._dispatchInstances = [];
510 + }
511 + event._dispatchListeners.push(listener);
512 + event._dispatchInstances.push(inst);
513 }
514 }
515 }
@@ -558,11 +522,14 @@ function accumulateDirectionalDispatches(inst, phase, event) {
522 }
523 const listener = listenerAtPhase(inst, event, phase);
524 if (listener) {
561 - event._dispatchListeners = accumulateInto(
562 - event._dispatchListeners,
563 - listener,
564 - );
565 - event._dispatchInstances = accumulateInto(event._dispatchInstances, inst);
525 + if (event._dispatchListeners == null) {
526 + event._dispatchListeners = [];
527 + }
528 + if (event._dispatchInstances == null) {
529 + event._dispatchInstances = [];
530 + }
531 + event._dispatchListeners.push(listener);
532 + event._dispatchInstances.push(inst);
533 }
534 }
535
@@ -572,23 +539,15 @@ function accumulateDirectDispatchesSingle(event) {
539 }
540 }
541
575 -function accumulateDirectDispatches(events) {
576 - forEachAccumulated(events, accumulateDirectDispatchesSingle);
577 -}
578 -
542 function accumulateTwoPhaseDispatchesSingle(event) {
543 if (event && event.dispatchConfig.phasedRegistrationNames) {
544 traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event);
545 }
546 }
547
585 -function accumulateTwoPhaseDispatches(events) {
586 - forEachAccumulated(events, accumulateTwoPhaseDispatchesSingle);
587 -}
548 // End of inline
549
550 const Simulate = {};
591 -let SimulateNative;
551
552 /**
553 * Exports:
@@ -618,8 +577,6 @@ function makeSimulator(eventType) {
577 fakeNativeEvent.target = domNode;
578 fakeNativeEvent.type = eventType.toLowerCase();
579
621 - // We don't use SyntheticEvent.getPooled in order to not have to worry about
622 - // properly destroying any properties assigned from `eventData` upon release
580 const targetInst = getInstanceFromNode(domNode);
581 const event = new SyntheticEvent(
582 dispatchConfig,
@@ -634,16 +591,17 @@ function makeSimulator(eventType) {
591 Object.assign(event, eventData);
592
593 if (dispatchConfig.phasedRegistrationNames) {
637 - accumulateTwoPhaseDispatches(event);
594 + accumulateTwoPhaseDispatchesSingle(event);
595 } else {
639 - accumulateDirectDispatches(event);
596 + accumulateDirectDispatchesSingle(event);
597 }
598
599 ReactDOM.unstable_batchedUpdates(function() {
600 // Normally extractEvent enqueues a state restore, but we'll just always
601 // do that since we're by-passing it here.
602 enqueueStateRestore(domNode);
646 - runEventsInBatch(event);
603 + executeDispatchesAndRelease(event);
604 + rethrowCaughtError();
605 });
606 restoreStateIfNeeded();
607 };
@@ -680,6 +638,5 @@ export {
638 mockComponent,
639 nativeTouchData,
640 Simulate,
683 - SimulateNative,
641 act,
642 };
packages/react-dom/src/test-utils/ReactTestUtilsAct.js
-2
@@ -20,11 +20,9 @@ const [
20 getInstanceFromNode,
21 getNodeFromInstance,
22 getFiberCurrentPropsFromNode,
23 - injectEventPluginsByName,
23 eventNameDispatchConfigs,
24 enqueueStateRestore,
25 restoreStateIfNeeded,
27 - dispatchEvent,
26 /* eslint-enable no-unused-vars */
27 flushPassiveEffects,
28 IsThisRendererActing,