dillon1000/react

Commit

Flow type event plugins (#7667)

* Type SimpleEventPlugin and TapEventPlugin

- Renamed file from 'ReactSynteticEvent' to 'ReactSyntheticEventType'
- Fills in the 'any' holes that were left in DispatchConfig type and the
  type annotations in EventPluginRegistry.
- Adds polymorphic PluginModule type and related types
- Uses hack to support indexable properties on 'Touch' type in
  TapEventPlugin

The issue in TapEventPlugin is that the code is accessing one of four
possible properties on the 'Touch' type native event using the bracket
accessor. Classes in Flow don't support using the bracket accessor,
unless you use a declaration and the syntax `[key: Type]: Type`.[1] The
downside of using that here is that we create a global type, which we
may not need in other files.

[1]: https://github.com/facebook/flow/issues/1323

Other options:
- Use looser typing or a '@FixMe' comment and open an issue with Flow to
  support indexing on regular classes.
- Rewrite TapEventPlugin to not use the bracket accessor on 'Touch'. I
  thought the current implementation was elegant and didn't want to
  change it. But we could do something like this:
```
 if (nativeEvent.pageX || nativeEvent.pageY) {
   return axis.page === 'pageX' ? nativeEvent.pageX : nativeEvent.pageY;
 } else {
   var clientAxis = axis.client === 'clientX' ? nativeEvent.clientX : nativeEvent.clientY;
   return nativeEvent[axis.client] + ViewportMetrics[axis.envScroll];
 }
```
Browse files
Changed paths7 files
First-parent comparison
M src/renderers/dom/client/eventPlugins/SimpleEventPlugin.js ModifiedM src/renderers/dom/client/eventPlugins/TapEventPlugin.js ModifiedM src/renderers/shared/stack/event/EventPluginRegistry.js ModifiedA src/renderers/shared/stack/event/PluginModuleType.js AddedD src/renderers/shared/stack/event/ReactSyntheticEvent.js DeletedA src/renderers/shared/stack/event/ReactSyntheticEventType.js AddedM src/renderers/shared/stack/reconciler/ReactInstanceType.js Modified
Patch

Files changed

Rendering syntax-highlighted changes…