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

Experimental event API: rework the propagation system for event components #15462

Merged
merged 3 commits into from Apr 23, 2019

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Apr 20, 2019

After much discussion with @necolas and quite a bit of internal testing, we came up with an idea to improve the experimental event API and its propagation system. Rather than return a boolean from the event responder onHandle to indicate if an event should be propagated, all events are now propagated depending on the responder and the event component.

Responders now have the stopLocalPropagation option (required). This tells the event system what it should do we encountering this particular event responder. If this flag is set to true, then when we encounter the same event responder during propagation, we skip calling the event listeners on that responder for that event component.

Furthermore, there was some confusion over the phases on the event object, and so now onHandle has been split into three methods: onEvent, onEventCapture and onRootEvent.

Ref #15257

Correct Drag and Swipe modules

Fix tests

Fix typo
@trueadm
Copy link
Contributor Author

trueadm commented Apr 20, 2019

@necolas it would be good if you could validate this PR locally when you get a chance against your codesandbox. Thanks!

@sizebot
Copy link

sizebot commented Apr 20, 2019

ReactDOM: size: 0.0%, gzip: -0.0%

Details of bundled changes.

Comparing: 5876769...c9a7fa7

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.1% +0.1% 810.7 KB 811.37 KB 185.03 KB 185.25 KB UMD_DEV
react-dom.production.min.js 0.0% -0.0% 103.58 KB 103.58 KB 33.65 KB 33.65 KB UMD_PROD
react-dom.profiling.min.js 0.0% -0.0% 106.73 KB 106.73 KB 34.61 KB 34.61 KB UMD_PROFILING
react-dom.development.js +0.1% +0.1% 805.18 KB 805.85 KB 183.49 KB 183.72 KB NODE_DEV
react-dom.production.min.js 0.0% -0.0% 103.58 KB 103.58 KB 33.1 KB 33.1 KB NODE_PROD
react-dom.profiling.min.js 0.0% -0.0% 106.9 KB 106.9 KB 33.95 KB 33.95 KB NODE_PROFILING
ReactDOM-dev.js +0.1% +0.1% 829.52 KB 830.03 KB 184.88 KB 185.06 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.1% 0.0% 337.24 KB 337.47 KB 62.68 KB 62.69 KB FB_WWW_PROD
ReactDOM-profiling.js +0.1% 0.0% 342.62 KB 342.85 KB 63.6 KB 63.61 KB FB_WWW_PROFILING
react-dom-unstable-fire.development.js +0.1% +0.1% 811.02 KB 811.7 KB 185.17 KB 185.39 KB UMD_DEV
react-dom-unstable-fire.production.min.js 0.0% -0.0% 103.6 KB 103.6 KB 33.66 KB 33.66 KB UMD_PROD
react-dom-unstable-fire.profiling.min.js 0.0% -0.0% 106.75 KB 106.75 KB 34.62 KB 34.62 KB UMD_PROFILING
react-dom-unstable-fire.development.js +0.1% +0.1% 805.5 KB 806.18 KB 183.63 KB 183.86 KB NODE_DEV
react-dom-unstable-fire.production.min.js 0.0% -0.0% 103.59 KB 103.59 KB 33.11 KB 33.11 KB NODE_PROD
react-dom-unstable-fire.profiling.min.js 0.0% -0.0% 106.91 KB 106.91 KB 33.96 KB 33.96 KB NODE_PROFILING
ReactFire-dev.js +0.1% +0.1% 828.71 KB 829.21 KB 184.89 KB 185.06 KB FB_WWW_DEV
ReactFire-prod.js 🔺+0.1% 0.0% 325.21 KB 325.44 KB 60.22 KB 60.23 KB FB_WWW_PROD
ReactFire-profiling.js +0.1% 0.0% 330.56 KB 330.79 KB 61.17 KB 61.18 KB FB_WWW_PROFILING
react-dom-test-utils.development.js 0.0% -0.0% 54.19 KB 54.19 KB 14.98 KB 14.98 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% -0.1% 10.52 KB 10.52 KB 3.9 KB 3.9 KB UMD_PROD
react-dom-test-utils.development.js 0.0% -0.0% 53.91 KB 53.91 KB 14.91 KB 14.91 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.1% 10.31 KB 10.31 KB 3.82 KB 3.82 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.76 KB 60.76 KB 15.85 KB 15.85 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.67 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.43 KB 60.43 KB 15.72 KB 15.72 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.42 KB 10.42 KB 3.57 KB 3.56 KB NODE_PROD
react-dom-server.browser.development.js 0.0% -0.0% 136.73 KB 136.73 KB 35.92 KB 35.92 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% -0.0% 19.18 KB 19.18 KB 7.21 KB 7.21 KB UMD_PROD
react-dom-server.browser.development.js 0.0% -0.0% 132.86 KB 132.86 KB 34.99 KB 34.99 KB NODE_DEV
react-dom-server.browser.production.min.js 0.0% -0.0% 19.1 KB 19.1 KB 7.21 KB 7.2 KB NODE_PROD
ReactDOMServer-dev.js 0.0% -0.0% 134.95 KB 134.95 KB 34.62 KB 34.61 KB FB_WWW_DEV
react-dom-server.node.production.min.js 0.0% -0.0% 19.96 KB 19.96 KB 7.51 KB 7.51 KB NODE_PROD
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.production.min.js 0.0% -0.1% 1.21 KB 1.21 KB 707 B 706 B UMD_PROD
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.browser.production.min.js 0.0% -0.3% 1.05 KB 1.05 KB 638 B 636 B NODE_PROD
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-dom-unstable-fizz.node.production.min.js 0.0% -0.1% 1.1 KB 1.1 KB 668 B 667 B NODE_PROD

