-
Notifications
You must be signed in to change notification settings - Fork 50k
Reduce the handleTopLevel() event code indirection #11915
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| import {enqueueEvents, processEventQueue} from 'events/EventPluginHub'; | ||
| import * as EventPluginHub from 'events/EventPluginHub'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why glob this instead of |
||
| import {accumulateTwoPhaseDispatches} from 'events/EventPropagators'; | ||
| import {enqueueStateRestore} from 'events/ReactControlledComponent'; | ||
| import {batchedUpdates} from 'events/ReactGenericBatching'; | ||
|
|
@@ -89,8 +89,7 @@ function manualDispatchChangeEvent(nativeEvent) { | |
| } | ||
|
|
||
| function runEventInBatch(event) { | ||
| enqueueEvents(event); | ||
| processEventQueue(false); | ||
| EventPluginHub.runEventsInBatch(event, false); | ||
| } | ||
|
|
||
| function getInstIfValueChanged(targetInst) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,16 +7,16 @@ | |
| * @flow | ||
| */ | ||
|
|
||
| import {getListener} from 'events/EventPluginHub'; | ||
| import {getListener, runExtractedEventsInBatch} from 'events/EventPluginHub'; | ||
| import {registrationNameModules} from 'events/EventPluginRegistry'; | ||
| import {batchedUpdates} from 'events/ReactGenericBatching'; | ||
| import {handleTopLevel} from 'events/ReactEventEmitterMixin'; | ||
| import warning from 'fbjs/lib/warning'; | ||
|
|
||
| import {getInstanceFromNode} from './ReactNativeComponentTree'; | ||
| import ReactNativeTagHandles from './ReactNativeTagHandles'; | ||
|
|
||
| export * from 'events/ReactEventEmitterMixin'; | ||
| import type {AnyNativeEvent} from 'events/PluginModuleType'; | ||
|
|
||
| export {getListener, registrationNameModules as registrationNames}; | ||
|
|
||
| /** | ||
|
|
@@ -25,7 +25,7 @@ export {getListener, registrationNameModules as registrationNames}; | |
| */ | ||
|
|
||
| // Shared default empty native event - conserve memory. | ||
| const EMPTY_NATIVE_EVENT = {}; | ||
| const EMPTY_NATIVE_EVENT = (({}: any): AnyNativeEvent); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit shady. I actually don't know why it's necessary at all. Native events don't always have event objects?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not that I've ever seen
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (This is specific to React Native) |
||
|
|
||
| /** | ||
| * Selects a subsequence of `Touch`es, without destroying `touches`. | ||
|
|
@@ -90,12 +90,17 @@ const removeTouchesAtIndices = function( | |
| export function _receiveRootNodeIDEvent( | ||
| rootNodeID: number, | ||
| topLevelType: string, | ||
| nativeEventParam: ?Object, | ||
| nativeEventParam: ?AnyNativeEvent, | ||
| ) { | ||
| const nativeEvent = nativeEventParam || EMPTY_NATIVE_EVENT; | ||
| const inst = getInstanceFromNode(rootNodeID); | ||
| batchedUpdates(function() { | ||
| handleTopLevel(topLevelType, inst, nativeEvent, nativeEvent.target); | ||
| runExtractedEventsInBatch( | ||
| topLevelType, | ||
| inst, | ||
| nativeEvent, | ||
| nativeEvent.target, | ||
| ); | ||
| }); | ||
| // React Native doesn't use ReactControlledComponent but if it did, here's | ||
| // where it would do it. | ||
|
|
@@ -111,7 +116,7 @@ export function _receiveRootNodeIDEvent( | |
| export function receiveEvent( | ||
| rootNodeID: number, | ||
| topLevelType: string, | ||
| nativeEventParam: Object, | ||
| nativeEventParam: AnyNativeEvent, | ||
| ) { | ||
| _receiveRootNodeIDEvent(rootNodeID, topLevelType, nativeEventParam); | ||
| } | ||
|
|
||
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.
Happy to bikeshed on naming here. On the one hand it's not exactly clear this is flushing an existing queue as well. On the other hand, as far as I can tell, it's not supported to enqueue more events while we're extracting them (there's an invariant below saying it's not implemented). So the naming is probably fine since it's not supported to enqueue and not flush them anyway.
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.
I think it's fine, and much clearer.