Skip to content
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

ModernEventSystem: refine Flow types #18349

Merged
merged 1 commit into from Mar 19, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Expand Up @@ -7,7 +7,6 @@
* @flow
*/

import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';
import type {RootType} from './ReactDOMRoot';

import {
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions packages/react-dom/src/client/ReactDOMUseEvent.js
Expand Up @@ -7,6 +7,7 @@
* @flow
*/

import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';
import type {EventPriority} from 'shared/ReactTypes';
import type {
ReactDOMListenerEvent,
Expand Down Expand Up @@ -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;
Expand All @@ -64,6 +65,9 @@ export function useEvent(
priority = optionsPriority;
}
}
if (priority === undefined) {
priority = getEventPriorityForListenerSystem(type);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed this when refining the type here. We shouldn't do a lookup for priority if we supply one.

}
const event: ReactDOMListenerEvent = {
capture,
passive,
Expand Down
6 changes: 4 additions & 2 deletions packages/react-dom/src/events/DOMEventProperties.js
Expand Up @@ -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;
}
Expand Down
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/ReactDOMTypes.js
Expand Up @@ -13,6 +13,7 @@ import type {
ReactEventResponderInstance,
EventPriority,
} from 'shared/ReactTypes';
import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';

type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | Touch;

Expand Down Expand Up @@ -80,7 +81,7 @@ export type ReactDOMListenerEvent = {|
capture: boolean,
passive: void | boolean,
priority: EventPriority,
type: string,
type: DOMTopLevelEventType,
|};

export type ReactDOMListenerMap = {|
Expand Down