@samitouri / QOS-React / commits / c0a87b2b8d

Remove unnecessary event whitelist in production (#10802)

* Remove unnecessary top level event type whitelist * Record sizes

Dan Abramov committed Sep 27, 2017 at 13:01 UTC c0a87b2b8d81a0099860c6fbcce55db25aaf64d8
1 file changed +51 -41
src/renderers/dom/shared/eventPlugins/SimpleEventPlugin.js
+51 -41
@@ -24,7 +24,7 @@ var SyntheticUIEvent = require('SyntheticUIEvent');
24 var SyntheticWheelEvent = require('SyntheticWheelEvent');
25
26 var getEventCharCode = require('getEventCharCode');
27 -var invariant = require('fbjs/lib/invariant');
27 +var warning = require('fbjs/lib/warning');
28
29 import type {TopLevelTypes} from 'BrowserEventConstants';
30 import type {
@@ -136,6 +136,41 @@ var topLevelEventsToDispatchConfig: {[key: TopLevelTypes]: DispatchConfig} = {};
136 topLevelEventsToDispatchConfig[topEvent] = type;
137 });
138
139 +// Only used in DEV for exhaustiveness validation.
140 +var knownHTMLTopLevelTypes = [
141 + 'topAbort',
142 + 'topCancel',
143 + 'topCanPlay',
144 + 'topCanPlayThrough',
145 + 'topClose',
146 + 'topDurationChange',
147 + 'topEmptied',
148 + 'topEncrypted',
149 + 'topEnded',
150 + 'topError',
151 + 'topInput',
152 + 'topInvalid',
153 + 'topLoad',
154 + 'topLoadedData',
155 + 'topLoadedMetadata',
156 + 'topLoadStart',
157 + 'topPause',
158 + 'topPlay',
159 + 'topPlaying',
160 + 'topProgress',
161 + 'topRateChange',
162 + 'topReset',
163 + 'topSeeked',
164 + 'topSeeking',
165 + 'topStalled',
166 + 'topSubmit',
167 + 'topSuspend',
168 + 'topTimeUpdate',
169 + 'topToggle',
170 + 'topVolumeChange',
171 + 'topWaiting',
172 +];
173 +
174 var SimpleEventPlugin: PluginModule<MouseEvent> = {
175 eventTypes: eventTypes,
176
@@ -151,41 +186,6 @@ var SimpleEventPlugin: PluginModule<MouseEvent> = {
186 }
187 var EventConstructor;
188 switch (topLevelType) {
154 - case 'topAbort':
155 - case 'topCancel':
156 - case 'topCanPlay':
157 - case 'topCanPlayThrough':
158 - case 'topClose':
159 - case 'topDurationChange':
160 - case 'topEmptied':
161 - case 'topEncrypted':
162 - case 'topEnded':
163 - case 'topError':
164 - case 'topInput':
165 - case 'topInvalid':
166 - case 'topLoad':
167 - case 'topLoadedData':
168 - case 'topLoadedMetadata':
169 - case 'topLoadStart':
170 - case 'topPause':
171 - case 'topPlay':
172 - case 'topPlaying':
173 - case 'topProgress':
174 - case 'topRateChange':
175 - case 'topReset':
176 - case 'topSeeked':
177 - case 'topSeeking':
178 - case 'topStalled':
179 - case 'topSubmit':
180 - case 'topSuspend':
181 - case 'topTimeUpdate':
182 - case 'topToggle':
183 - case 'topVolumeChange':
184 - case 'topWaiting':
185 - // HTML Events
186 - // @see http://www.w3.org/TR/html5/index.html#events-0
187 - EventConstructor = SyntheticEvent;
188 - break;
189 case 'topKeyPress':
190 // Firefox creates a keypress event for function keys too. This removes
191 // the unwanted keypress events. Enter is however both printable and
@@ -255,12 +255,22 @@ var SimpleEventPlugin: PluginModule<MouseEvent> = {
255 case 'topPaste':
256 EventConstructor = SyntheticClipboardEvent;
257 break;
258 + default:
259 + if (__DEV__) {
260 + if (knownHTMLTopLevelTypes.indexOf(topLevelType) === -1) {
261 + warning(
262 + false,
263 + 'SimpleEventPlugin: Unhandled event type, `%s`. This warning ' +
264 + 'is likely caused by a bug in React. Please file an issue.',
265 + topLevelType,
266 + );
267 + }
268 + }
269 + // HTML Events
270 + // @see http://www.w3.org/TR/html5/index.html#events-0
271 + EventConstructor = SyntheticEvent;
272 + break;
273 }
259 - invariant(
260 - EventConstructor,
261 - 'SimpleEventPlugin: Unhandled event type, `%s`.',
262 - topLevelType,
263 - );
274 var event = EventConstructor.getPooled(
275 dispatchConfig,
276 targetInst,