Skip to content

Conversation

@visigoth
Copy link

@visigoth visigoth commented Jul 4, 2019

Implementing react's SyntheticEvent dispatch algorithm and data types enables
the use of a wide variety of react components. My personal motivation is
react-hotkeys, which requires blur, focus, and key* events.

react-dom does this by mapping the react event names to native event
subscriptions that are required to satisfy them. Then, react-dom pushes them
through its event plugin hub, where plugins transform the native event to
react events. The generated events then go through the capture and bubble
phases.

This set of changes implements most of this in a simpler fashion. It would have
been nice to simply steal react's events package, but it is still private.

This set of changes also copies react's SyntheticEvent data types as of 16.8.6.

With this change, the included example works.

@Yomguithereal
Copy link
Owner

Hello @visigoth. I am having trouble understanding the whole ramifications of what your PR adds. Can you just tell me 1. how you estimate adding those events may impact overall performance & 2. if your PR introduces breaking changes?

@visigoth
Copy link
Author

visigoth commented Jul 5, 2019

  1. i don't think it would impact performance at all. the setup happens at instance creation time, and should happen at props update time (though it doesn't with this stack of commits yet). it is basically a mapping from native events delivered by screen to synthetic events required by react. it is also the same algorithm used by react-dom
  2. yes; i think onXYZ handlers will now always receive react synthetic events rather than blessed native events. the native event is attached to the synthetic event, so components would potentially need to change a little bit, but not too much.

@visigoth
Copy link
Author

visigoth commented Jul 5, 2019

one other thing: this does break things because not all of the events are implemented. only keypress, focus, and blur. all the other events need appropriate entries, but they are not difficult to add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants