Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor event object creation for the experimental event API #15295

Merged
merged 4 commits into from
Apr 2, 2019

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Apr 2, 2019

This PR refactors the experimental event API to use event objects at the point of the responder module, rather than via indirection through the responder context dispatchEvent. This allows responder events to be strongly typed and it also means we can avoid using the plugin event system to dispatch the event and instead handle the event directly within the responder system itself.

Furthermore, this removes stopPropagation and preventDefault from event objects. The short term expectation is that their functionality will exist again but, instead of imperative method calls, the behaviour will live inside the React component tree. This will happen in follow up PRs.

@sizebot
Copy link

sizebot commented Apr 2, 2019

ReactDOM: size: 0.0%, gzip: 0.0%

Details of bundled changes.

Comparing: f243dea...2b5dde8

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.2% +0.2% 814.12 KB 815.65 KB 184.33 KB 184.75 KB UMD_DEV
react-dom.production.min.js 0.0% 0.0% 105.15 KB 105.2 KB 33.98 KB 33.98 KB UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 108.13 KB 108.18 KB 34.62 KB 34.62 KB UMD_PROFILING
react-dom.development.js +0.2% +0.2% 808.51 KB 810.04 KB 182.73 KB 183.15 KB NODE_DEV
react-dom.production.min.js 🔺+0.1% 0.0% 105.13 KB 105.18 KB 33.48 KB 33.5 KB NODE_PROD
react-dom.profiling.min.js 0.0% +0.1% 108.23 KB 108.28 KB 34.09 KB 34.11 KB NODE_PROFILING
ReactDOM-dev.js +0.2% +0.2% 833.25 KB 834.79 KB 184.37 KB 184.77 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.1% 🔺+0.3% 331.56 KB 332 KB 61.06 KB 61.25 KB FB_WWW_PROD
ReactDOM-profiling.js +0.1% +0.3% 337.95 KB 338.39 KB 62.41 KB 62.58 KB FB_WWW_PROFILING
react-dom-unstable-fire.development.js +0.2% +0.2% 814.47 KB 815.99 KB 184.47 KB 184.89 KB UMD_DEV
react-dom-unstable-fire.production.min.js 0.0% 0.0% 105.17 KB 105.21 KB 33.99 KB 33.99 KB UMD_PROD
react-dom-unstable-fire.profiling.min.js 0.0% 0.0% 108.14 KB 108.19 KB 34.62 KB 34.63 KB UMD_PROFILING
react-dom-unstable-fire.development.js +0.2% +0.2% 808.85 KB 810.38 KB 182.86 KB 183.29 KB NODE_DEV
react-dom-unstable-fire.production.min.js 🔺+0.1% 0.0% 105.14 KB 105.19 KB 33.49 KB 33.51 KB NODE_PROD
react-dom-unstable-fire.profiling.min.js 0.0% +0.1% 108.24 KB 108.3 KB 34.09 KB 34.12 KB NODE_PROFILING
ReactFire-dev.js +0.2% +0.2% 832.46 KB 834 KB 184.29 KB 184.74 KB FB_WWW_DEV
ReactFire-prod.js 🔺+0.1% 🔺+0.3% 320.22 KB 320.66 KB 58.73 KB 58.91 KB FB_WWW_PROD
ReactFire-profiling.js +0.1% +0.3% 326.55 KB 327 KB 60.08 KB 60.25 KB FB_WWW_PROFILING
react-dom-test-utils.production.min.js 0.0% 0.0% 9.73 KB 9.73 KB 3.58 KB 3.59 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.74 KB 60.74 KB 15.84 KB 15.84 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.69 KB 10.69 KB 3.67 KB 3.66 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.41 KB 60.41 KB 15.71 KB 15.71 KB NODE_DEV
react-dom-server.browser.development.js 0.0% -0.0% 134.78 KB 134.78 KB 35.51 KB 35.51 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% -0.0% 19.05 KB 19.05 KB 7.18 KB 7.18 KB UMD_PROD
react-dom-server.browser.production.min.js 0.0% -0.0% 18.98 KB 18.98 KB 7.17 KB 7.17 KB NODE_PROD
ReactDOMServer-prod.js 0.0% -0.0% 46.19 KB 46.19 KB 10.63 KB 10.63 KB FB_WWW_PROD
react-dom-server.node.development.js 0.0% -0.0% 132.86 KB 132.86 KB 35.12 KB 35.11 KB NODE_DEV
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.66 KB 3.66 KB 1.45 KB 1.45 KB UMD_DEV
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.49 KB 3.49 KB 1.41 KB 1.41 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% -0.1% 3.74 KB 3.74 KB 1.43 KB 1.43 KB NODE_DEV

