@samitouri / QOS-React-2 / commits / b7f217d40c

[Concurrent Mode] Add missing event plugin priorities (#17914)

Dominic Gannaway committed Jan 28, 2020 at 13:20 UTC b7f217d40c6c8c973c86fabceeda238b38662171
1 file changed +45 -9
packages/react-dom/src/events/DOMEventProperties.js
+45 -9
@@ -36,11 +36,17 @@ export const topLevelEventsToDispatchConfig: Map<
36
37 const eventPriorities = new Map();
38
39 -// We store all the DOMTopLevelEventTypes and their React Types in pairs of two.
40 -// Furthermore, we ignore prettier so we can keep the formatting sane.
39 +// We store most of the events in this module in pairs of two strings so we can re-use
40 +// the code required to apply the same logic for event prioritization and that of the
41 +// SimpleEventPlugin. This complicates things slightly, but the aim is to reduce code
42 +// duplication (for which there would be quite a bit). For the events that are not needed
43 +// for the SimpleEventPlugin (otherDiscreteEvents) we process them separately as an
44 +// array of top level events.
45 +
46 +// Lastly, we ignore prettier so we can keep the formatting sane.
47
48 // prettier-ignore
43 -const discreteEvents = [
49 +const discreteEventPairsForSimpleEventPlugin = [
50 DOMTopLevelEventTypes.TOP_BLUR, 'blur',
51 DOMTopLevelEventTypes.TOP_CANCEL, 'cancel',
52 DOMTopLevelEventTypes.TOP_CLICK, 'click',
@@ -77,8 +83,17 @@ const discreteEvents = [
83 DOMTopLevelEventTypes.TOP_VOLUME_CHANGE, 'volumeChange',
84 ];
85
86 +const otherDiscreteEvents = [
87 + DOMTopLevelEventTypes.TOP_CHANGE,
88 + DOMTopLevelEventTypes.TOP_SELECTION_CHANGE,
89 + DOMTopLevelEventTypes.TOP_TEXT_INPUT,
90 + DOMTopLevelEventTypes.TOP_COMPOSITION_START,
91 + DOMTopLevelEventTypes.TOP_COMPOSITION_END,
92 + DOMTopLevelEventTypes.TOP_COMPOSITION_UPDATE,
93 +];
94 +
95 // prettier-ignore
81 -const userBlockingEvents = [
96 +const userBlockingPairsForSimpleEventPlugin = [
97 DOMTopLevelEventTypes.TOP_DRAG, 'drag',
98 DOMTopLevelEventTypes.TOP_DRAG_ENTER, 'dragEnter',
99 DOMTopLevelEventTypes.TOP_DRAG_EXIT, 'dragExit',
@@ -97,7 +112,7 @@ const userBlockingEvents = [
112 ];
113
114 // prettier-ignore
100 -const continuousEvents = [
115 +const continuousPairsForSimpleEventPlugin = [
116 DOMTopLevelEventTypes.TOP_ABORT, 'abort',
117 DOMTopLevelEventTypes.TOP_ANIMATION_END, 'animationEnd',
118 DOMTopLevelEventTypes.TOP_ANIMATION_ITERATION, 'animationIteration',
@@ -144,7 +159,7 @@ const continuousEvents = [
159 * ]);
160 */
161
147 -function processTopEventTypesByPriority(
162 +function processSimpleEventPluginPairsByPriority(
163 eventTypes: Array<DOMTopLevelEventType | string>,
164 priority: EventPriority,
165 ): void {
@@ -174,9 +189,30 @@ function processTopEventTypesByPriority(
189 }
190 }
191
177 -processTopEventTypesByPriority(discreteEvents, DiscreteEvent);
178 -processTopEventTypesByPriority(userBlockingEvents, UserBlockingEvent);
179 -processTopEventTypesByPriority(continuousEvents, ContinuousEvent);
192 +function processTopEventPairsByPriority(
193 + eventTypes: Array<DOMTopLevelEventType | string>,
194 + priority: EventPriority,
195 +): void {
196 + for (let i = 0; i < eventTypes.length; i++) {
197 + eventPriorities.set(eventTypes[i], priority);
198 + }
199 +}
200 +
201 +// SimpleEventPlugin
202 +processSimpleEventPluginPairsByPriority(
203 + discreteEventPairsForSimpleEventPlugin,
204 + DiscreteEvent,
205 +);
206 +processSimpleEventPluginPairsByPriority(
207 + userBlockingPairsForSimpleEventPlugin,
208 + UserBlockingEvent,
209 +);
210 +processSimpleEventPluginPairsByPriority(
211 + continuousPairsForSimpleEventPlugin,
212 + ContinuousEvent,
213 +);
214 +// Not used by SimpleEventPlugin
215 +processTopEventPairsByPriority(otherDiscreteEvents, DiscreteEvent);
216
217 export function getEventPriorityForPluginSystem(
218 topLevelType: TopLevelType,