Skip to content

Commit 86776d4

Browse files
committed
Put both whitelists in one file
1 parent 9b394ac commit 86776d4

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 {
@@ -222,34 +223,6 @@ function getOwnerDocumentFromRootContainer(
222223
: rootContainerElement.ownerDocument;
223224
}
224225

225-
// There are so many media events, it makes sense to just
226-
// maintain a list rather than create a `trapBubbledEvent` for each
227-
const mediaEvents = {
228-
topAbort: 'abort',
229-
topCanPlay: 'canplay',
230-
topCanPlayThrough: 'canplaythrough',
231-
topDurationChange: 'durationchange',
232-
topEmptied: 'emptied',
233-
topEncrypted: 'encrypted',
234-
topEnded: 'ended',
235-
topError: 'error',
236-
topLoadedData: 'loadeddata',
237-
topLoadedMetadata: 'loadedmetadata',
238-
topLoadStart: 'loadstart',
239-
topPause: 'pause',
240-
topPlay: 'play',
241-
topPlaying: 'playing',
242-
topProgress: 'progress',
243-
topRateChange: 'ratechange',
244-
topSeeked: 'seeked',
245-
topSeeking: 'seeking',
246-
topStalled: 'stalled',
247-
topSuspend: 'suspend',
248-
topTimeUpdate: 'timeupdate',
249-
topVolumeChange: 'volumechange',
250-
topWaiting: 'waiting',
251-
};
252-
253226
function trapClickOnNonInteractiveElement(node: HTMLElement) {
254227
// Mobile Safari does not fire properly bubble click events on
255228
// non-interactive elements, which means delegated click listeners do not
@@ -471,9 +444,9 @@ export function setInitialProperties(
471444
case 'video':
472445
case 'audio':
473446
// Create listener for each media event
474-
for (const event in mediaEvents) {
475-
if (mediaEvents.hasOwnProperty(event)) {
476-
trapBubbledEvent(event, mediaEvents[event], domElement);
447+
for (const event in mediaEventTypes) {
448+
if (mediaEventTypes.hasOwnProperty(event)) {
449+
trapBubbledEvent(event, mediaEventTypes[event], domElement);
477450
}
478451
}
479452
props = rawProps;
@@ -847,9 +820,9 @@ export function diffHydratedProperties(
847820
case 'video':
848821
case 'audio':
849822
// Create listener for each media event
850-
for (const event in mediaEvents) {
851-
if (mediaEvents.hasOwnProperty(event)) {
852-
trapBubbledEvent(event, mediaEvents[event], domElement);
823+
for (const event in mediaEventTypes) {
824+
if (mediaEventTypes.hasOwnProperty(event)) {
825+
trapBubbledEvent(event, mediaEventTypes[event], domElement);
853826
}
854827
}
855828
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') || 'animationend',
1919
topAnimationIteration:
2020
getVendorPrefixedEventName('animationiteration') || 'animationiteration',
@@ -66,10 +66,35 @@ const topLevelTypes = {
6666
topWheel: 'wheel',
6767
};
6868

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

75-
export default BrowserEventConstants;
100+
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
@@ -14,12 +14,10 @@ import {
1414
trapCapturedEvent,
1515
} from './ReactDOMEventListener';
1616
import isEventSupported from './isEventSupported';
17-
import BrowserEventConstants from './BrowserEventConstants';
17+
import {topLevelTypes} from './BrowserEventConstants';
1818

1919
export * from 'events/ReactEventEmitterMixin';
2020

21-
const {topLevelTypes} = BrowserEventConstants;
22-
2321
/**
2422
* Summary of `ReactBrowserEventEmitter` event handling:
2523
*

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)