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

Consolidate events between EventConstants and BrowserEventEmitter (#9512)

Nathan Hunzaker committed Apr 25, 2017 at 12:24 UTC a9d0deb8e13e9f0b1ee7d2f28a6eec0e7ad2e41d
10 files changed +119 -191
src/renderers/dom/shared/ReactBrowserEventEmitter.js
+3 -79
@@ -14,8 +14,8 @@
14 var EventPluginRegistry = require('EventPluginRegistry');
15 var ReactEventEmitterMixin = require('ReactEventEmitterMixin');
16
17 -var getVendorPrefixedEventName = require('getVendorPrefixedEventName');
17 var isEventSupported = require('isEventSupported');
18 +var {topLevelTypes} = require('BrowserEventConstants');
19
20 /**
21 * Summary of `ReactBrowserEventEmitter` event handling:
@@ -75,82 +75,6 @@ var isEventSupported = require('isEventSupported');
75 var alreadyListeningTo = {};
76 var reactTopListenersCounter = 0;
77
78 -// For events like 'submit' which don't consistently bubble (which we trap at a
79 -// lower node than `document`), binding at `document` would cause duplicate
80 -// events so we don't include them here
81 -var topEventMapping = {
82 - topAbort: 'abort',
83 - topAnimationEnd: getVendorPrefixedEventName('animationend') || 'animationend',
84 - topAnimationIteration: getVendorPrefixedEventName('animationiteration') ||
85 - 'animationiteration',
86 - topAnimationStart: getVendorPrefixedEventName('animationstart') ||
87 - 'animationstart',
88 - topBlur: 'blur',
89 - topCancel: 'cancel',
90 - topCanPlay: 'canplay',
91 - topCanPlayThrough: 'canplaythrough',
92 - topChange: 'change',
93 - topClick: 'click',
94 - topClose: 'close',
95 - topCompositionEnd: 'compositionend',
96 - topCompositionStart: 'compositionstart',
97 - topCompositionUpdate: 'compositionupdate',
98 - topContextMenu: 'contextmenu',
99 - topCopy: 'copy',
100 - topCut: 'cut',
101 - topDoubleClick: 'dblclick',
102 - topDrag: 'drag',
103 - topDragEnd: 'dragend',
104 - topDragEnter: 'dragenter',
105 - topDragExit: 'dragexit',
106 - topDragLeave: 'dragleave',
107 - topDragOver: 'dragover',
108 - topDragStart: 'dragstart',
109 - topDrop: 'drop',
110 - topDurationChange: 'durationchange',
111 - topEmptied: 'emptied',
112 - topEncrypted: 'encrypted',
113 - topEnded: 'ended',
114 - topError: 'error',
115 - topFocus: 'focus',
116 - topInput: 'input',
117 - topKeyDown: 'keydown',
118 - topKeyPress: 'keypress',
119 - topKeyUp: 'keyup',
120 - topLoadedData: 'loadeddata',
121 - topLoadedMetadata: 'loadedmetadata',
122 - topLoadStart: 'loadstart',
123 - topMouseDown: 'mousedown',
124 - topMouseMove: 'mousemove',
125 - topMouseOut: 'mouseout',
126 - topMouseOver: 'mouseover',
127 - topMouseUp: 'mouseup',
128 - topPaste: 'paste',
129 - topPause: 'pause',
130 - topPlay: 'play',
131 - topPlaying: 'playing',
132 - topProgress: 'progress',
133 - topRateChange: 'ratechange',
134 - topScroll: 'scroll',
135 - topSeeked: 'seeked',
136 - topSeeking: 'seeking',
137 - topSelectionChange: 'selectionchange',
138 - topStalled: 'stalled',
139 - topSuspend: 'suspend',
140 - topTextInput: 'textInput',
141 - topTimeUpdate: 'timeupdate',
142 - topToggle: 'toggle',
143 - topTouchCancel: 'touchcancel',
144 - topTouchEnd: 'touchend',
145 - topTouchMove: 'touchmove',
146 - topTouchStart: 'touchstart',
147 - topTransitionEnd: getVendorPrefixedEventName('transitionend') ||
148 - 'transitionend',
149 - topVolumeChange: 'volumechange',
150 - topWaiting: 'waiting',
151 - topWheel: 'wheel',
152 -};
153 -
78 /**
79 * To ensure no conflicts with other potential React instances on the page
80 */
@@ -296,10 +220,10 @@ var ReactBrowserEventEmitter = Object.assign({}, ReactEventEmitterMixin, {
220 );
221 }
222 isListening.topClose = true;
299 - } else if (topEventMapping.hasOwnProperty(dependency)) {
223 + } else if (topLevelTypes.hasOwnProperty(dependency)) {
224 ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent(
225 dependency,
302 - topEventMapping[dependency],
226 + topLevelTypes[dependency],
227 mountAt,
228 );
229 }
src/renderers/dom/shared/ReactEventListener.js
+2 -2
@@ -125,7 +125,7 @@ var ReactEventListener = {
125 /**
126 * Traps top-level events by using event bubbling.
127 *
128 - * @param {string} topLevelType Record from `EventConstants`.
128 + * @param {string} topLevelType Record from `BrowserEventConstants`.
129 * @param {string} handlerBaseName Event name (e.g. "click").
130 * @param {object} element Element on which to attach listener.
131 * @return {?object} An object with a remove function which will forcefully
@@ -146,7 +146,7 @@ var ReactEventListener = {
146 /**
147 * Traps a top-level event by using event capturing.
148 *
149 - * @param {string} topLevelType Record from `EventConstants`.
149 + * @param {string} topLevelType Record from `BrowserEventConstants`.
150 * @param {string} handlerBaseName Event name (e.g. "click").
151 * @param {object} element Element on which to attach listener.
152 * @return {?object} An object with a remove function which will forcefully
src/renderers/dom/shared/eventPlugins/BeforeInputEventPlugin.js
+3 -3
@@ -17,7 +17,7 @@ var FallbackCompositionState = require('FallbackCompositionState');
17 var SyntheticCompositionEvent = require('SyntheticCompositionEvent');
18 var SyntheticInputEvent = require('SyntheticInputEvent');
19
20 -import type {TopLevelTypes} from 'EventConstants';
20 +import type {TopLevelTypes} from 'BrowserEventConstants';
21
22 var END_KEYCODES = [9, 13, 27, 32]; // Tab, Return, Esc, Space
23 var START_KEYCODE = 229;
@@ -275,7 +275,7 @@ function extractCompositionEvent(
275 }
276
277 /**
278 - * @param {string} topLevelType Record from `EventConstants`.
278 + * @param {string} topLevelType Record from `BrowserEventConstants`.
279 * @param {object} nativeEvent Native browser event.
280 * @return {?string} The string corresponding to this `beforeInput` event.
281 */
@@ -329,7 +329,7 @@ function getNativeBeforeInputChars(topLevelType: TopLevelTypes, nativeEvent) {
329 * For browsers that do not provide the `textInput` event, extract the
330 * appropriate string to use for SyntheticInputEvent.
331 *
332 - * @param {string} topLevelType Record from `EventConstants`.
332 + * @param {string} topLevelType Record from `BrowserEventConstants`.
333 * @param {object} nativeEvent Native browser event.
334 * @return {?string} The fallback string for this `beforeInput` event.
335 */
src/renderers/dom/shared/eventPlugins/SimpleEventPlugin.js
+1 -1
@@ -28,7 +28,7 @@ var SyntheticWheelEvent = require('SyntheticWheelEvent');
28 var getEventCharCode = require('getEventCharCode');
29 var invariant = require('fbjs/lib/invariant');
30
31 -import type {TopLevelTypes} from 'EventConstants';
31 +import type {TopLevelTypes} from 'BrowserEventConstants';
32 import type {
33 DispatchConfig,
34 ReactSyntheticEvent,
src/renderers/dom/test/ReactTestUtils.js
+5 -5
@@ -11,7 +11,7 @@
11
12 'use strict';
13
14 -var EventConstants = require('EventConstants');
14 +var BrowserEventConstants = require('BrowserEventConstants');
15 var React = require('react');
16 var ReactDOM = require('react-dom');
17 var ReactFiberTreeReflection = require('ReactFiberTreeReflection');
@@ -33,7 +33,7 @@ var {
33 ReactDOMComponentTree,
34 } = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
35
36 -var topLevelTypes = EventConstants.topLevelTypes;
36 +var topLevelTypes = BrowserEventConstants.topLevelTypes;
37 var {
38 ClassComponent,
39 FunctionalComponent,
@@ -389,7 +389,7 @@ var ReactTestUtils = {
389 /**
390 * Simulates a top level event being dispatched from a raw event that occurred
391 * on an `Element` node.
392 - * @param {Object} topLevelType A type from `EventConstants.topLevelTypes`
392 + * @param {Object} topLevelType A type from `BrowserEventConstants.topLevelTypes`
393 * @param {!Element} node The dom to simulate an event occurring on.
394 * @param {?Event} fakeNativeEvent Fake native event to use in SyntheticEvent.
395 */
@@ -404,7 +404,7 @@ var ReactTestUtils = {
404 /**
405 * Simulates a top level event being dispatched from a raw event that occurred
406 * on the `ReactDOMComponent` `comp`.
407 - * @param {Object} topLevelType A type from `EventConstants.topLevelTypes`.
407 + * @param {Object} topLevelType A type from `BrowserEventConstants.topLevelTypes`.
408 * @param {!ReactDOMComponent} comp
409 * @param {?Event} fakeNativeEvent Fake native event to use in SyntheticEvent.
410 */
@@ -529,7 +529,7 @@ buildSimulators();
529 * - `ReactTestUtils.SimulateNative.mouseMove(Element/ReactDOMComponent)`
530 * - `ReactTestUtils.SimulateNative.mouseIn/ReactDOMComponent)`
531 * - `ReactTestUtils.SimulateNative.mouseOut(Element/ReactDOMComponent)`
532 - * - ... (All keys from `EventConstants.topLevelTypes`)
532 + * - ... (All keys from `BrowserEventConstants.topLevelTypes`)
533 *
534 * Note: Top level event types are a subset of the entire set of handler types
535 * (which include a broader set of "synthetic" events). For example, onDragDone
src/renderers/shared/shared/event/BrowserEventConstants.js new
+103
@@ -0,0 +1,103 @@
1 +/**
2 + * Copyright 2013-present, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + *
9 + * @providesModule BrowserEventConstants
10 + */
11 +
12 +'use strict';
13 +
14 +var getVendorPrefixedEventName = require('getVendorPrefixedEventName');
15 +
16 +/**
17 + * Types of raw signals from the browser caught at the top level.
18 + *
19 + * For events like 'submit' which don't consistently bubble (which we
20 + * trap at a lower node than `document`), binding at `document` would
21 + * cause duplicate events so we don't include them here.
22 + */
23 +var topLevelTypes = {
24 + topAbort: 'abort',
25 + topAnimationEnd: getVendorPrefixedEventName('animationend') || 'animationend',
26 + topAnimationIteration: getVendorPrefixedEventName('animationiteration') ||
27 + 'animationiteration',
28 + topAnimationStart: getVendorPrefixedEventName('animationstart') ||
29 + 'animationstart',
30 + topBlur: 'blur',
31 + topCancel: 'cancel',
32 + topCanPlay: 'canplay',
33 + topCanPlayThrough: 'canplaythrough',
34 + topChange: 'change',
35 + topClick: 'click',
36 + topClose: 'close',
37 + topCompositionEnd: 'compositionend',
38 + topCompositionStart: 'compositionstart',
39 + topCompositionUpdate: 'compositionupdate',
40 + topContextMenu: 'contextmenu',
41 + topCopy: 'copy',
42 + topCut: 'cut',
43 + topDoubleClick: 'dblclick',
44 + topDrag: 'drag',
45 + topDragEnd: 'dragend',
46 + topDragEnter: 'dragenter',
47 + topDragExit: 'dragexit',
48 + topDragLeave: 'dragleave',
49 + topDragOver: 'dragover',
50 + topDragStart: 'dragstart',
51 + topDrop: 'drop',
52 + topDurationChange: 'durationchange',
53 + topEmptied: 'emptied',
54 + topEncrypted: 'encrypted',
55 + topEnded: 'ended',
56 + topError: 'error',
57 + topFocus: 'focus',
58 + topInput: 'input',
59 + topKeyDown: 'keydown',
60 + topKeyPress: 'keypress',
61 + topKeyUp: 'keyup',
62 + topLoadedData: 'loadeddata',
63 + topLoad: 'load',
64 + topLoadedMetadata: 'loadedmetadata',
65 + topLoadStart: 'loadstart',
66 + topMouseDown: 'mousedown',
67 + topMouseMove: 'mousemove',
68 + topMouseOut: 'mouseout',
69 + topMouseOver: 'mouseover',
70 + topMouseUp: 'mouseup',
71 + topPaste: 'paste',
72 + topPause: 'pause',
73 + topPlay: 'play',
74 + topPlaying: 'playing',
75 + topProgress: 'progress',
76 + topRateChange: 'ratechange',
77 + topScroll: 'scroll',
78 + topSeeked: 'seeked',
79 + topSeeking: 'seeking',
80 + topSelectionChange: 'selectionchange',
81 + topStalled: 'stalled',
82 + topSuspend: 'suspend',
83 + topTextInput: 'textInput',
84 + topTimeUpdate: 'timeupdate',
85 + topToggle: 'toggle',
86 + topTouchCancel: 'touchcancel',
87 + topTouchEnd: 'touchend',
88 + topTouchMove: 'touchmove',
89 + topTouchStart: 'touchstart',
90 + topTransitionEnd: getVendorPrefixedEventName('transitionend') ||
91 + 'transitionend',
92 + topVolumeChange: 'volumechange',
93 + topWaiting: 'waiting',
94 + topWheel: 'wheel',
95 +};
96 +
97 +export type TopLevelTypes = $Enum<typeof topLevelTypes>;
98 +
99 +var BrowserEventConstants = {
100 + topLevelTypes,
101 +};
102 +
103 +module.exports = BrowserEventConstants;
src/renderers/shared/shared/event/EventConstants.js deleted
-99
@@ -1,99 +0,0 @@
1 -/**
2 - * Copyright 2013-present, Facebook, Inc.
3 - * All rights reserved.
4 - *
5 - * This source code is licensed under the BSD-style license found in the
6 - * LICENSE file in the root directory of this source tree. An additional grant
7 - * of patent rights can be found in the PATENTS file in the same directory.
8 - *
9 - * @providesModule EventConstants
10 - */
11 -
12 -'use strict';
13 -
14 -export type PropagationPhases = 'bubbled' | 'captured';
15 -
16 -/**
17 - * Types of raw signals from the browser caught at the top level.
18 - */
19 -var topLevelTypes = {
20 - topAbort: null,
21 - topAnimationEnd: null,
22 - topAnimationIteration: null,
23 - topAnimationStart: null,
24 - topBlur: null,
25 - topCancel: null,
26 - topCanPlay: null,
27 - topCanPlayThrough: null,
28 - topChange: null,
29 - topClick: null,
30 - topClose: null,
31 - topCompositionEnd: null,
32 - topCompositionStart: null,
33 - topCompositionUpdate: null,
34 - topContextMenu: null,
35 - topCopy: null,
36 - topCut: null,
37 - topDoubleClick: null,
38 - topDrag: null,
39 - topDragEnd: null,
40 - topDragEnter: null,
41 - topDragExit: null,
42 - topDragLeave: null,
43 - topDragOver: null,
44 - topDragStart: null,
45 - topDrop: null,
46 - topDurationChange: null,
47 - topEmptied: null,
48 - topEncrypted: null,
49 - topEnded: null,
50 - topError: null,
51 - topFocus: null,
52 - topInput: null,
53 - topInvalid: null,
54 - topKeyDown: null,
55 - topKeyPress: null,
56 - topKeyUp: null,
57 - topLoad: null,
58 - topLoadedData: null,
59 - topLoadedMetadata: null,
60 - topLoadStart: null,
61 - topMouseDown: null,
62 - topMouseMove: null,
63 - topMouseOut: null,
64 - topMouseOver: null,
65 - topMouseUp: null,
66 - topPaste: null,
67 - topPause: null,
68 - topPlay: null,
69 - topPlaying: null,
70 - topProgress: null,
71 - topRateChange: null,
72 - topReset: null,
73 - topScroll: null,
74 - topSeeked: null,
75 - topSeeking: null,
76 - topSelectionChange: null,
77 - topStalled: null,
78 - topSubmit: null,
79 - topSuspend: null,
80 - topTextInput: null,
81 - topTimeUpdate: null,
82 - topToggle: null,
83 - topTouchCancel: null,
84 - topTouchEnd: null,
85 - topTouchMove: null,
86 - topTouchStart: null,
87 - topTransitionEnd: null,
88 - topVolumeChange: null,
89 - topWaiting: null,
90 - topWheel: null,
91 -};
92 -
93 -export type TopLevelTypes = $Enum<typeof topLevelTypes>;
94 -
95 -var EventConstants = {
96 - topLevelTypes,
97 -};
98 -
99 -module.exports = EventConstants;
src/renderers/shared/shared/event/EventPropagators.js
+1 -1
@@ -18,7 +18,7 @@ var accumulateInto = require('accumulateInto');
18 var forEachAccumulated = require('forEachAccumulated');
19 var warning = require('fbjs/lib/warning');
20
21 -import type {PropagationPhases} from 'EventConstants';
21 +type PropagationPhases = 'bubbled' | 'captured';
22
23 var getListener = EventPluginHub.getListener;
24
src/renderers/shared/shared/event/eventPlugins/ResponderEventPlugin.js
+1 -1
@@ -420,7 +420,7 @@ function setResponderAndExtractTransfer(
420 * element to claim responder status. Any start event could trigger a transfer
421 * of responderInst. Any move event could trigger a transfer.
422 *
423 - * @param {string} topLevelType Record from `EventConstants`.
423 + * @param {string} topLevelType Record from `BrowserEventConstants`.
424 * @return {boolean} True if a transfer of responder could possibly occur.
425 */
426 function canTriggerTransfer(topLevelType, topLevelInst, nativeEvent) {
src/renderers/shared/shared/event/getVendorPrefixedEventName.js renamed