react-events

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-events.development.js 0.0% -0.1% 1.59 KB 1.59 KB 688 B 687 B UMD_DEV
react-events.production.min.js 0.0% -0.2% 857 B 857 B 477 B 476 B UMD_PROD
react-events.development.js 0.0% -0.2% 1.4 KB 1.4 KB 626 B 625 B NODE_DEV
react-events.production.min.js 0.0% -0.5% 698 B 698 B 402 B 400 B NODE_PROD
react-events-press.development.js -3.1% -2.2% 17.79 KB 17.23 KB 4.48 KB 4.39 KB UMD_DEV
react-events-press.production.min.js -1.2% -0.4% 6.83 KB 6.75 KB 2.56 KB 2.55 KB UMD_PROD
react-events-press.development.js -3.2% -2.1% 17.62 KB 17.06 KB 4.45 KB 4.35 KB NODE_DEV
react-events-press.production.min.js -1.1% -1.0% 6.66 KB 6.59 KB 2.51 KB 2.49 KB NODE_PROD
ReactEventsPress-dev.js -3.5% -2.4% 15.68 KB 15.13 KB 3.7 KB 3.61 KB FB_WWW_DEV
ReactEventsPress-prod.js 🔺+0.5% -0.3% 12.85 KB 12.91 KB 2.85 KB 2.84 KB FB_WWW_PROD
react-events-hover.development.js -2.3% -2.3% 9.65 KB 9.43 KB 2.37 KB 2.32 KB UMD_DEV
react-events-hover.production.min.js -0.8% -0.3% 3.9 KB 3.87 KB 1.45 KB 1.44 KB UMD_PROD
react-events-hover.development.js -2.4% -2.4% 9.48 KB 9.26 KB 2.33 KB 2.27 KB NODE_DEV
react-events-hover.production.min.js -0.8% -0.6% 3.74 KB 3.71 KB 1.4 KB 1.4 KB NODE_PROD
ReactEventsHover-dev.js -2.4% -2.3% 9.48 KB 9.25 KB 2.33 KB 2.28 KB FB_WWW_DEV
ReactEventsHover-prod.js 🔺+0.4% -0.1% 7.67 KB 7.7 KB 1.82 KB 1.81 KB FB_WWW_PROD
react-events-focus.development.js -6.9% -7.5% 4.52 KB 4.21 KB 1.42 KB 1.32 KB UMD_DEV
react-events-focus.production.min.js -4.8% -5.8% 1.84 KB 1.75 KB 857 B 807 B UMD_PROD
react-events-focus.development.js -7.2% -7.8% 4.35 KB 4.04 KB 1.37 KB 1.27 KB NODE_DEV
react-events-focus.production.min.js -5.3% -6.4% 1.67 KB 1.58 KB 787 B 737 B NODE_PROD
ReactEventsFocus-dev.js -7.4% -8.1% 4.28 KB 3.96 KB 1.35 KB 1.24 KB FB_WWW_DEV
ReactEventsFocus-prod.js -6.4% -6.6% 3.23 KB 3.02 KB 981 B 916 B FB_WWW_PROD
react-events-swipe.development.js -0.3% -2.1% 8.43 KB 8.4 KB 2.63 KB 2.57 KB UMD_DEV
react-events-swipe.production.min.js 🔺+1.7% -0.1% 3.46 KB 3.52 KB 1.61 KB 1.61 KB UMD_PROD
react-events-swipe.development.js -0.4% -2.1% 8.26 KB 8.23 KB 2.59 KB 2.54 KB NODE_DEV
react-events-swipe.production.min.js 🔺+1.8% 🔺+0.1% 3.3 KB 3.36 KB 1.55 KB 1.55 KB NODE_PROD
ReactEventsSwipe-dev.js -0.4% -2.5% 6.36 KB 6.33 KB 1.84 KB 1.8 KB FB_WWW_DEV
ReactEventsSwipe-prod.js 🔺+0.8% -0.5% 5.96 KB 6.01 KB 1.55 KB 1.54 KB FB_WWW_PROD
react-events-drag.development.js -0.2% -2.0% 7.96 KB 7.95 KB 2.51 KB 2.46 KB UMD_DEV
react-events-drag.production.min.js 🔺+1.7% 🔺+1.7% 3.33 KB 3.38 KB 1.51 KB 1.53 KB UMD_PROD
react-events-drag.development.js -0.2% -2.0% 7.79 KB 7.78 KB 2.47 KB 2.42 KB NODE_DEV
react-events-drag.production.min.js 🔺+1.8% 🔺+1.6% 3.17 KB 3.22 KB 1.45 KB 1.47 KB NODE_PROD
ReactEventsDrag-dev.js -0.1% -2.3% 6.05 KB 6.04 KB 1.76 KB 1.72 KB FB_WWW_DEV
ReactEventsDrag-prod.js 🔺+1.1% 🔺+1.9% 5.45 KB 5.51 KB 1.41 KB 1.43 KB FB_WWW_PROD

Generated by 🚫 dangerJS

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.

Looks good. I can test this patch in the sandbox after the merge conflicts with master are resolved.

About the names, we could probably follow existing naming convention in React for bubble vs capture phase, e.g., onClick/onClickCapture.

onBubbledTargetEvent -> onEvent or onTargetEvent
onCapturedTargetEvent -> onEventCapture or onTargetEventCapture

Might be worth avoiding the word target though as it's used in a few places to mean different things at the moment.

@trueadm
Copy link
Contributor Author

trueadm commented Apr 22, 2019

@necolas I've fixed the conflicts with master and applied the name change that you suggested. I'll let you test it first – if it's all good, feel free to merge or wait till I'm back in the office. :)

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.

Sandbox (updated to use this patch) seems to be working as before: https://fburl.com/nfye4390

@trueadm trueadm merged commit 784ebd8 into facebook:master Apr 23, 2019
@trueadm trueadm deleted the event-redesign2 branch April 23, 2019 10:50
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.

None yet

4 participants