Skip to content

Commit b6df441

Browse files
authored
Remove event config (facebook#19237)
1 parent 991c3b8 commit b6df441

10 files changed

+124
-229
lines changed

packages/react-dom/src/client/ReactDOMComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import {
1111
registrationNameDependencies,
1212
possibleRegistrationNames,
13-
} from '../events/EventPluginRegistry';
13+
} from '../events/EventRegistry';
1414
import {canUseDOM} from 'shared/ExecutionEnvironment';
1515
import invariant from 'shared/invariant';
1616
import {

packages/react-dom/src/events/DOMEventProperties.js

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import type {
1212
TopLevelType,
1313
DOMTopLevelEventType,
1414
} from '../events/TopLevelEventTypes';
15-
import type {EventTypes} from '../events/PluginModuleType';
1615

16+
import {registerTwoPhaseEvent} from './EventRegistry';
1717
import * as DOMTopLevelEventTypes from './DOMTopLevelEventTypes';
1818
import {
1919
DiscreteEvent,
@@ -23,14 +23,6 @@ import {
2323

2424
import {enableCreateEventHandleAPI} from 'shared/ReactFeatureFlags';
2525

26-
// Needed for SimpleEventPlugin, rather than
27-
// do it in two places, which duplicates logic
28-
// and increases the bundle size, we do it all
29-
// here once. If we remove or refactor the
30-
// SimpleEventPlugin, we should also remove or
31-
// update the below line.
32-
export const simpleEventPluginEventTypes: EventTypes = {};
33-
3426
export const topLevelEventsToReactNames: Map<
3527
TopLevelType,
3628
string | null,
@@ -152,23 +144,16 @@ const continuousPairsForSimpleEventPlugin = [
152144
/**
153145
* Turns
154146
* ['abort', ...]
147+
*
155148
* into
156-
* eventTypes = {
157-
* 'abort': {
158-
* phasedRegistrationNames: {
159-
* bubbled: 'onAbort',
160-
* captured: 'onAbortCapture',
161-
* },
162-
* dependencies: [TOP_ABORT],
163-
* },
164-
* ...
165-
* };
149+
*
166150
* topLevelEventsToReactNames = new Map([
167151
* [TOP_ABORT, 'onAbort'],
168152
* ]);
153+
*
154+
* and registers them.
169155
*/
170-
171-
function processSimpleEventPluginPairsByPriority(
156+
function registerSimplePluginEventsAndSetTheirPriorities(
172157
eventTypes: Array<DOMTopLevelEventType | string>,
173158
priority: EventPriority,
174159
): void {
@@ -182,23 +167,14 @@ function processSimpleEventPluginPairsByPriority(
182167
const topEvent = ((eventTypes[i]: any): DOMTopLevelEventType);
183168
const event = ((eventTypes[i + 1]: any): string);
184169
const capitalizedEvent = event[0].toUpperCase() + event.slice(1);
185-
const onEvent = 'on' + capitalizedEvent;
186-
187-
const config = {
188-
phasedRegistrationNames: {
189-
bubbled: onEvent,
190-
captured: onEvent + 'Capture',
191-
},
192-
dependencies: [topEvent],
193-
eventPriority: priority,
194-
};
170+
const reactName = 'on' + capitalizedEvent;
195171
eventPriorities.set(topEvent, priority);
196-
topLevelEventsToReactNames.set(topEvent, onEvent);
197-
simpleEventPluginEventTypes[event] = config;
172+
topLevelEventsToReactNames.set(topEvent, reactName);
173+
registerTwoPhaseEvent(reactName, [topEvent]);
198174
}
199175
}
200176

201-
function processTopEventPairsByPriority(
177+
function setEventPriorities(
202178
eventTypes: Array<DOMTopLevelEventType | string>,
203179
priority: EventPriority,
204180
): void {
@@ -207,22 +183,6 @@ function processTopEventPairsByPriority(
207183
}
208184
}
209185

210-
// SimpleEventPlugin
211-
processSimpleEventPluginPairsByPriority(
212-
discreteEventPairsForSimpleEventPlugin,
213-
DiscreteEvent,
214-
);
215-
processSimpleEventPluginPairsByPriority(
216-
userBlockingPairsForSimpleEventPlugin,
217-
UserBlockingEvent,
218-
);
219-
processSimpleEventPluginPairsByPriority(
220-
continuousPairsForSimpleEventPlugin,
221-
ContinuousEvent,
222-
);
223-
// Not used by SimpleEventPlugin
224-
processTopEventPairsByPriority(otherDiscreteEvents, DiscreteEvent);
225-
226186
export function getEventPriorityForPluginSystem(
227187
topLevelType: TopLevelType,
228188
): EventPriority {
@@ -248,3 +208,19 @@ export function getEventPriorityForListenerSystem(
248208
}
249209
return ContinuousEvent;
250210
}
211+
212+
export function registerSimpleEvents() {
213+
registerSimplePluginEventsAndSetTheirPriorities(
214+
discreteEventPairsForSimpleEventPlugin,
215+
DiscreteEvent,
216+
);
217+
registerSimplePluginEventsAndSetTheirPriorities(
218+
userBlockingPairsForSimpleEventPlugin,
219+
UserBlockingEvent,
220+
);
221+
registerSimplePluginEventsAndSetTheirPriorities(
222+
continuousPairsForSimpleEventPlugin,
223+
ContinuousEvent,
224+
);
225+
setEventPriorities(otherDiscreteEvents, DiscreteEvent);
226+
}

packages/react-dom/src/events/DOMModernPluginEventSystem.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ import type {
2424
import type {EventPriority, ReactScopeInstance} from 'shared/ReactTypes';
2525
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
2626

27-
import {
28-
injectEventPlugin,
29-
registrationNameDependencies,
30-
} from './EventPluginRegistry';
27+
import {registrationNameDependencies} from './EventRegistry';
3128
import {
3229
PLUGIN_EVENT_SYSTEM,
3330
LEGACY_FB_SUPPORT,
@@ -118,11 +115,11 @@ import * as ModernSelectEventPlugin from './plugins/ModernSelectEventPlugin';
118115
import * as ModernSimpleEventPlugin from './plugins/ModernSimpleEventPlugin';
119116

120117
// TODO: remove top-level side effect.
121-
injectEventPlugin(ModernSimpleEventPlugin.eventTypes);
122-
injectEventPlugin(ModernEnterLeaveEventPlugin.eventTypes);
123-
injectEventPlugin(ModernChangeEventPlugin.eventTypes);
124-
injectEventPlugin(ModernSelectEventPlugin.eventTypes);
125-
injectEventPlugin(ModernBeforeInputEventPlugin.eventTypes);
118+
ModernSimpleEventPlugin.registerEvents();
119+
ModernEnterLeaveEventPlugin.registerEvents();
120+
ModernChangeEventPlugin.registerEvents();
121+
ModernSelectEventPlugin.registerEvents();
122+
ModernBeforeInputEventPlugin.registerEvents();
126123

127124
function extractEvents(
128125
dispatchQueue: DispatchQueue,

packages/react-dom/src/events/EventPluginRegistry.js renamed to packages/react-dom/src/events/EventRegistry.js

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
import type {TopLevelType} from './TopLevelEventTypes';
11-
import type {EventTypes} from './PluginModuleType';
1211

1312
/**
1413
* Mapping from registration name to event name
@@ -24,41 +23,22 @@ export const registrationNameDependencies = {};
2423
export const possibleRegistrationNames = __DEV__ ? {} : (null: any);
2524
// Trust the developer to only use possibleRegistrationNames in __DEV__
2625

27-
function publishEventForPlugin(
28-
eventTypes: EventTypes,
29-
eventName: string,
30-
): boolean {
31-
const dispatchConfig = eventTypes[eventName];
32-
const phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
33-
if (phasedRegistrationNames) {
34-
for (const phaseName in phasedRegistrationNames) {
35-
if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
36-
const phasedRegistrationName = phasedRegistrationNames[phaseName];
37-
publishRegistrationName(
38-
phasedRegistrationName,
39-
eventTypes[eventName].dependencies,
40-
);
41-
}
42-
}
43-
return true;
44-
} else if (dispatchConfig.registrationName) {
45-
publishRegistrationName(
46-
dispatchConfig.registrationName,
47-
eventTypes[eventName].dependencies,
48-
);
49-
return true;
50-
}
51-
return false;
26+
export function registerTwoPhaseEvent(
27+
registrationName: string,
28+
dependencies: ?Array<TopLevelType>,
29+
): void {
30+
registerDirectEvent(registrationName, dependencies);
31+
registerDirectEvent(registrationName + 'Capture', dependencies);
5232
}
5333

54-
function publishRegistrationName(
34+
export function registerDirectEvent(
5535
registrationName: string,
5636
dependencies: ?Array<TopLevelType>,
57-
): void {
37+
) {
5838
if (__DEV__) {
5939
if (registrationNameDependencies[registrationName]) {
6040
console.error(
61-
'EventPluginRegistry: More than one plugin attempted to publish the same ' +
41+
'EventRegistry: More than one plugin attempted to publish the same ' +
6242
'registration name, `%s`.',
6343
registrationName,
6444
);
@@ -76,9 +56,3 @@ function publishRegistrationName(
7656
}
7757
}
7858
}
79-
80-
export function injectEventPlugin(eventTypes: EventTypes): void {
81-
for (const eventName in eventTypes) {
82-
publishEventForPlugin(eventTypes, eventName);
83-
}
84-
}

packages/react-dom/src/events/PluginModuleType.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88
*/
99

1010
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
11-
import type {
12-
DispatchConfig,
13-
ReactSyntheticEvent,
14-
} from './ReactSyntheticEventType';
15-
16-
export type EventTypes = {[key: string]: DispatchConfig, ...};
11+
import type {ReactSyntheticEvent} from './ReactSyntheticEventType';
1712

1813
export type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | TouchEvent;
1914

packages/react-dom/src/events/plugins/ModernBeforeInputEventPlugin.js

Lines changed: 34 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {TopLevelType} from '../../events/TopLevelEventTypes';
99

1010
import {canUseDOM} from 'shared/ExecutionEnvironment';
1111

12+
import {registerTwoPhaseEvent} from '../EventRegistry';
1213
import {
1314
TOP_BLUR,
1415
TOP_COMPOSITION_START,
@@ -57,63 +58,38 @@ const useFallbackCompositionData =
5758
const SPACEBAR_CODE = 32;
5859
const SPACEBAR_CHAR = String.fromCharCode(SPACEBAR_CODE);
5960

60-
// Events and their corresponding property names.
61-
const eventTypes: EventTypes = {
62-
beforeInput: {
63-
phasedRegistrationNames: {
64-
bubbled: 'onBeforeInput',
65-
captured: 'onBeforeInputCapture',
66-
},
67-
dependencies: [
68-
TOP_COMPOSITION_END,
69-
TOP_KEY_PRESS,
70-
TOP_TEXT_INPUT,
71-
TOP_PASTE,
72-
],
73-
},
74-
compositionEnd: {
75-
phasedRegistrationNames: {
76-
bubbled: 'onCompositionEnd',
77-
captured: 'onCompositionEndCapture',
78-
},
79-
dependencies: [
80-
TOP_BLUR,
81-
TOP_COMPOSITION_END,
82-
TOP_KEY_DOWN,
83-
TOP_KEY_PRESS,
84-
TOP_KEY_UP,
85-
TOP_MOUSE_DOWN,
86-
],
87-
},
88-
compositionStart: {
89-
phasedRegistrationNames: {
90-
bubbled: 'onCompositionStart',
91-
captured: 'onCompositionStartCapture',
92-
},
93-
dependencies: [
94-
TOP_BLUR,
95-
TOP_COMPOSITION_START,
96-
TOP_KEY_DOWN,
97-
TOP_KEY_PRESS,
98-
TOP_KEY_UP,
99-
TOP_MOUSE_DOWN,
100-
],
101-
},
102-
compositionUpdate: {
103-
phasedRegistrationNames: {
104-
bubbled: 'onCompositionUpdate',
105-
captured: 'onCompositionUpdateCapture',
106-
},
107-
dependencies: [
108-
TOP_BLUR,
109-
TOP_COMPOSITION_UPDATE,
110-
TOP_KEY_DOWN,
111-
TOP_KEY_PRESS,
112-
TOP_KEY_UP,
113-
TOP_MOUSE_DOWN,
114-
],
115-
},
116-
};
61+
function registerEvents() {
62+
registerTwoPhaseEvent('onBeforeInput', [
63+
TOP_COMPOSITION_END,
64+
TOP_KEY_PRESS,
65+
TOP_TEXT_INPUT,
66+
TOP_PASTE,
67+
]);
68+
registerTwoPhaseEvent('onCompositionEnd', [
69+
TOP_BLUR,
70+
TOP_COMPOSITION_END,
71+
TOP_KEY_DOWN,
72+
TOP_KEY_PRESS,
73+
TOP_KEY_UP,
74+
TOP_MOUSE_DOWN,
75+
]);
76+
registerTwoPhaseEvent('onCompositionStart', [
77+
TOP_BLUR,
78+
TOP_COMPOSITION_START,
79+
TOP_KEY_DOWN,
80+
TOP_KEY_PRESS,
81+
TOP_KEY_UP,
82+
TOP_MOUSE_DOWN,
83+
]);
84+
registerTwoPhaseEvent('onCompositionUpdate', [
85+
TOP_BLUR,
86+
TOP_COMPOSITION_UPDATE,
87+
TOP_KEY_DOWN,
88+
TOP_KEY_PRESS,
89+
TOP_KEY_UP,
90+
TOP_MOUSE_DOWN,
91+
]);
92+
}
11793

11894
// Track whether we've ever handled a keypress on the space key.
11995
let hasSpaceKeypress = false;
@@ -482,4 +458,4 @@ function extractEvents(
482458
);
483459
}
484460

485-
export {eventTypes, extractEvents};
461+
export {registerEvents, extractEvents};

0 commit comments

Comments
 (0)