|
7 | 7 | * @flow |
8 | 8 | */ |
9 | 9 |
|
10 | | -import type {EventPriority} from 'shared/ReactTypes'; |
11 | 10 | import type {DOMEventName} from './DOMEventNames'; |
12 | 11 |
|
13 | 12 | import {registerTwoPhaseEvent} from './EventRegistry'; |
@@ -17,7 +16,6 @@ import { |
17 | 16 | ANIMATION_START, |
18 | 17 | TRANSITION_END, |
19 | 18 | } from './DOMEventNames'; |
20 | | -import {DiscreteEvent, ContinuousEvent, DefaultEvent} from 'shared/ReactTypes'; |
21 | 19 |
|
22 | 20 | import {enableCreateEventHandleAPI} from 'shared/ReactFeatureFlags'; |
23 | 21 |
|
@@ -26,19 +24,8 @@ export const topLevelEventsToReactNames: Map< |
26 | 24 | string | null, |
27 | 25 | > = new Map(); |
28 | 26 |
|
29 | | -const eventPriorities = new Map(); |
30 | | - |
31 | | -// We store most of the events in this module in pairs of two strings so we can re-use |
32 | | -// the code required to apply the same logic for event prioritization and that of the |
33 | | -// SimpleEventPlugin. This complicates things slightly, but the aim is to reduce code |
34 | | -// duplication (for which there would be quite a bit). For the events that are not needed |
35 | | -// for the SimpleEventPlugin (otherDiscreteEvents) we process them separately as an |
36 | | -// array of top level events. |
37 | | - |
38 | | -// Lastly, we ignore prettier so we can keep the formatting sane. |
39 | | - |
40 | 27 | // prettier-ignore |
41 | | -const discreteEventPairsForSimpleEventPlugin = [ |
| 28 | +const simpleEventPluginNames = [ |
42 | 29 | ('cancel': DOMEventName), 'cancel', |
43 | 30 | ('click': DOMEventName), 'click', |
44 | 31 | ('close': DOMEventName), 'close', |
@@ -73,27 +60,7 @@ const discreteEventPairsForSimpleEventPlugin = [ |
73 | 60 | ('touchend': DOMEventName), 'touchEnd', |
74 | 61 | ('touchstart': DOMEventName), 'touchStart', |
75 | 62 | ('volumechange': DOMEventName), 'volumeChange', |
76 | | -]; |
77 | | - |
78 | | -const otherDiscreteEvents: Array<DOMEventName> = [ |
79 | | - 'change', |
80 | | - 'selectionchange', |
81 | | - 'textInput', |
82 | | - 'compositionstart', |
83 | | - 'compositionend', |
84 | | - 'compositionupdate', |
85 | | -]; |
86 | | - |
87 | | -if (enableCreateEventHandleAPI) { |
88 | | - // Special case: these two events don't have on* React handler |
89 | | - // and are only accessible via the createEventHandle API. |
90 | | - topLevelEventsToReactNames.set('beforeblur', null); |
91 | | - topLevelEventsToReactNames.set('afterblur', null); |
92 | | - otherDiscreteEvents.push('beforeblur', 'afterblur'); |
93 | | -} |
94 | 63 |
|
95 | | -// prettier-ignore |
96 | | -const continuousPairsForSimpleEventPlugin: Array<string | DOMEventName> = [ |
97 | 64 | ('drag': DOMEventName), 'drag', |
98 | 65 | ('dragenter': DOMEventName), 'dragEnter', |
99 | 66 | ('dragexit': DOMEventName), 'dragExit', |
@@ -109,10 +76,7 @@ const continuousPairsForSimpleEventPlugin: Array<string | DOMEventName> = [ |
109 | 76 | ('toggle': DOMEventName), 'toggle', |
110 | 77 | ('touchmove': DOMEventName), 'touchMove', |
111 | 78 | ('wheel': DOMEventName), 'wheel', |
112 | | -]; |
113 | 79 |
|
114 | | -// prettier-ignore |
115 | | -const defaultPairsForSimpleEventPlugin: Array<string | DOMEventName> = [ |
116 | 80 | ('abort': DOMEventName), 'abort', |
117 | 81 | (ANIMATION_END: DOMEventName), 'animationEnd', |
118 | 82 | (ANIMATION_ITERATION: DOMEventName), 'animationIteration', |
@@ -140,6 +104,13 @@ const defaultPairsForSimpleEventPlugin: Array<string | DOMEventName> = [ |
140 | 104 | ('waiting': DOMEventName), 'waiting', |
141 | 105 | ]; |
142 | 106 |
|
| 107 | +if (enableCreateEventHandleAPI) { |
| 108 | + // Special case: these two events don't have on* React handler |
| 109 | + // and are only accessible via the createEventHandle API. |
| 110 | + topLevelEventsToReactNames.set('beforeblur', null); |
| 111 | + topLevelEventsToReactNames.set('afterblur', null); |
| 112 | +} |
| 113 | + |
143 | 114 | /** |
144 | 115 | * Turns |
145 | 116 | * ['abort', ...] |
@@ -152,75 +123,19 @@ const defaultPairsForSimpleEventPlugin: Array<string | DOMEventName> = [ |
152 | 123 | * |
153 | 124 | * and registers them. |
154 | 125 | */ |
155 | | -function registerSimplePluginEventsAndSetTheirPriorities( |
156 | | - eventTypes: Array<DOMEventName | string>, |
157 | | - priority: EventPriority, |
158 | | -): void { |
| 126 | +export function registerSimpleEvents() { |
159 | 127 | // As the event types are in pairs of two, we need to iterate |
160 | 128 | // through in twos. The events are in pairs of two to save code |
161 | 129 | // and improve init perf of processing this array, as it will |
162 | 130 | // result in far fewer object allocations and property accesses |
163 | 131 | // if we only use three arrays to process all the categories of |
164 | 132 | // instead of tuples. |
165 | | - for (let i = 0; i < eventTypes.length; i += 2) { |
166 | | - const topEvent = ((eventTypes[i]: any): DOMEventName); |
167 | | - const event = ((eventTypes[i + 1]: any): string); |
| 133 | + for (let i = 0; i < simpleEventPluginNames.length; i += 2) { |
| 134 | + const topEvent = ((simpleEventPluginNames[i]: any): DOMEventName); |
| 135 | + const event = ((simpleEventPluginNames[i + 1]: any): string); |
168 | 136 | const capitalizedEvent = event[0].toUpperCase() + event.slice(1); |
169 | 137 | const reactName = 'on' + capitalizedEvent; |
170 | | - eventPriorities.set(topEvent, priority); |
171 | 138 | topLevelEventsToReactNames.set(topEvent, reactName); |
172 | 139 | registerTwoPhaseEvent(reactName, [topEvent]); |
173 | 140 | } |
174 | 141 | } |
175 | | - |
176 | | -function setEventPriorities( |
177 | | - eventTypes: Array<DOMEventName>, |
178 | | - priority: EventPriority, |
179 | | -): void { |
180 | | - for (let i = 0; i < eventTypes.length; i++) { |
181 | | - eventPriorities.set(eventTypes[i], priority); |
182 | | - } |
183 | | -} |
184 | | - |
185 | | -export function getEventPriorityForPluginSystem( |
186 | | - domEventName: DOMEventName, |
187 | | -): EventPriority { |
188 | | - const priority = eventPriorities.get(domEventName); |
189 | | - // Default to a DefaultEvent. Note: we might |
190 | | - // want to warn if we can't detect the priority |
191 | | - // for the event. |
192 | | - return priority === undefined ? DefaultEvent : priority; |
193 | | -} |
194 | | - |
195 | | -export function getEventPriorityForListenerSystem( |
196 | | - type: DOMEventName, |
197 | | -): EventPriority { |
198 | | - const priority = eventPriorities.get(type); |
199 | | - if (priority !== undefined) { |
200 | | - return priority; |
201 | | - } |
202 | | - if (__DEV__) { |
203 | | - console.warn( |
204 | | - 'The event "%s" provided to createEventHandle() does not have a known priority type.' + |
205 | | - ' This is likely a bug in React.', |
206 | | - type, |
207 | | - ); |
208 | | - } |
209 | | - return DefaultEvent; |
210 | | -} |
211 | | - |
212 | | -export function registerSimpleEvents() { |
213 | | - registerSimplePluginEventsAndSetTheirPriorities( |
214 | | - discreteEventPairsForSimpleEventPlugin, |
215 | | - DiscreteEvent, |
216 | | - ); |
217 | | - registerSimplePluginEventsAndSetTheirPriorities( |
218 | | - continuousPairsForSimpleEventPlugin, |
219 | | - ContinuousEvent, |
220 | | - ); |
221 | | - registerSimplePluginEventsAndSetTheirPriorities( |
222 | | - defaultPairsForSimpleEventPlugin, |
223 | | - DefaultEvent, |
224 | | - ); |
225 | | - setEventPriorities(otherDiscreteEvents, DiscreteEvent); |
226 | | -} |