[Flare] Refine flow type annotations (#15950)

This commit is contained in:
Dominic Gannaway 2019-06-21 12:32:43 +01:00 committed by GitHub
parent 4f92fbce5c
commit 34ce57ae75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 147 additions and 158 deletions

View File

@ -45,8 +45,10 @@ import {
import dangerousStyleValue from '../shared/dangerousStyleValue'; import dangerousStyleValue from '../shared/dangerousStyleValue';
import type {DOMContainer} from './ReactDOM'; import type {DOMContainer} from './ReactDOM';
import type {ReactEventComponentInstance} from 'shared/ReactTypes'; import type {
import type {ReactDOMEventResponder} from 'shared/ReactDOMTypes'; ReactDOMEventResponder,
ReactDOMEventComponentInstance,
} from 'shared/ReactDOMTypes';
import { import {
mountEventResponder, mountEventResponder,
unmountEventResponder, unmountEventResponder,
@ -102,7 +104,6 @@ export type UpdatePayload = Array<mixed>;
export type ChildSet = void; // Unused export type ChildSet = void; // Unused
export type TimeoutHandle = TimeoutID; export type TimeoutHandle = TimeoutID;
export type NoTimeout = -1; export type NoTimeout = -1;
export type EventResponder = ReactDOMEventResponder;
import { import {
enableSuspenseServerRenderer, enableSuspenseServerRenderer,
@ -900,7 +901,7 @@ export function didNotFindHydratableSuspenseInstance(
} }
export function mountEventComponent( export function mountEventComponent(
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactDOMEventComponentInstance,
): void { ): void {
if (enableEventAPI) { if (enableEventAPI) {
const rootContainerInstance = ((eventComponentInstance.rootInstance: any): Container); const rootContainerInstance = ((eventComponentInstance.rootInstance: any): Container);
@ -926,13 +927,13 @@ export function mountEventComponent(
} }
export function updateEventComponent( export function updateEventComponent(
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactDOMEventComponentInstance,
): void { ): void {
// NO-OP, why might use this in the future // NO-OP, why might use this in the future
} }
export function unmountEventComponent( export function unmountEventComponent(
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactDOMEventComponentInstance,
): void { ): void {
if (enableEventAPI) { if (enableEventAPI) {
// TODO stop listening to targetEventTypes // TODO stop listening to targetEventTypes

View File

@ -18,12 +18,10 @@ import {
HostComponent, HostComponent,
FunctionComponent, FunctionComponent,
} from 'shared/ReactWorkTags'; } from 'shared/ReactWorkTags';
import type { import type {EventPriority} from 'shared/ReactTypes';
ReactEventComponentInstance,
EventPriority,
} from 'shared/ReactTypes';
import type { import type {
ReactDOMEventResponder, ReactDOMEventResponder,
ReactDOMEventComponentInstance,
ReactDOMEventResponderEventType, ReactDOMEventResponderEventType,
ReactDOMResponderContext, ReactDOMResponderContext,
ReactDOMResponderEvent, ReactDOMResponderEvent,
@ -86,7 +84,7 @@ type ResponderTimeout = {|
|}; |};
type ResponderTimer = {| type ResponderTimer = {|
instance: ReactEventComponentInstance, instance: ReactDOMEventComponentInstance,
func: () => void, func: () => void,
id: number, id: number,
timeStamp: number, timeStamp: number,
@ -95,13 +93,13 @@ type ResponderTimer = {|
const activeTimeouts: Map<number, ResponderTimeout> = new Map(); const activeTimeouts: Map<number, ResponderTimeout> = new Map();
const rootEventTypesToEventComponentInstances: Map< const rootEventTypesToEventComponentInstances: Map<
DOMTopLevelEventType | string, DOMTopLevelEventType | string,
Set<ReactEventComponentInstance>, Set<ReactDOMEventComponentInstance>,
> = new Map(); > = new Map();
const targetEventTypeCached: Map< const targetEventTypeCached: Map<
Array<ReactDOMEventResponderEventType>, Array<ReactDOMEventResponderEventType>,
Set<string>, Set<string>,
> = new Map(); > = new Map();
const ownershipChangeListeners: Set<ReactEventComponentInstance> = new Set(); const ownershipChangeListeners: Set<ReactDOMEventComponentInstance> = new Set();
const PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map; const PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
const eventListeners: const eventListeners:
| WeakMap | WeakMap
@ -115,7 +113,7 @@ let continueLocalPropagation = false;
let currentTimeStamp = 0; let currentTimeStamp = 0;
let currentTimers = new Map(); let currentTimers = new Map();
let currentInstance: null | ReactEventComponentInstance = null; let currentInstance: null | ReactDOMEventComponentInstance = null;
let currentEventQueue: null | EventQueue = null; let currentEventQueue: null | EventQueue = null;
let currentTimerIDCounter = 0; let currentTimerIDCounter = 0;
let currentDocument: null | Document = null; let currentDocument: null | Document = null;
@ -215,7 +213,7 @@ const eventResponderContext: ReactDOMResponderContext = {
validateResponderContext(); validateResponderContext();
if (target != null) { if (target != null) {
let fiber = getClosestInstanceFromNode(target); let fiber = getClosestInstanceFromNode(target);
const currentFiber = ((currentInstance: any): ReactEventComponentInstance) const currentFiber = ((currentInstance: any): ReactDOMEventComponentInstance)
.currentFiber; .currentFiber;
while (fiber !== null) { while (fiber !== null) {
@ -233,12 +231,12 @@ const eventResponderContext: ReactDOMResponderContext = {
}, },
isTargetWithinEventResponderScope(target: Element | Document): boolean { isTargetWithinEventResponderScope(target: Element | Document): boolean {
validateResponderContext(); validateResponderContext();
const componentInstance = ((currentInstance: any): ReactEventComponentInstance); const componentInstance = ((currentInstance: any): ReactDOMEventComponentInstance);
const responder = componentInstance.responder; const responder = componentInstance.responder;
if (target != null) { if (target != null) {
let fiber = getClosestInstanceFromNode(target); let fiber = getClosestInstanceFromNode(target);
const currentFiber = ((currentInstance: any): ReactEventComponentInstance) const currentFiber = ((currentInstance: any): ReactDOMEventComponentInstance)
.currentFiber; .currentFiber;
while (fiber !== null) { while (fiber !== null) {
if (fiber.tag === EventComponent) { if (fiber.tag === EventComponent) {
@ -284,7 +282,7 @@ const eventResponderContext: ReactDOMResponderContext = {
listenToResponderEventTypesImpl(rootEventTypes, activeDocument); listenToResponderEventTypesImpl(rootEventTypes, activeDocument);
for (let i = 0; i < rootEventTypes.length; i++) { for (let i = 0; i < rootEventTypes.length; i++) {
const rootEventType = rootEventTypes[i]; const rootEventType = rootEventTypes[i];
const eventComponentInstance = ((currentInstance: any): ReactEventComponentInstance); const eventComponentInstance = ((currentInstance: any): ReactDOMEventComponentInstance);
registerRootEventType(rootEventType, eventComponentInstance); registerRootEventType(rootEventType, eventComponentInstance);
} }
}, },
@ -315,14 +313,14 @@ const eventResponderContext: ReactDOMResponderContext = {
let rootEventComponents = rootEventTypesToEventComponentInstances.get( let rootEventComponents = rootEventTypesToEventComponentInstances.get(
listeningName, listeningName,
); );
let rootEventTypesSet = ((currentInstance: any): ReactEventComponentInstance) let rootEventTypesSet = ((currentInstance: any): ReactDOMEventComponentInstance)
.rootEventTypes; .rootEventTypes;
if (rootEventTypesSet !== null) { if (rootEventTypesSet !== null) {
rootEventTypesSet.delete(listeningName); rootEventTypesSet.delete(listeningName);
} }
if (rootEventComponents !== undefined) { if (rootEventComponents !== undefined) {
rootEventComponents.delete( rootEventComponents.delete(
((currentInstance: any): ReactEventComponentInstance), ((currentInstance: any): ReactDOMEventComponentInstance),
); );
} }
} }
@ -343,7 +341,7 @@ const eventResponderContext: ReactDOMResponderContext = {
releaseOwnership(): boolean { releaseOwnership(): boolean {
validateResponderContext(); validateResponderContext();
return releaseOwnershipForEventComponentInstance( return releaseOwnershipForEventComponentInstance(
((currentInstance: any): ReactEventComponentInstance), ((currentInstance: any): ReactDOMEventComponentInstance),
); );
}, },
setTimeout(func: () => void, delay): number { setTimeout(func: () => void, delay): number {
@ -366,7 +364,7 @@ const eventResponderContext: ReactDOMResponderContext = {
currentTimers.set(delay, timeout); currentTimers.set(delay, timeout);
} }
timeout.timers.set(timerId, { timeout.timers.set(timerId, {
instance: ((currentInstance: any): ReactEventComponentInstance), instance: ((currentInstance: any): ReactDOMEventComponentInstance),
func, func,
id: timerId, id: timerId,
timeStamp: currentTimeStamp, timeStamp: currentTimeStamp,
@ -389,7 +387,7 @@ const eventResponderContext: ReactDOMResponderContext = {
getFocusableElementsInScope(): Array<HTMLElement> { getFocusableElementsInScope(): Array<HTMLElement> {
validateResponderContext(); validateResponderContext();
const focusableElements = []; const focusableElements = [];
const eventComponentInstance = ((currentInstance: any): ReactEventComponentInstance); const eventComponentInstance = ((currentInstance: any): ReactDOMEventComponentInstance);
const child = ((eventComponentInstance.currentFiber: any): Fiber).child; const child = ((eventComponentInstance.currentFiber: any): Fiber).child;
if (child !== null) { if (child !== null) {
@ -404,7 +402,7 @@ const eventResponderContext: ReactDOMResponderContext = {
const target = event.target; const target = event.target;
let fiber = getClosestInstanceFromNode(target); let fiber = getClosestInstanceFromNode(target);
let hostComponent = target; let hostComponent = target;
const currentResponder = ((currentInstance: any): ReactEventComponentInstance) const currentResponder = ((currentInstance: any): ReactDOMEventComponentInstance)
.responder; .responder;
while (fiber !== null) { while (fiber !== null) {
@ -433,7 +431,7 @@ const eventResponderContext: ReactDOMResponderContext = {
): boolean { ): boolean {
validateResponderContext(); validateResponderContext();
let fiber = getClosestInstanceFromNode(target); let fiber = getClosestInstanceFromNode(target);
const currentResponder = ((currentInstance: any): ReactEventComponentInstance) const currentResponder = ((currentInstance: any): ReactDOMEventComponentInstance)
.responder; .responder;
while (fiber !== null) { while (fiber !== null) {
@ -490,7 +488,7 @@ function getActiveDocument(): Document {
} }
function releaseOwnershipForEventComponentInstance( function releaseOwnershipForEventComponentInstance(
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactDOMEventComponentInstance,
): boolean { ): boolean {
if (globalOwner === eventComponentInstance) { if (globalOwner === eventComponentInstance) {
globalOwner = null; globalOwner = null;
@ -679,8 +677,8 @@ function getDOMTargetEventTypesSet(
function storeTargetEventResponderInstance( function storeTargetEventResponderInstance(
listeningName: string, listeningName: string,
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactDOMEventComponentInstance,
eventResponderInstances: Array<ReactEventComponentInstance>, eventResponderInstances: Array<ReactDOMEventComponentInstance>,
eventComponentResponders: null | Set<ReactDOMEventResponder>, eventComponentResponders: null | Set<ReactDOMEventResponder>,
): void { ): void {
const responder = eventComponentInstance.responder; const responder = eventComponentInstance.responder;
@ -700,7 +698,7 @@ function storeTargetEventResponderInstance(
function getTargetEventResponderInstances( function getTargetEventResponderInstances(
listeningName: string, listeningName: string,
targetFiber: null | Fiber, targetFiber: null | Fiber,
): Array<ReactEventComponentInstance> { ): Array<ReactDOMEventComponentInstance> {
// We use this to know if we should check add hooks. If there are // We use this to know if we should check add hooks. If there are
// no event targets, then we don't add the hook forms. // no event targets, then we don't add the hook forms.
const eventComponentResponders = new Set(); const eventComponentResponders = new Set();
@ -743,7 +741,7 @@ function getTargetEventResponderInstances(
function getRootEventResponderInstances( function getRootEventResponderInstances(
listeningName: string, listeningName: string,
): Array<ReactEventComponentInstance> { ): Array<ReactDOMEventComponentInstance> {
const eventResponderInstances = []; const eventResponderInstances = [];
const rootEventInstances = rootEventTypesToEventComponentInstances.get( const rootEventInstances = rootEventTypesToEventComponentInstances.get(
listeningName, listeningName,
@ -760,7 +758,7 @@ function getRootEventResponderInstances(
} }
function shouldSkipEventComponent( function shouldSkipEventComponent(
eventResponderInstance: ReactEventComponentInstance, eventResponderInstance: ReactDOMEventComponentInstance,
responder: ReactDOMEventResponder, responder: ReactDOMEventResponder,
propagatedEventResponders: null | Set<ReactDOMEventResponder>, propagatedEventResponders: null | Set<ReactDOMEventResponder>,
localPropagation: boolean, localPropagation: boolean,
@ -841,7 +839,7 @@ function traverseAndHandleEventResponderInstances(
if ( if (
shouldSkipEventComponent( shouldSkipEventComponent(
targetEventResponderInstance, targetEventResponderInstance,
responder, ((responder: any): ReactDOMEventResponder),
propagatedEventResponders, propagatedEventResponders,
localPropagation, localPropagation,
) )
@ -874,7 +872,7 @@ function traverseAndHandleEventResponderInstances(
if ( if (
shouldSkipEventComponent( shouldSkipEventComponent(
targetEventResponderInstance, targetEventResponderInstance,
responder, ((responder: any): ReactDOMEventResponder),
propagatedEventResponders, propagatedEventResponders,
localPropagation, localPropagation,
) )
@ -933,7 +931,8 @@ function triggerOwnershipListeners(): void {
const instance = listeningInstances[i]; const instance = listeningInstances[i];
const {props, responder, state} = instance; const {props, responder, state} = instance;
currentInstance = instance; currentInstance = instance;
const onOwnershipChange = responder.onOwnershipChange; const onOwnershipChange = ((responder: any): ReactDOMEventResponder)
.onOwnershipChange;
if (onOwnershipChange !== undefined) { if (onOwnershipChange !== undefined) {
onOwnershipChange(eventResponderContext, props, state); onOwnershipChange(eventResponderContext, props, state);
} }
@ -944,9 +943,9 @@ function triggerOwnershipListeners(): void {
} }
export function mountEventResponder( export function mountEventResponder(
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactDOMEventComponentInstance,
) { ) {
const responder = eventComponentInstance.responder; const responder = ((eventComponentInstance.responder: any): ReactDOMEventResponder);
if (responder.onOwnershipChange !== undefined) { if (responder.onOwnershipChange !== undefined) {
ownershipChangeListeners.add(eventComponentInstance); ownershipChangeListeners.add(eventComponentInstance);
} }
@ -966,9 +965,9 @@ export function mountEventResponder(
} }
export function unmountEventResponder( export function unmountEventResponder(
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactDOMEventComponentInstance,
): void { ): void {
const responder = eventComponentInstance.responder; const responder = ((eventComponentInstance.responder: any): ReactDOMEventResponder);
const onUnmount = responder.onUnmount; const onUnmount = responder.onUnmount;
if (onUnmount !== undefined) { if (onUnmount !== undefined) {
let {props, state} = eventComponentInstance; let {props, state} = eventComponentInstance;
@ -1054,7 +1053,7 @@ export function dispatchEventForResponderEventSystem(
} }
export function addRootEventTypesForComponentInstance( export function addRootEventTypesForComponentInstance(
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactDOMEventComponentInstance,
rootEventTypes: Array<ReactDOMEventResponderEventType>, rootEventTypes: Array<ReactDOMEventResponderEventType>,
): void { ): void {
for (let i = 0; i < rootEventTypes.length; i++) { for (let i = 0; i < rootEventTypes.length; i++) {
@ -1065,7 +1064,7 @@ export function addRootEventTypesForComponentInstance(
function registerRootEventType( function registerRootEventType(
rootEventType: ReactDOMEventResponderEventType, rootEventType: ReactDOMEventResponderEventType,
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactDOMEventComponentInstance,
): void { ): void {
let name = rootEventType; let name = rootEventType;
let passive = true; let passive = true;

View File

@ -8,6 +8,7 @@
*/ */
import type { import type {
ReactDOMEventResponder,
ReactDOMResponderEvent, ReactDOMResponderEvent,
ReactDOMResponderContext, ReactDOMResponderContext,
} from 'shared/ReactDOMTypes'; } from 'shared/ReactDOMTypes';
@ -84,7 +85,7 @@ function dispatchDragEvent(
context.dispatchEvent(syntheticEvent, listener, eventPriority); context.dispatchEvent(syntheticEvent, listener, eventPriority);
} }
const DragResponder = { const DragResponder: ReactDOMEventResponder = {
displayName: 'Drag', displayName: 'Drag',
targetEventTypes, targetEventTypes,
createInitialState(): DragState { createInitialState(): DragState {

View File

@ -8,6 +8,7 @@
*/ */
import type { import type {
ReactDOMEventResponder,
ReactDOMResponderEvent, ReactDOMResponderEvent,
ReactDOMResponderContext, ReactDOMResponderContext,
PointerType, PointerType,
@ -216,7 +217,7 @@ function handleRootPointerEvent(
let isGlobalFocusVisible = true; let isGlobalFocusVisible = true;
const FocusResponder = { const FocusResponder: ReactDOMEventResponder = {
displayName: 'Focus', displayName: 'Focus',
targetEventTypes, targetEventTypes,
rootEventTypes, rootEventTypes,

View File

@ -7,6 +7,7 @@
* @flow * @flow
*/ */
import type { import type {
ReactDOMEventResponder,
ReactDOMResponderEvent, ReactDOMResponderEvent,
ReactDOMResponderContext, ReactDOMResponderContext,
} from 'shared/ReactDOMTypes'; } from 'shared/ReactDOMTypes';
@ -45,7 +46,7 @@ function getFirstFocusableElement(
} }
} }
const FocusScopeResponder = { const FocusScopeResponder: ReactDOMEventResponder = {
displayName: 'FocusScope', displayName: 'FocusScope',
targetEventTypes, targetEventTypes,
rootEventTypes, rootEventTypes,

View File

@ -8,6 +8,7 @@
*/ */
import type { import type {
ReactDOMEventResponder,
ReactDOMResponderEvent, ReactDOMResponderEvent,
ReactDOMResponderContext, ReactDOMResponderContext,
} from 'shared/ReactDOMTypes'; } from 'shared/ReactDOMTypes';
@ -273,7 +274,7 @@ function isEmulatedMouseEvent(event, state) {
); );
} }
const HoverResponder = { const HoverResponder: ReactDOMEventResponder = {
displayName: 'Hover', displayName: 'Hover',
targetEventTypes, targetEventTypes,
createInitialState() { createInitialState() {

View File

@ -8,6 +8,7 @@
*/ */
import type { import type {
ReactDOMEventResponder,
ReactDOMResponderEvent, ReactDOMResponderEvent,
ReactDOMResponderContext, ReactDOMResponderContext,
PointerType, PointerType,
@ -622,7 +623,7 @@ function updateIsPressWithinResponderRegion(
state.isPressWithinResponderRegion = isPressWithinResponderRegion; state.isPressWithinResponderRegion = isPressWithinResponderRegion;
} }
const PressResponder = { const PressResponder: ReactDOMEventResponder = {
displayName: 'Press', displayName: 'Press',
targetEventTypes, targetEventTypes,
createInitialState(): PressState { createInitialState(): PressState {

View File

@ -8,6 +8,7 @@
*/ */
import type { import type {
ReactDOMEventResponder,
ReactDOMResponderEvent, ReactDOMResponderEvent,
ReactDOMResponderContext, ReactDOMResponderContext,
PointerType, PointerType,
@ -116,7 +117,7 @@ function dispatchEvent(
context.dispatchEvent(syntheticEvent, listener, eventPriority); context.dispatchEvent(syntheticEvent, listener, eventPriority);
} }
const ScrollResponder = { const ScrollResponder: ReactDOMEventResponder = {
displayName: 'Scroll', displayName: 'Scroll',
targetEventTypes, targetEventTypes,
createInitialState() { createInitialState() {

View File

@ -8,6 +8,7 @@
*/ */
import type { import type {
ReactDOMEventResponder,
ReactDOMResponderEvent, ReactDOMResponderEvent,
ReactDOMResponderContext, ReactDOMResponderContext,
} from 'shared/ReactDOMTypes'; } from 'shared/ReactDOMTypes';
@ -88,7 +89,7 @@ type SwipeState = {
y: number, y: number,
}; };
const SwipeResponder = { const SwipeResponder: ReactDOMEventResponder = {
displayName: 'Scroll', displayName: 'Scroll',
targetEventTypes, targetEventTypes,
createInitialState(): SwipeState { createInitialState(): SwipeState {

View File

@ -436,19 +436,19 @@ export function replaceContainerChildren(
): void {} ): void {}
export function mountEventComponent( export function mountEventComponent(
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactEventComponentInstance<any, any, any>,
) { ) {
throw new Error('Not yet implemented.'); throw new Error('Not yet implemented.');
} }
export function updateEventComponent( export function updateEventComponent(
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactEventComponentInstance<any, any, any>,
) { ) {
throw new Error('Not yet implemented.'); throw new Error('Not yet implemented.');
} }
export function unmountEventComponent( export function unmountEventComponent(
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactEventComponentInstance<any, any, any>,
): void { ): void {
throw new Error('Not yet implemented.'); throw new Error('Not yet implemented.');
} }

View File

@ -497,19 +497,19 @@ export function unhideTextInstance(
} }
export function mountEventComponent( export function mountEventComponent(
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactEventComponentInstance<any, any, any>,
) { ) {
throw new Error('Not yet implemented.'); throw new Error('Not yet implemented.');
} }
export function updateEventComponent( export function updateEventComponent(
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactEventComponentInstance<any, any, any>,
) { ) {
throw new Error('Not yet implemented.'); throw new Error('Not yet implemented.');
} }
export function unmountEventComponent( export function unmountEventComponent(
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactEventComponentInstance<any, any, any>,
): void { ): void {
throw new Error('Not yet implemented.'); throw new Error('Not yet implemented.');
} }

View File

@ -106,7 +106,7 @@ if (__DEV__) {
export type Dependencies = { export type Dependencies = {
expirationTime: ExpirationTime, expirationTime: ExpirationTime,
firstContext: ContextDependency<mixed> | null, firstContext: ContextDependency<mixed> | null,
events: Array<ReactEventComponentInstance> | null, events: Array<ReactEventComponentInstance<any, any, any>> | null,
}; };
// A Fiber is work on a Component that needs to be done or was done. There can // A Fiber is work on a Component that needs to be done or was done. There can
@ -682,7 +682,7 @@ export function createFiberFromFragment(
} }
export function createFiberFromEventComponent( export function createFiberFromEventComponent(
eventComponent: ReactEventComponent, eventComponent: ReactEventComponent<any>,
pendingProps: any, pendingProps: any,
mode: TypeOfMode, mode: TypeOfMode,
expirationTime: ExpirationTime, expirationTime: ExpirationTime,

View File

@ -1013,7 +1013,11 @@ function completeWork(
popHostContext(workInProgress); popHostContext(workInProgress);
const rootContainerInstance = getRootHostContainer(); const rootContainerInstance = getRootHostContainer();
const responder = workInProgress.type.responder; const responder = workInProgress.type.responder;
let eventComponentInstance: ReactEventComponentInstance | null = let eventComponentInstance: ReactEventComponentInstance<
any,
any,
any,
> | null =
workInProgress.stateNode; workInProgress.stateNode;
if (eventComponentInstance === null) { if (eventComponentInstance === null) {
@ -1036,7 +1040,7 @@ function completeWork(
newProps, newProps,
responder, responder,
rootContainerInstance, rootContainerInstance,
responderState, responderState || {},
true, true,
); );
markUpdate(workInProgress); markUpdate(workInProgress);

View File

@ -8,8 +8,10 @@
*/ */
import type {Fiber, Dependencies} from './ReactFiber'; import type {Fiber, Dependencies} from './ReactFiber';
import type {ReactEventComponentInstance} from 'shared/ReactTypes'; import type {
import type {EventResponder} from 'react-reconciler/src/ReactFiberHostConfig'; ReactEventResponder,
ReactEventComponentInstance,
} from 'shared/ReactTypes';
import { import {
HostComponent, HostComponent,
@ -29,9 +31,9 @@ export function prepareToReadEventComponents(workInProgress: Fiber): void {
currentEventComponentInstanceIndex = 0; currentEventComponentInstanceIndex = 0;
} }
export function updateEventComponentInstance( export function updateEventComponentInstance<T, E, C>(
responder: EventResponder, responder: ReactEventResponder<T, E, C>,
props: null | Object, props: Object,
): void { ): void {
invariant( invariant(
responder.allowEventHooks, responder.allowEventHooks,
@ -64,7 +66,7 @@ export function updateEventComponentInstance(
props, props,
responder, responder,
null, null,
responderState, responderState || {},
false, false,
); );
events.push(eventComponentInstance); events.push(eventComponentInstance);
@ -77,14 +79,14 @@ export function updateEventComponentInstance(
} }
} }
export function createEventComponentInstance( export function createEventComponentInstance<T, E, C>(
currentFiber: Fiber, currentFiber: Fiber,
props: null | Object, props: Object,
responder: EventResponder, responder: ReactEventResponder<T, E, C>,
rootInstance: mixed, rootInstance: mixed,
state: null | Object, state: Object,
localPropagation: boolean, localPropagation: boolean,
): ReactEventComponentInstance { ): ReactEventComponentInstance<T, E, C> {
return { return {
currentFiber, currentFiber,
localPropagation, localPropagation,

View File

@ -7,13 +7,12 @@
* @flow * @flow
*/ */
import type {ReactContext} from 'shared/ReactTypes'; import type {ReactEventResponder, ReactContext} from 'shared/ReactTypes';
import type {SideEffectTag} from 'shared/ReactSideEffectTags'; import type {SideEffectTag} from 'shared/ReactSideEffectTags';
import type {Fiber} from './ReactFiber'; import type {Fiber} from './ReactFiber';
import type {ExpirationTime} from './ReactFiberExpirationTime'; import type {ExpirationTime} from './ReactFiberExpirationTime';
import type {HookEffectTag} from './ReactHookEffectTags'; import type {HookEffectTag} from './ReactHookEffectTags';
import type {SuspenseConfig} from './ReactFiberSuspenseConfig'; import type {SuspenseConfig} from './ReactFiberSuspenseConfig';
import type {EventResponder} from 'react-reconciler/src/ReactFiberHostConfig';
import ReactSharedInternals from 'shared/ReactSharedInternals'; import ReactSharedInternals from 'shared/ReactSharedInternals';
@ -83,7 +82,10 @@ export type Dispatcher = {
deps: Array<mixed> | void | null, deps: Array<mixed> | void | null,
): void, ): void,
useDebugValue<T>(value: T, formatterFn: ?(value: T) => mixed): void, useDebugValue<T>(value: T, formatterFn: ?(value: T) => mixed): void,
useEvent(responder: EventResponder, props: null | Object): void, useEvent<T, E, C>(
responder: ReactEventResponder<T, E, C>,
props: Object,
): void,
}; };
type Update<S, A> = { type Update<S, A> = {
@ -1397,7 +1399,7 @@ if (__DEV__) {
mountHookTypesDev(); mountHookTypesDev();
return mountDebugValue(value, formatterFn); return mountDebugValue(value, formatterFn);
}, },
useEvent(responder, props) { useEvent<T, E, C>(responder: ReactEventResponder<T, E, C>, props) {
currentHookNameInDev = 'useEvent'; currentHookNameInDev = 'useEvent';
mountHookTypesDev(); mountHookTypesDev();
updateEventComponentInstance(responder, props); updateEventComponentInstance(responder, props);
@ -1499,7 +1501,7 @@ if (__DEV__) {
updateHookTypesDev(); updateHookTypesDev();
return mountDebugValue(value, formatterFn); return mountDebugValue(value, formatterFn);
}, },
useEvent(responder, props) { useEvent<T, E, C>(responder: ReactEventResponder<T, E, C>, props) {
currentHookNameInDev = 'useEvent'; currentHookNameInDev = 'useEvent';
updateHookTypesDev(); updateHookTypesDev();
updateEventComponentInstance(responder, props); updateEventComponentInstance(responder, props);
@ -1601,7 +1603,7 @@ if (__DEV__) {
updateHookTypesDev(); updateHookTypesDev();
return updateDebugValue(value, formatterFn); return updateDebugValue(value, formatterFn);
}, },
useEvent(responder, props) { useEvent<T, E, C>(responder: ReactEventResponder<T, E, C>, props) {
currentHookNameInDev = 'useEvent'; currentHookNameInDev = 'useEvent';
updateHookTypesDev(); updateHookTypesDev();
updateEventComponentInstance(responder, props); updateEventComponentInstance(responder, props);
@ -1714,7 +1716,7 @@ if (__DEV__) {
mountHookTypesDev(); mountHookTypesDev();
return mountDebugValue(value, formatterFn); return mountDebugValue(value, formatterFn);
}, },
useEvent(responder, props) { useEvent<T, E, C>(responder: ReactEventResponder<T, E, C>, props) {
currentHookNameInDev = 'useEvent'; currentHookNameInDev = 'useEvent';
warnInvalidHookAccess(); warnInvalidHookAccess();
mountHookTypesDev(); mountHookTypesDev();
@ -1828,7 +1830,7 @@ if (__DEV__) {
updateHookTypesDev(); updateHookTypesDev();
return updateDebugValue(value, formatterFn); return updateDebugValue(value, formatterFn);
}, },
useEvent(responder, props) { useEvent<T, E, C>(responder: ReactEventResponder<T, E, C>, props) {
currentHookNameInDev = 'useEvent'; currentHookNameInDev = 'useEvent';
warnInvalidHookAccess(); warnInvalidHookAccess();
updateHookTypesDev(); updateHookTypesDev();

View File

@ -329,19 +329,19 @@ export function unhideTextInstance(
} }
export function mountEventComponent( export function mountEventComponent(
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactEventComponentInstance<any, any, any>,
): void { ): void {
// noop // noop
} }
export function updateEventComponent( export function updateEventComponent(
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactEventComponentInstance<any, any, any>,
): void { ): void {
// noop // noop
} }
export function unmountEventComponent( export function unmountEventComponent(
eventComponentInstance: ReactEventComponentInstance, eventComponentInstance: ReactEventComponentInstance<any, any, any>,
): void { ): void {
// noop // noop
} }

View File

@ -7,8 +7,7 @@
* @flow * @flow
*/ */
import type {ReactContext} from 'shared/ReactTypes'; import type {ReactEventResponder, ReactContext} from 'shared/ReactTypes';
import type {EventResponder} from 'react-reconciler/src/ReactFiberHostConfig';
import invariant from 'shared/invariant'; import invariant from 'shared/invariant';
import warning from 'shared/warning'; import warning from 'shared/warning';
@ -137,7 +136,12 @@ export function useDebugValue(value: any, formatterFn: ?(value: any) => any) {
} }
} }
export function useEvent(responder: EventResponder, props: null | Object) { export const emptyObject = {};
export function useEvent<T, E, C>(
responder: ReactEventResponder<T, E, C>,
props: null | Object,
) {
const dispatcher = resolveDispatcher(); const dispatcher = resolveDispatcher();
return dispatcher.useEvent(responder, props); return dispatcher.useEvent(responder, props || emptyObject);
} }

View File

@ -7,7 +7,11 @@
* @flow * @flow
*/ */
import type {EventPriority} from 'shared/ReactTypes'; import type {
ReactEventResponder,
ReactEventComponentInstance,
EventPriority,
} from 'shared/ReactTypes';
type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | Touch; type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | Touch;
@ -33,47 +37,17 @@ export type ReactDOMResponderEvent = {
type: string, type: string,
}; };
export type ReactDOMEventResponder = { export type ReactDOMEventResponder = ReactEventResponder<
displayName: string, ReactDOMEventResponderEventType,
targetEventTypes?: Array<ReactDOMEventResponderEventType>, ReactDOMResponderEvent,
rootEventTypes?: Array<ReactDOMEventResponderEventType>, ReactDOMResponderContext,
createInitialState?: (props: null | Object) => Object, >;
allowMultipleHostChildren: boolean,
allowEventHooks: boolean, export type ReactDOMEventComponentInstance = ReactEventComponentInstance<
onEvent?: ( ReactDOMEventResponderEventType,
event: ReactDOMResponderEvent, ReactDOMResponderEvent,
context: ReactDOMResponderContext, ReactDOMResponderContext,
props: null | Object, >;
state: null | Object,
) => void,
onEventCapture?: (
event: ReactDOMResponderEvent,
context: ReactDOMResponderContext,
props: null | Object,
state: null | Object,
) => void,
onRootEvent?: (
event: ReactDOMResponderEvent,
context: ReactDOMResponderContext,
props: null | Object,
state: null | Object,
) => void,
onMount?: (
context: ReactDOMResponderContext,
props: null | Object,
state: null | Object,
) => void,
onUnmount?: (
context: ReactDOMResponderContext,
props: null | Object,
state: null | Object,
) => void,
onOwnershipChange?: (
context: ReactDOMResponderContext,
props: null | Object,
state: null | Object,
) => void,
};
export type ReactDOMResponderContext = { export type ReactDOMResponderContext = {
dispatchEvent: ( dispatchEvent: (

View File

@ -7,9 +7,6 @@
* @flow * @flow
*/ */
// NOTE: this line is changed in the RN build, see: copyRNShims in packaging.js
import type {EventResponder} from 'react-reconciler/src/ReactFiberHostConfig';
export type ReactNode = export type ReactNode =
| React$Element<any> | React$Element<any>
| ReactPortal | ReactPortal
@ -17,7 +14,7 @@ export type ReactNode =
| ReactFragment | ReactFragment
| ReactProvider<any> | ReactProvider<any>
| ReactConsumer<any> | ReactConsumer<any>
| ReactEventComponent | ReactEventComponent<any, any, any>
| ReactEventTarget; | ReactEventTarget;
export type ReactEmpty = null | void | boolean; export type ReactEmpty = null | void | boolean;
@ -84,20 +81,34 @@ export type RefObject = {|
current: any, current: any,
|}; |};
export type ReactEventComponentInstance = {| export type ReactEventComponentInstance<T, E, C> = {|
currentFiber: mixed, currentFiber: mixed,
localPropagation: boolean, localPropagation: boolean,
props: null | Object, props: Object,
responder: EventResponder, responder: ReactEventResponder<T, E, C>,
rootEventTypes: null | Set<string>, rootEventTypes: null | Set<string>,
rootInstance: null | mixed, rootInstance: null | mixed,
state: null | Object, state: Object,
|}; |};
export type ReactEventComponent = {| export type ReactEventResponder<T, E, C> = {
displayName: string,
targetEventTypes?: Array<T>,
rootEventTypes?: Array<T>,
createInitialState?: (props: Object) => Object,
allowMultipleHostChildren: boolean,
allowEventHooks: boolean,
onEvent?: (event: E, context: C, props: Object, state: Object) => void,
onEventCapture?: (event: E, context: C, props: Object, state: Object) => void,
onRootEvent?: (event: E, context: C, props: Object, state: Object) => void,
onMount?: (context: C, props: Object, state: Object) => void,
onUnmount?: (context: C, props: Object, state: Object) => void,
onOwnershipChange?: (context: C, props: Object, state: Object) => void,
};
export type ReactEventComponent<T, E, C> = {|
$$typeof: Symbol | number, $$typeof: Symbol | number,
props: null | Object, responder: ReactEventResponder<T, E, C>,
responder: EventResponder,
|}; |};
export type ReactEventTarget = {| export type ReactEventTarget = {|

View File

@ -6,8 +6,7 @@
* @flow * @flow
*/ */
import type {EventResponder} from 'react-reconciler/src/ReactFiberHostConfig'; import type {ReactEventResponder, ReactEventComponent} from 'shared/ReactTypes';
import type {ReactEventComponent} from 'shared/ReactTypes';
import {REACT_EVENT_COMPONENT_TYPE} from 'shared/ReactSymbols'; import {REACT_EVENT_COMPONENT_TYPE} from 'shared/ReactSymbols';
let hasBadMapPolyfill; let hasBadMapPolyfill;
@ -29,9 +28,9 @@ if (__DEV__) {
} }
} }
export default function createEventComponent( export default function createEventComponent<T, E, C>(
responder: EventResponder, responder: ReactEventResponder<T, E, C>,
): ReactEventComponent { ): ReactEventComponent<T, E, C> {
// We use responder as a Map key later on. When we have a bad // We use responder as a Map key later on. When we have a bad
// polyfill, then we can't use it as a key as the polyfill tries // polyfill, then we can't use it as a key as the polyfill tries
// to add a property to the object. // to add a property to the object.
@ -40,7 +39,6 @@ export default function createEventComponent(
} }
const eventComponent = { const eventComponent = {
$$typeof: REACT_EVENT_COMPONENT_TYPE, $$typeof: REACT_EVENT_COMPONENT_TYPE,
props: null,
responder: responder, responder: responder,
}; };
if (__DEV__) { if (__DEV__) {

View File

@ -27,7 +27,7 @@ import {
REACT_EVENT_TARGET_TOUCH_HIT, REACT_EVENT_TARGET_TOUCH_HIT,
} from 'shared/ReactSymbols'; } from 'shared/ReactSymbols';
import {refineResolvedLazyComponent} from 'shared/ReactLazyComponent'; import {refineResolvedLazyComponent} from 'shared/ReactLazyComponent';
import type {ReactEventComponent, ReactEventTarget} from 'shared/ReactTypes'; import type {ReactEventTarget} from 'shared/ReactTypes';
import {enableEventAPI} from './ReactFeatureFlags'; import {enableEventAPI} from './ReactFeatureFlags';
@ -97,8 +97,7 @@ function getComponentName(type: mixed): string | null {
} }
case REACT_EVENT_COMPONENT_TYPE: { case REACT_EVENT_COMPONENT_TYPE: {
if (enableEventAPI) { if (enableEventAPI) {
const eventComponent = ((type: any): ReactEventComponent); return (type: any).responder.displayName;
return eventComponent.responder.displayName;
} }
break; break;
} }

View File

@ -1,12 +1,6 @@
'use strict'; 'use strict';
const { const {existsSync, readdirSync, unlinkSync} = require('fs');
existsSync,
readdirSync,
unlinkSync,
readFileSync,
writeFileSync,
} = require('fs');
const Bundles = require('./bundles'); const Bundles = require('./bundles');
const { const {
asyncCopyTo, asyncCopyTo,
@ -103,12 +97,6 @@ async function copyRNShims() {
'build/react-native/shims/ReactNativeTypes.js' 'build/react-native/shims/ReactNativeTypes.js'
), ),
]); ]);
// Modify the EventResponder type in ReactTypes
const reactTypesSource = readFileSync(reactTypesBuildTarget, 'utf8');
const original = `import type {EventResponder} from 'react-reconciler/src/ReactFiberHostConfig';`;
const changeTo = `import type {ReactNativeEventResponder as EventResponder} from './ReactNativeTypes';`;
const modifiedSource = reactTypesSource.replace(original, changeTo);
writeFileSync(reactTypesBuildTarget, modifiedSource);
} }
async function copyAllShims() { async function copyAllShims() {