react-events

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-events.development.js 0.0% -0.2% 1.16 KB 1.16 KB 617 B 616 B UMD_DEV
react-events.production.min.js 0.0% -0.2% 682 B 682 B 431 B 430 B UMD_PROD
react-events.development.js 0.0% -0.2% 996 B 996 B 555 B 554 B NODE_DEV
react-events.production.min.js 0.0% -0.6% 512 B 512 B 354 B 352 B NODE_PROD
react-events-press.development.js -4.4% -5.5% 10.56 KB 10.09 KB 2.73 KB 2.58 KB UMD_DEV
react-events-press.production.min.js -5.3% -2.1% 4.19 KB 3.97 KB 1.51 KB 1.48 KB UMD_PROD
react-events-press.development.js -4.5% -5.6% 10.39 KB 9.92 KB 2.69 KB 2.53 KB NODE_DEV
react-events-press.production.min.js -5.5% -2.3% 4.03 KB 3.81 KB 1.46 KB 1.43 KB NODE_PROD
ReactEventsPress-dev.js -4.1% -5.2% 10.67 KB 10.23 KB 2.71 KB 2.57 KB FB_WWW_DEV
ReactEventsPress-prod.js -5.7% -3.0% 8.29 KB 7.81 KB 1.92 KB 1.86 KB FB_WWW_PROD
react-events-hover.development.js +8.8% +6.4% 4.74 KB 5.15 KB 1.31 KB 1.39 KB UMD_DEV
react-events-hover.production.min.js 🔺+6.9% 🔺+5.9% 2.12 KB 2.26 KB 882 B 934 B UMD_PROD
react-events-hover.development.js +9.2% +6.5% 4.57 KB 4.98 KB 1.27 KB 1.35 KB NODE_DEV
react-events-hover.production.min.js 🔺+7.5% 🔺+6.1% 1.96 KB 2.1 KB 825 B 875 B NODE_PROD
ReactEventsHover-dev.js +10.0% +6.3% 4.54 KB 4.99 KB 1.27 KB 1.35 KB FB_WWW_DEV
ReactEventsHover-prod.js 🔺+10.7% 🔺+8.2% 3.78 KB 4.18 KB 1.02 KB 1.1 KB FB_WWW_PROD
react-events-focus.development.js +14.2% +7.7% 2.95 KB 3.37 KB 1.02 KB 1.1 KB UMD_DEV
react-events-focus.production.min.js 🔺+10.5% 🔺+8.1% 1.39 KB 1.53 KB 677 B 732 B UMD_PROD
react-events-focus.development.js +15.0% +8.4% 2.78 KB 3.2 KB 992 B 1.05 KB NODE_DEV
react-events-focus.production.min.js 🔺+12.0% 🔺+8.5% 1.22 KB 1.37 KB 614 B 666 B NODE_PROD
ReactEventsFocus-dev.js +14.7% +8.4% 2.76 KB 3.17 KB 976 B 1.03 KB FB_WWW_DEV
ReactEventsFocus-prod.js 🔺+17.5% 🔺+12.4% 2.12 KB 2.49 KB 736 B 827 B FB_WWW_PROD
react-events-swipe.development.js +38.5% +48.1% 5.98 KB 8.29 KB 1.72 KB 2.55 KB UMD_DEV
react-events-swipe.production.min.js 🔺+33.3% 🔺+39.4% 2.59 KB 3.45 KB 1.15 KB 1.6 KB UMD_PROD
react-events-swipe.development.js +39.6% +49.8% 5.81 KB 8.12 KB 1.68 KB 2.52 KB NODE_DEV
react-events-swipe.production.min.js 🔺+35.6% 🔺+41.5% 2.43 KB 3.29 KB 1.09 KB 1.54 KB NODE_PROD
ReactEventsSwipe-dev.js +4.6% +4.4% 5.94 KB 6.21 KB 1.7 KB 1.77 KB FB_WWW_DEV
ReactEventsSwipe-prod.js 🔺+4.1% 🔺+6.6% 5.71 KB 5.95 KB 1.43 KB 1.53 KB FB_WWW_PROD
react-events-drag.development.js +43.4% +53.2% 5.27 KB 7.56 KB 1.57 KB 2.4 KB UMD_DEV
react-events-drag.production.min.js 🔺+37.8% 🔺+46.0% 2.33 KB 3.21 KB 1 KB 1.46 KB UMD_PROD
react-events-drag.development.js +44.9% +55.1% 5.1 KB 7.39 KB 1.53 KB 2.37 KB NODE_DEV
react-events-drag.production.min.js 🔺+40.6% 🔺+48.0% 2.17 KB 3.04 KB 972 B 1.41 KB NODE_PROD
ReactEventsDrag-dev.js +5.5% +4.9% 5.28 KB 5.57 KB 1.57 KB 1.64 KB FB_WWW_DEV
ReactEventsDrag-prod.js 🔺+6.0% 🔺+7.8% 4.83 KB 5.12 KB 1.24 KB 1.34 KB FB_WWW_PROD

Generated by 🚫 dangerJS

packages/events/EventTypes.js Outdated Show resolved Hide resolved
packages/react-dom/src/events/DOMEventResponderSystem.js Outdated Show resolved Hide resolved
packages/react-events/src/Hover.js Outdated Show resolved Hide resolved
Copy link
Contributor

@necolas necolas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just minor a nit about using familiar for statements

let i, length;

if (capture !== null) {
for (i = capture.length; i-- > 0; ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (i = capture.length; i-- > 0; ) {
for (let i = capture.length - 1; i > 0; i -= 1) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually find that a bit harder to read, maybe it's me?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find @necolas's version to be more idiomatic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version I used was also the same as the one currently in React, not that it matters.

TBH it's all personal preference, if you both feel strongly, I can address in a follow up later this week :)

}
}
if (bubble !== null) {
for (i = 0, length = bubble.length; i < length; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (i = 0, length = bubble.length; i < length; ++i) {
for (let i = 0; i < bubble.length; i += 1) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the length out intentionally here, just because it's generally faster at runtime.

@trueadm trueadm merged commit 9307932 into facebook:master Apr 2, 2019
@trueadm trueadm deleted the refactor-event-api-objects branch April 2, 2019 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants