Skip to content

Commit 2dbf22e

Browse files
committed
Put both whitelists in one file
1 parent e8e7a66 commit 2dbf22e

File tree

4 files changed

+40
-46
lines changed

4 files changed

+40
-46
lines changed

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

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import * as inputValueTracking from './inputValueTracking';
2222
import setInnerHTML from './setInnerHTML';
2323
import setTextContent from './setTextContent';
2424
import {listenTo, trapBubbledEvent} from '../events/ReactBrowserEventEmitter';
25+
import {mediaEventTypes} from '../events/BrowserEventConstants';
2526
import * as CSSPropertyOperations from '../shared/CSSPropertyOperations';
2627
import {Namespaces, getIntrinsicNamespace} from '../shared/DOMNamespaces';
2728
import {
@@ -223,34 +224,6 @@ function getOwnerDocumentFromRootContainer(
223224
: rootContainerElement.ownerDocument;
224225
}
225226

226-
// There are so many media events, it makes sense to just
227-
// maintain a list rather than create a `trapBubbledEvent` for each
228-
const mediaEvents = {
229-
topAbort: 'abort',
230-
topCanPlay: 'canplay',
231-
topCanPlayThrough: 'canplaythrough',
232-
topDurationChange: 'durationchange',
233-
topEmptied: 'emptied',
234-
topEncrypted: 'encrypted',
235-
topEnded: 'ended',
236-
topError: 'error',
237-
topLoadedData: 'loadeddata',
238-
topLoadedMetadata: 'loadedmetadata',
239-
topLoadStart: 'loadstart',
240-
topPause: 'pause',
241-
topPlay: 'play',
242-
topPlaying: 'playing',
243-
topProgress: 'progress',
244-
topRateChange: 'ratechange',
245-
topSeeked: 'seeked',
246-
topSeeking: 'seeking',
247-
topStalled: 'stalled',
248-
topSuspend: 'suspend',
249-
topTimeUpdate: 'timeupdate',
250-
topVolumeChange: 'volumechange',
251-
topWaiting: 'waiting',
252-
};
253-
254227
function trapClickOnNonInteractiveElement(node: HTMLElement) {
255228
// Mobile Safari does not fire properly bubble click events on
256229
// non-interactive elements, which means delegated click listeners do not
@@ -472,9 +445,9 @@ export function setInitialProperties(
472445
case 'video':
473446
case 'audio':
474447
// Create listener for each media event
475-
for (const event in mediaEvents) {
476-
if (mediaEvents.hasOwnProperty(event)) {
477-
trapBubbledEvent(event, mediaEvents[event], domElement);
448+
for (const event in mediaEventTypes) {
449+
if (mediaEventTypes.hasOwnProperty(event)) {
450+
trapBubbledEvent(event, mediaEventTypes[event], domElement);
478451
}
479452
}
480453
props = rawProps;
@@ -860,9 +833,9 @@ export function diffHydratedProperties(
860833
case 'video':
861834
case 'audio':
862835
// Create listener for each media event
863-
for (const event in mediaEvents) {
864-
if (mediaEvents.hasOwnProperty(event)) {
865-
trapBubbledEvent(event, mediaEvents[event], domElement);
836+
for (const event in mediaEventTypes) {
837+
if (mediaEventTypes.hasOwnProperty(event)) {
838+
trapBubbledEvent(event, mediaEventTypes[event], domElement);
866839
}
867840
}
868841
break;

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

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import getVendorPrefixedEventName from './getVendorPrefixedEventName';
1414
* bubble (which we trap at a lower node than `document`), binding
1515
* at `document` would cause duplicate events so we don't include them here.
1616
*/
17-
const topLevelTypes = {
17+
export const topLevelTypes = {
1818
topAnimationEnd: getVendorPrefixedEventName('animationend'),
1919
topAnimationIteration: getVendorPrefixedEventName('animationiteration'),
2020
topAnimationStart: getVendorPrefixedEventName('animationstart'),
@@ -63,10 +63,35 @@ const topLevelTypes = {
6363
topWheel: 'wheel',
6464
};
6565

66-
export type TopLevelTypes = $Enum<typeof topLevelTypes>;
67-
68-
const BrowserEventConstants = {
69-
topLevelTypes,
66+
// There are so many media events, it makes sense to just
67+
// maintain a list of them. Note these aren't technically
68+
// "top-level" since they don't bubble. We should come up
69+
// with a better naming convention if we come to refactoring
70+
// the event system.
71+
export const mediaEventTypes = {
72+
topAbort: 'abort',
73+
topCanPlay: 'canplay',
74+
topCanPlayThrough: 'canplaythrough',
75+
topDurationChange: 'durationchange',
76+
topEmptied: 'emptied',
77+
topEncrypted: 'encrypted',
78+
topEnded: 'ended',
79+
topError: 'error',
80+
topLoadedData: 'loadeddata',
81+
topLoadedMetadata: 'loadedmetadata',
82+
topLoadStart: 'loadstart',
83+
topPause: 'pause',
84+
topPlay: 'play',
85+
topPlaying: 'playing',
86+
topProgress: 'progress',
87+
topRateChange: 'ratechange',
88+
topSeeked: 'seeked',
89+
topSeeking: 'seeking',
90+
topStalled: 'stalled',
91+
topSuspend: 'suspend',
92+
topTimeUpdate: 'timeupdate',
93+
topVolumeChange: 'volumechange',
94+
topWaiting: 'waiting',
7095
};
7196

72-
export default BrowserEventConstants;
97+
export type TopLevelTypes = $Enum<typeof topLevelTypes>;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import {
1313
trapCapturedEvent,
1414
} from './ReactDOMEventListener';
1515
import isEventSupported from './isEventSupported';
16-
import BrowserEventConstants from './BrowserEventConstants';
17-
18-
const {topLevelTypes} = BrowserEventConstants;
16+
import {topLevelTypes} from './BrowserEventConstants';
1917

2018
/**
2119
* Summary of `ReactBrowserEventEmitter` event handling:

packages/react-dom/src/test-utils/ReactTestUtils.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import SyntheticEvent from 'events/SyntheticEvent';
1919
import invariant from 'fbjs/lib/invariant';
2020

21-
import BrowserEventConstants from '../events/BrowserEventConstants';
21+
import {topLevelTypes} from '../events/BrowserEventConstants';
2222

2323
const {findDOMNode} = ReactDOM;
2424
const {
@@ -30,8 +30,6 @@ const {
3030
ReactDOMEventListener,
3131
} = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
3232

33-
const topLevelTypes = BrowserEventConstants.topLevelTypes;
34-
3533
function Event(suffix) {}
3634

3735
/**

0 commit comments

Comments
 (0)