-
Notifications
You must be signed in to change notification settings - Fork 47k
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
[WIP] React Native: Turn HostComponent into an EventEmitter #23278
Closed
JoshuaGross
wants to merge
27
commits into
facebook:main
from
JoshuaGross:jgross-hostcomponent-eventemitter
Closed
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
a33b351
Turn HostComponent into an EventEmitter
JoshuaGross 83e9bc9
_eventListeners is null by default to save on memory/perf
JoshuaGross d73dd66
make listeners nullable
JoshuaGross d35b766
New mechanism for 'once'
JoshuaGross 29bf6a4
fix typo, add comments
JoshuaGross 049a50b
CustomEvent should be typed in react, but implemented in RN repo
JoshuaGross 88cfd64
Handle CustomEvent in ReactNativeBridgeEventPlugin
JoshuaGross f79c3fc
getEventListener returns an array of functions instead of Function | …
JoshuaGross 7f2a1b3
Send data back and forth between Event <> SyntheticEvent in a way tha…
JoshuaGross 7f3a82c
typo
JoshuaGross 5a8047d
fix null deref
JoshuaGross 3f38d4a
fix dispatch / listener code to accept 0 or more listeners and handle…
JoshuaGross 1055e56
fix another site where insts.length needs to == listeners.length
JoshuaGross f1746d2
getListener -> getListeners
JoshuaGross df4a1fd
fix flow
JoshuaGross e5f5199
missing files
JoshuaGross 901742a
prettier
JoshuaGross a78b098
fix lints, clean up
JoshuaGross 633f9eb
initialize listeners to null, only create empty array if there is a l…
JoshuaGross 7adec88
initialize listeners to null, only create empty array if there is a l…
JoshuaGross 5bc7103
var in for loop to make ci happy?
JoshuaGross e50bf63
yarn replace-fork
JoshuaGross f01bd0c
turn for loop into forEach
JoshuaGross d1c0843
yarn prettier-all
JoshuaGross 050211d
attempt to provide a working CustomEvent jest mock so that tests can run
JoshuaGross b37c1af
remove console.log
JoshuaGross a994a3a
fix capture phase registration
JoshuaGross File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
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.
Even if we initialize it lazily, I'm not sure I feel great about adding a new field to every single host instance, even if it's set to null. We're trying to minimize memory usage. And this is doing that for a (relatively uncommon) feature in the tree. I wonder if there's any way we could only pay the cost for the components using it. E.g. some sort of a Map outside. I guess it would have to be a WeakMap. I think we need to get @sebmarkbage opinion on this.
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.
One extra field is probably not the biggest deal here. The big deal is that this object exists at all and that methods use virtual dispatch and that all methods must always be loaded instead of lazily.
The goal was to get rid of it but if the goal is to preserve DOM-like looks, then maybe the whole object can at least be made lazy only if there are refs on it.
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.
By "this object" do you mean the ReactFabricHostComponent object? Can you describe what the alternative would be - just using a raw JSI-bridged native object? I was not aware of those plans. Worth discussing that more for sure if we want to move further in that direction, I'd like to hear pros/cons and it'd be good to have an idea of what the cost of this class and fields are
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.
Do you mean something like - ReactFabricHostComponent is not instantiated for a given ShadowNode until/unless it is requested via the
ref
prop? That is a pretty interesting optimization that I would be happy to drive (in a few months - I'm going on leave soon) - I would be happy with that, hopefully we agree that that is outside of the scope of this PR?