-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Compose: Documentation: Document withGlobalEvents #15175
Conversation
create or update a window event handler to invoke the callback when an event | ||
occurs. On behalf of the consuming developer, the higher-order component | ||
manages unbinding when the component unmounts, and binding at most a single | ||
event handler for the entire application. |
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.
Interesting. Isn't that a built in feature of addEventListener
to bind once at most?
The event listener list will not contain multiple event listeners with equal type, callback, and capture, as add an event listener prevents that.
https://dom.spec.whatwg.org/#dom-eventtarget-addeventlistener
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.
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.
Interesting. Isn't that a built in feature of addEventListener to bind once at most?
While it's not really relevant for change here, the question does get me wondering whether it really matters to consolidate to a single event handler. I'm trying to recall from the original implementation (#5730) whether I'd thought this was some sort of performance enhancement (i.e. one 'scroll'
handler on the window
rather than one for every component) and if that was the case, whether there's actually any truth to the consolidation being an optimization. I might expect a browser with its low-level language code could iterate to invoke individual callbacks of addEventListener
faster than we could iterate to invoke the Listener
callbacks here in JavaScript.
This pull request seeks to add missing documentation for the
withGlobalEvents
higher-order component creator.Testing Instructions:
Verify by rendered output of "Files changed" tab that produced documentation is sensible.
There are only documentation changes. Thus, there is no expected impact on application runtime.