-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
React Event System: Refactor ElementListenerMap for upgrading #18308
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
facebook-github-bot
added
CLA Signed
React Core Team
Opened by a member of the React Core Team
labels
Mar 13, 2020
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 1e68634:
|
Details of bundled changes.Comparing: 3a0076e...1e68634 react-dom
ReactDOM: size: 0.0%, gzip: 🔺+0.3% Size changes (experimental) |
Details of bundled changes.Comparing: 3a0076e...1e68634 react-dom
ReactDOM: size: 0.0%, gzip: 🔺+0.1% Size changes (stable) |
trueadm
force-pushed
the
change-listener-map
branch
2 times, most recently
from
March 16, 2020 22:38
78bdff8
to
b269aa9
Compare
trueadm
force-pushed
the
change-listener-map
branch
from
March 17, 2020 15:33
b269aa9
to
1e68634
Compare
sebmarkbage
approved these changes
Mar 18, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR refactors the
ElementListenerMap
properties of the existing modern event system, React Flare responder system and the legacy event systems. They all useElementListenerMap
to register an event type against a container. Unfortunately, they don't have a way of co-ordinating when event listeners should be "upgraded" – which is the process of removing and passive/default listener and adding an active listener.There are three states for event listeners and their
passive
flag. They can betrue
,false
orvoid
. If they aretrue
, then the listener is passive. If they arefalse
then the listener is active and finally, if they arevoid
then we use the browser default and we don't specify an option value forpassive
when creating the listener viaaddEventListener
. To wire all this up, we have to unify the value ofElementListenerMap
, so that it's an object telling us of the last previously usedpassive
value. We represent this as{ passive: void | boolean, listener: any => void }
. The upgrade order should go frompassive (true) -> default (void) -> active (false)
.Now we have this refactor in place, it makes it possible for the modern event system and the work going into
useEvent
to live together nicely and have a nice optimial system where they can share event listeners together. For Flare, we change the pattern so it uses the new format, but it really doesn't affect the others as Flare will soon be removed, so we keep theElementListenerMap
keys different (they have a_active
/_passive
suffixes to not clash with the legacy/modern event system listeners).