77 * @flow
88 */
99
10- import type { EventPriority } from 'shared/ReactTypes' ;
1110import type { DOMEventName } from './DOMEventNames' ;
1211
1312import { registerTwoPhaseEvent } from './EventRegistry' ;
@@ -17,7 +16,6 @@ import {
1716 ANIMATION_START ,
1817 TRANSITION_END ,
1918} from './DOMEventNames' ;
20- import { DiscreteEvent , ContinuousEvent , DefaultEvent } from 'shared/ReactTypes' ;
2119
2220import { enableCreateEventHandleAPI } from 'shared/ReactFeatureFlags' ;
2321
@@ -26,19 +24,8 @@ export const topLevelEventsToReactNames: Map<
2624 string | null ,
2725> = new Map ( ) ;
2826
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-
4027// prettier-ignore
41- const discreteEventPairsForSimpleEventPlugin = [
28+ const simpleEventPluginNames = [
4229 ( 'cancel' : DOMEventName ) , 'cancel' ,
4330 ( 'click' : DOMEventName ) , 'click' ,
4431 ( 'close' : DOMEventName ) , 'close' ,
@@ -73,27 +60,7 @@ const discreteEventPairsForSimpleEventPlugin = [
7360 ( 'touchend' : DOMEventName ) , 'touchEnd' ,
7461 ( 'touchstart' : DOMEventName ) , 'touchStart' ,
7562 ( '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- }
9463
95- // prettier-ignore
96- const continuousPairsForSimpleEventPlugin: Array< string | DOMEventName > = [
9764 ( 'drag' : DOMEventName ) , 'drag' ,
9865 ( 'dragenter' : DOMEventName ) , 'dragEnter' ,
9966 ( 'dragexit' : DOMEventName ) , 'dragExit' ,
@@ -109,10 +76,7 @@ const continuousPairsForSimpleEventPlugin: Array<string | DOMEventName> = [
10976 ( 'toggle' : DOMEventName ) , 'toggle' ,
11077 ( 'touchmove' : DOMEventName ) , 'touchMove' ,
11178 ( 'wheel' : DOMEventName ) , 'wheel' ,
112- ];
11379
114- // prettier-ignore
115- const defaultPairsForSimpleEventPlugin: Array< string | DOMEventName > = [
11680 ( 'abort' : DOMEventName ) , 'abort' ,
11781 ( ANIMATION_END : DOMEventName ) , 'animationEnd' ,
11882 ( ANIMATION_ITERATION : DOMEventName ) , 'animationIteration' ,
@@ -140,6 +104,13 @@ const defaultPairsForSimpleEventPlugin: Array<string | DOMEventName> = [
140104 ( 'waiting' : DOMEventName ) , 'waiting' ,
141105] ;
142106
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+
143114/**
144115 * Turns
145116 * ['abort', ...]
@@ -152,75 +123,19 @@ const defaultPairsForSimpleEventPlugin: Array<string | DOMEventName> = [
152123 *
153124 * and registers them.
154125 */
155- function registerSimplePluginEventsAndSetTheirPriorities(
156- eventTypes: Array< DOMEventName | string > ,
157- priority: EventPriority,
158- ): void {
126+ export function registerSimpleEvents ( ) {
159127 // As the event types are in pairs of two, we need to iterate
160128 // through in twos. The events are in pairs of two to save code
161129 // and improve init perf of processing this array, as it will
162130 // result in far fewer object allocations and property accesses
163131 // if we only use three arrays to process all the categories of
164132 // 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 ) ;
168136 const capitalizedEvent = event [ 0 ] . toUpperCase ( ) + event . slice ( 1 ) ;
169137 const reactName = 'on' + capitalizedEvent ;
170- eventPriorities . set ( topEvent , priority ) ;
171138 topLevelEventsToReactNames . set ( topEvent , reactName ) ;
172139 registerTwoPhaseEvent ( reactName , [ topEvent ] ) ;
173140 }
174141}
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- }
0 commit comments