Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions packages/events/EventPluginHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @flow
*/

import ReactErrorUtils from 'shared/ReactErrorUtils';
Expand All @@ -20,11 +21,16 @@ import {
import accumulateInto from './accumulateInto';
import forEachAccumulated from './forEachAccumulated';

import type {PluginModule} from './PluginModuleType';
import type {ReactSyntheticEvent} from './ReactSyntheticEventType';
import type {Fiber} from 'react-reconciler/src/ReactFiber';
import type {AnyNativeEvent} from './PluginModuleType';

/**
* Internal queue of events that have accumulated their dispatches and are
* waiting to have their dispatches executed.
*/
var eventQueue = null;
var eventQueue: ?(Array<ReactSyntheticEvent> | ReactSyntheticEvent) = null;

/**
* Dispatches an event and releases it back into the pool, unless persistent.
Expand All @@ -33,7 +39,10 @@ var eventQueue = null;
* @param {boolean} simulated If the event is simulated (changes exn behavior)
* @private
*/
var executeDispatchesAndRelease = function(event, simulated) {
var executeDispatchesAndRelease = function(
event: ReactSyntheticEvent,
simulated: boolean,
) {
if (event) {
executeDispatchesInOrder(event, simulated);

Expand Down Expand Up @@ -120,7 +129,7 @@ export const injection = {
* @param {string} registrationName Name of listener (e.g. `onClick`).
* @return {?function} The stored callback.
*/
export function getListener(inst, registrationName) {
export function getListener(inst: Fiber, registrationName: string) {
var listener;

// TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
Expand Down Expand Up @@ -156,15 +165,15 @@ export function getListener(inst, registrationName) {
* @internal
*/
export function extractEvents(
topLevelType,
targetInst,
nativeEvent,
nativeEventTarget,
topLevelType: string,
targetInst: Fiber,
nativeEvent: AnyNativeEvent,
nativeEventTarget: EventTarget,
) {
var events;
for (var i = 0; i < plugins.length; i++) {
// Not every plugin in the ordering may be loaded at runtime.
var possiblePlugin = plugins[i];
var possiblePlugin: PluginModule<AnyNativeEvent> = plugins[i];
if (possiblePlugin) {
var extractedEvents = possiblePlugin.extractEvents(
topLevelType,
Expand All @@ -187,7 +196,9 @@ export function extractEvents(
* @param {*} events An accumulation of synthetic events.
* @internal
*/
export function enqueueEvents(events) {
export function enqueueEvents(
events: Array<ReactSyntheticEvent> | ReactSyntheticEvent,
) {
if (events) {
eventQueue = accumulateInto(eventQueue, events);
}
Expand All @@ -198,11 +209,16 @@ export function enqueueEvents(events) {
*
* @internal
*/
export function processEventQueue(simulated) {
export function processEventQueue(simulated: boolean) {
// Set `eventQueue` to null before processing it so that we can tell if more
// events get enqueued while processing.
var processingEventQueue = eventQueue;
eventQueue = null;

if (!processingEventQueue) {
return;
}

if (simulated) {
forEachAccumulated(
processingEventQueue,
Expand Down
2 changes: 1 addition & 1 deletion packages/events/PluginModuleType.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export type PluginModule<NativeEvent> = {
targetInst: Fiber,
nativeTarget: NativeEvent,
nativeEventTarget: EventTarget,
) => null | ReactSyntheticEvent,
) => ?ReactSyntheticEvent,
tapMoveThreshold?: number,
};
1 change: 1 addition & 0 deletions packages/events/ReactSyntheticEventType.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ export type ReactSyntheticEvent = {
nativeTarget: Event,
nativeEventTarget: EventTarget,
) => ReactSyntheticEvent,
isPersistent: () => boolean,
} & SyntheticEvent<>;
2 changes: 1 addition & 1 deletion packages/events/accumulateInto.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import invariant from 'fbjs/lib/invariant';
*/

function accumulateInto<T>(
current: ?(T | Array<T>),
current: ?(Array<T> | T),
next: T | Array<T>,
): T | Array<T> {
invariant(
Expand Down
2 changes: 1 addition & 1 deletion packages/events/forEachAccumulated.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @param {?} [scope] Scope used as `this` in a callback.
*/
function forEachAccumulated<T>(
arr: ?(T | Array<T>),
arr: ?(Array<T> | T),
cb: (elem: T) => void,
scope: ?any,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import type {ReactNativeBaseComponentViewConfig} from './ReactNativeTypes';

import type {AnyNativeEvent} from 'events/PluginModuleType';
import {
accumulateTwoPhaseDispatches,
accumulateDirectDispatches,
Expand All @@ -28,7 +28,7 @@ const ReactNativeBridgeEventPlugin = {
extractEvents: function(
topLevelType: string,
targetInst: Object,
nativeEvent: Event,
nativeEvent: AnyNativeEvent,
nativeEventTarget: Object,
): ?Object {
const bubbleDispatchConfig = customBubblingEventTypes[topLevelType];
Expand Down