Flare: simplify dispatchEvent discrete argument (#15694)

This commit is contained in:
Dominic Gannaway
2019-05-21 16:06:17 +01:00
committed by GitHub
parent a398cbd5a7
commit 121acae090
8 changed files with 29 additions and 42 deletions
+1 -2
View File
@@ -23,7 +23,6 @@ import type {
ReactEventComponentInstance,
ReactResponderContext,
ReactResponderEvent,
ReactResponderDispatchEventOptions,
} from 'shared/ReactTypes';
import type {DOMTopLevelEventType} from 'events/TopLevelEventTypes';
import {batchedUpdates, interactiveUpdates} from 'events/ReactGenericBatching';
@@ -104,7 +103,7 @@ const eventResponderContext: ReactResponderContext = {
dispatchEvent(
possibleEventObject: Object,
listener: ($Shape<PartialEventObject>) => void,
{discrete}: ReactResponderDispatchEventOptions,
discrete: boolean,
): void {
validateResponderContext();
const {target, type, timeStamp} = possibleEventObject;
@@ -403,9 +403,7 @@ describe('DOMEventResponderSystem', () => {
phase: 'bubble',
timeStamp: context.getTimeStamp(),
};
context.dispatchEvent(syntheticEvent, props.onMagicClick, {
discrete: true,
});
context.dispatchEvent(syntheticEvent, props.onMagicClick, true);
}
},
onEventCapture: (event, context, props) => {
@@ -416,9 +414,7 @@ describe('DOMEventResponderSystem', () => {
phase: 'capture',
timeStamp: context.getTimeStamp(),
};
context.dispatchEvent(syntheticEvent, props.onMagicClick, {
discrete: true,
});
context.dispatchEvent(syntheticEvent, props.onMagicClick, true);
}
},
});
@@ -460,7 +456,7 @@ describe('DOMEventResponderSystem', () => {
phase,
timeStamp: context.getTimeStamp(),
};
context.dispatchEvent(pressEvent, props.onPress, {discrete: true});
context.dispatchEvent(pressEvent, props.onPress, true);
context.setTimeout(() => {
if (props.onLongPress) {
@@ -470,9 +466,7 @@ describe('DOMEventResponderSystem', () => {
phase,
timeStamp: context.getTimeStamp(),
};
context.dispatchEvent(longPressEvent, props.onLongPress, {
discrete: true,
});
context.dispatchEvent(longPressEvent, props.onLongPress, true);
}
if (props.onLongPressChange) {
@@ -482,9 +476,11 @@ describe('DOMEventResponderSystem', () => {
phase,
timeStamp: context.getTimeStamp(),
};
context.dispatchEvent(longPressChangeEvent, props.onLongPressChange, {
discrete: true,
});
context.dispatchEvent(
longPressChangeEvent,
props.onLongPressChange,
true,
);
}
}, 500);
}
@@ -842,9 +838,7 @@ describe('DOMEventResponderSystem', () => {
type: 'click',
timeStamp: context.getTimeStamp(),
};
context.dispatchEvent(syntheticEvent, props.onClick, {
discrete: true,
});
context.dispatchEvent(syntheticEvent, props.onClick, true);
},
});
+1 -1
View File
@@ -79,7 +79,7 @@ function dispatchDragEvent(
): void {
const target = ((state.dragTarget: any): Element | Document);
const syntheticEvent = createDragEvent(context, name, target, eventData);
context.dispatchEvent(syntheticEvent, listener, {discrete});
context.dispatchEvent(syntheticEvent, listener, discrete);
}
const DragResponder = {
+6 -6
View File
@@ -93,7 +93,7 @@ function dispatchFocusInEvents(
target,
pointerType,
);
context.dispatchEvent(syntheticEvent, props.onFocus, {discrete: true});
context.dispatchEvent(syntheticEvent, props.onFocus, true);
}
if (props.onFocusChange) {
const listener = () => {
@@ -105,7 +105,7 @@ function dispatchFocusInEvents(
target,
pointerType,
);
context.dispatchEvent(syntheticEvent, listener, {discrete: true});
context.dispatchEvent(syntheticEvent, listener, true);
}
if (props.onFocusVisibleChange && state.isLocalFocusVisible) {
const listener = () => {
@@ -117,7 +117,7 @@ function dispatchFocusInEvents(
target,
pointerType,
);
context.dispatchEvent(syntheticEvent, listener, {discrete: true});
context.dispatchEvent(syntheticEvent, listener, true);
}
}
@@ -135,7 +135,7 @@ function dispatchFocusOutEvents(
target,
pointerType,
);
context.dispatchEvent(syntheticEvent, props.onBlur, {discrete: true});
context.dispatchEvent(syntheticEvent, props.onBlur, true);
}
if (props.onFocusChange) {
const listener = () => {
@@ -147,7 +147,7 @@ function dispatchFocusOutEvents(
target,
pointerType,
);
context.dispatchEvent(syntheticEvent, listener, {discrete: true});
context.dispatchEvent(syntheticEvent, listener, true);
}
dispatchFocusVisibleOutEvent(context, props, state);
}
@@ -169,7 +169,7 @@ function dispatchFocusVisibleOutEvent(
target,
pointerType,
);
context.dispatchEvent(syntheticEvent, listener, {discrete: true});
context.dispatchEvent(syntheticEvent, listener, true);
state.isLocalFocusVisible = false;
}
}
+8 -8
View File
@@ -86,7 +86,7 @@ function dispatchHoverChangeEvent(
'hoverchange',
((state.hoverTarget: any): Element | Document),
);
context.dispatchEvent(syntheticEvent, listener, {discrete: true});
context.dispatchEvent(syntheticEvent, listener, true);
}
function dispatchHoverStartEvents(
@@ -123,9 +123,7 @@ function dispatchHoverStartEvents(
'hoverstart',
((target: any): Element | Document),
);
context.dispatchEvent(syntheticEvent, props.onHoverStart, {
discrete: true,
});
context.dispatchEvent(syntheticEvent, props.onHoverStart, true);
}
if (props.onHoverChange) {
dispatchHoverChangeEvent(context, props, state);
@@ -183,7 +181,7 @@ function dispatchHoverEndEvents(
'hoverend',
((target: any): Element | Document),
);
context.dispatchEvent(syntheticEvent, props.onHoverEnd, {discrete: true});
context.dispatchEvent(syntheticEvent, props.onHoverEnd, true);
}
if (props.onHoverChange) {
dispatchHoverChangeEvent(context, props, state);
@@ -322,9 +320,11 @@ const HoverResponder = {
'hovermove',
state.hoverTarget,
);
context.dispatchEvent(syntheticEvent, props.onHoverMove, {
discrete: false,
});
context.dispatchEvent(
syntheticEvent,
props.onHoverMove,
true,
);
}
}
}
+1 -3
View File
@@ -211,9 +211,7 @@ function dispatchEvent(
pointerType,
event,
);
context.dispatchEvent(syntheticEvent, listener, {
discrete,
});
context.dispatchEvent(syntheticEvent, listener, discrete);
}
function dispatchPressChangeEvent(
+1 -1
View File
@@ -69,7 +69,7 @@ function dispatchSwipeEvent(
) {
const target = ((state.swipeTarget: any): Element | Document);
const syntheticEvent = createSwipeEvent(context, name, target, eventData);
context.dispatchEvent(syntheticEvent, listener, {discrete});
context.dispatchEvent(syntheticEvent, listener, discrete);
}
type SwipeState = {
+1 -5
View File
@@ -158,15 +158,11 @@ export type ReactResponderEvent = {
passiveSupported: boolean,
};
export type ReactResponderDispatchEventOptions = {
discrete?: boolean,
};
export type ReactResponderContext = {
dispatchEvent: (
eventObject: Object,
listener: (Object) => void,
options: ReactResponderDispatchEventOptions,
discrete: boolean,
) => void,
isTargetWithinElement: (
childTarget: Element | Document,