mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
ModernEventSystem: refine Flow types (#18349)
This commit is contained in:
+1
-2
@@ -7,7 +7,6 @@
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';
|
||||
import type {RootType} from './ReactDOMRoot';
|
||||
|
||||
import {
|
||||
@@ -1112,7 +1111,7 @@ export function registerEvent(
|
||||
// Add the event listener to the target container (falling back to
|
||||
// the target if we didn't find one).
|
||||
listenToTopLevelEvent(
|
||||
((type: any): DOMTopLevelEventType),
|
||||
type,
|
||||
rootContainerInstance,
|
||||
listenerMap,
|
||||
passive,
|
||||
|
||||
+6
-2
@@ -7,6 +7,7 @@
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';
|
||||
import type {EventPriority} from 'shared/ReactTypes';
|
||||
import type {
|
||||
ReactDOMListenerEvent,
|
||||
@@ -41,13 +42,13 @@ function resolveDispatcher() {
|
||||
}
|
||||
|
||||
export function useEvent(
|
||||
type: string,
|
||||
type: DOMTopLevelEventType,
|
||||
options?: EventOptions,
|
||||
): ReactDOMListenerMap {
|
||||
const dispatcher = resolveDispatcher();
|
||||
let capture = false;
|
||||
let passive = undefined; // Undefined means to use the browser default
|
||||
let priority = getEventPriorityForListenerSystem((type: any));
|
||||
let priority;
|
||||
|
||||
if (options != null) {
|
||||
const optionsCapture = options.capture;
|
||||
@@ -64,6 +65,9 @@ export function useEvent(
|
||||
priority = optionsPriority;
|
||||
}
|
||||
}
|
||||
if (priority === undefined) {
|
||||
priority = getEventPriorityForListenerSystem(type);
|
||||
}
|
||||
const event: ReactDOMListenerEvent = {
|
||||
capture,
|
||||
passive,
|
||||
|
||||
+4
-2
@@ -224,8 +224,10 @@ export function getEventPriorityForPluginSystem(
|
||||
return priority === undefined ? ContinuousEvent : priority;
|
||||
}
|
||||
|
||||
export function getEventPriorityForListenerSystem(type: string): EventPriority {
|
||||
const priority = eventPriorities.get(((type: any): TopLevelType));
|
||||
export function getEventPriorityForListenerSystem(
|
||||
type: DOMTopLevelEventType,
|
||||
): EventPriority {
|
||||
const priority = eventPriorities.get(type);
|
||||
if (priority !== undefined) {
|
||||
return priority;
|
||||
}
|
||||
|
||||
@@ -404,7 +404,7 @@ export function attachElementListener(listener: ReactDOMListener): void {
|
||||
// Add the event listener to the target container (falling back to
|
||||
// the target if we didn't find one).
|
||||
listenToTopLevelEvent(
|
||||
((type: any): DOMTopLevelEventType),
|
||||
type,
|
||||
containerEventTarget,
|
||||
listenerMap,
|
||||
passive,
|
||||
|
||||
@@ -13,6 +13,7 @@ import type {
|
||||
ReactEventResponderInstance,
|
||||
EventPriority,
|
||||
} from 'shared/ReactTypes';
|
||||
import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';
|
||||
|
||||
type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | Touch;
|
||||
|
||||
@@ -80,7 +81,7 @@ export type ReactDOMListenerEvent = {|
|
||||
capture: boolean,
|
||||
passive: void | boolean,
|
||||
priority: EventPriority,
|
||||
type: string,
|
||||
type: DOMTopLevelEventType,
|
||||
|};
|
||||
|
||||
export type ReactDOMListenerMap = {|
|
||||
|
||||
Reference in New Issue
Block a user