From afec354fd2cdf16b77401b78ea56bf59211ab8ac Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sun, 24 Sep 2017 17:37:53 +0200 Subject: [PATCH 1/2] Remove unnecessary top level event type whitelist --- .../shared/eventPlugins/SimpleEventPlugin.js | 92 ++++++++++--------- 1 file changed, 51 insertions(+), 41 deletions(-) diff --git a/src/renderers/dom/shared/eventPlugins/SimpleEventPlugin.js b/src/renderers/dom/shared/eventPlugins/SimpleEventPlugin.js index 7acdeaca06c3b..35a2382852668 100644 --- a/src/renderers/dom/shared/eventPlugins/SimpleEventPlugin.js +++ b/src/renderers/dom/shared/eventPlugins/SimpleEventPlugin.js @@ -26,7 +26,7 @@ var SyntheticUIEvent = require('SyntheticUIEvent'); var SyntheticWheelEvent = require('SyntheticWheelEvent'); var getEventCharCode = require('getEventCharCode'); -var invariant = require('fbjs/lib/invariant'); +var warning = require('fbjs/lib/warning'); import type {TopLevelTypes} from 'BrowserEventConstants'; import type { @@ -138,6 +138,41 @@ var topLevelEventsToDispatchConfig: {[key: TopLevelTypes]: DispatchConfig} = {}; topLevelEventsToDispatchConfig[topEvent] = type; }); +// Only used in DEV for exhaustiveness validation. +var knownHTMLTopLevelTypes = [ + 'topAbort', + 'topCancel', + 'topCanPlay', + 'topCanPlayThrough', + 'topClose', + 'topDurationChange', + 'topEmptied', + 'topEncrypted', + 'topEnded', + 'topError', + 'topInput', + 'topInvalid', + 'topLoad', + 'topLoadedData', + 'topLoadedMetadata', + 'topLoadStart', + 'topPause', + 'topPlay', + 'topPlaying', + 'topProgress', + 'topRateChange', + 'topReset', + 'topSeeked', + 'topSeeking', + 'topStalled', + 'topSubmit', + 'topSuspend', + 'topTimeUpdate', + 'topToggle', + 'topVolumeChange', + 'topWaiting', +]; + var SimpleEventPlugin: PluginModule = { eventTypes: eventTypes, @@ -153,41 +188,6 @@ var SimpleEventPlugin: PluginModule = { } var EventConstructor; switch (topLevelType) { - case 'topAbort': - case 'topCancel': - case 'topCanPlay': - case 'topCanPlayThrough': - case 'topClose': - case 'topDurationChange': - case 'topEmptied': - case 'topEncrypted': - case 'topEnded': - case 'topError': - case 'topInput': - case 'topInvalid': - case 'topLoad': - case 'topLoadedData': - case 'topLoadedMetadata': - case 'topLoadStart': - case 'topPause': - case 'topPlay': - case 'topPlaying': - case 'topProgress': - case 'topRateChange': - case 'topReset': - case 'topSeeked': - case 'topSeeking': - case 'topStalled': - case 'topSubmit': - case 'topSuspend': - case 'topTimeUpdate': - case 'topToggle': - case 'topVolumeChange': - case 'topWaiting': - // HTML Events - // @see http://www.w3.org/TR/html5/index.html#events-0 - EventConstructor = SyntheticEvent; - break; case 'topKeyPress': // Firefox creates a keypress event for function keys too. This removes // the unwanted keypress events. Enter is however both printable and @@ -257,12 +257,22 @@ var SimpleEventPlugin: PluginModule = { case 'topPaste': EventConstructor = SyntheticClipboardEvent; break; + default: + if (__DEV__) { + if (knownHTMLTopLevelTypes.indexOf(topLevelType) === -1) { + warning( + false, + 'SimpleEventPlugin: Unhandled event type, `%s`. This warning ' + + 'is likely caused by a bug in React. Please file an issue.', + topLevelType, + ); + } + } + // HTML Events + // @see http://www.w3.org/TR/html5/index.html#events-0 + EventConstructor = SyntheticEvent; + break; } - invariant( - EventConstructor, - 'SimpleEventPlugin: Unhandled event type, `%s`.', - topLevelType, - ); var event = EventConstructor.getPooled( dispatchConfig, targetInst, From 36c374c7c6b311953791fe598ca2c5174ed2a3e7 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sun, 24 Sep 2017 17:46:44 +0200 Subject: [PATCH 2/2] Record sizes --- scripts/rollup/results.json | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/rollup/results.json b/scripts/rollup/results.json index 9db87a1c9537b..b56a44fe69e12 100644 --- a/scripts/rollup/results.json +++ b/scripts/rollup/results.json @@ -25,28 +25,28 @@ "gzip": 6767 }, "react-dom.development.js (UMD_DEV)": { - "size": 650284, - "gzip": 148956 + "size": 650200, + "gzip": 149037 }, "react-dom.production.min.js (UMD_PROD)": { - "size": 103018, - "gzip": 32102 + "size": 102429, + "gzip": 31953 }, "react-dom.development.js (NODE_DEV)": { - "size": 611085, - "gzip": 140117 + "size": 611001, + "gzip": 140196 }, "react-dom.production.min.js (NODE_PROD)": { - "size": 108328, - "gzip": 33945 + "size": 107766, + "gzip": 33808 }, "ReactDOMFiber-dev.js (FB_DEV)": { - "size": 607451, - "gzip": 139504 + "size": 607385, + "gzip": 139587 }, "ReactDOMFiber-prod.js (FB_PROD)": { - "size": 421286, - "gzip": 94454 + "size": 420318, + "gzip": 94289 }, "react-dom-test-utils.development.js (NODE_DEV)": { "size": 43849,