-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Conversation
ReactDOM: size: 0.0%, gzip: 0.0% Details of bundled changes.Comparing: f243dea...2b5dde8 react-dom
react-events
Generated by 🚫 dangerJS |
There was a problem hiding this 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; ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (i = capture.length; i-- > 0; ) { | |
for (let i = capture.length - 1; i > 0; i -= 1) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (i = 0, length = bubble.length; i < length; ++i) { | |
for (let i = 0; i < bubble.length; i += 1) { |
There was a problem hiding this comment.
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.
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
andpreventDefault
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.