@@ -21,6 +21,7 @@ import getEventTarget from './getEventTarget';
2121import { getClosestInstanceFromNode } from '../client/ReactDOMComponentTree' ;
2222import SimpleEventPlugin from './SimpleEventPlugin' ;
2323import { getRawEventName } from './DOMTopLevelEventTypes' ;
24+ import { unsafeCastStringToDOMTopLevelType } from 'events/TopLevelEventTypes' ;
2425
2526const { isInteractiveTopLevelEventType} = SimpleEventPlugin ;
2627
@@ -48,7 +49,6 @@ function findRootContainerNode(inst) {
4849
4950// Used to store ancestor hierarchy in top level callback
5051function getTopLevelCallbackBookKeeping (
51- topLevelType ,
5252 nativeEvent ,
5353 targetInst ,
5454) : {
@@ -57,6 +57,9 @@ function getTopLevelCallbackBookKeeping(
5757 targetInst : Fiber | null ,
5858 ancestors : Array < Fiber > ,
5959} {
60+ // This is safe because DOMTopLevelTypes are always native event type strings
61+ const topLevelType = unsafeCastStringToDOMTopLevelType ( nativeEvent . type ) ;
62+
6063 if ( callbackBookkeepingPool . length ) {
6164 const instance = callbackBookkeepingPool . pop ( ) ;
6265 instance . topLevelType = topLevelType ;
@@ -141,16 +144,13 @@ export function trapBubbledEvent(
141144 if ( ! element ) {
142145 return null ;
143146 }
147+
148+ // Check if interactive and wrap in interactiveUpdates
144149 const dispatch = isInteractiveTopLevelEventType ( topLevelType )
145150 ? dispatchInteractiveEvent
146151 : dispatchEvent ;
147152
148- addEventBubbleListener (
149- element ,
150- getRawEventName ( topLevelType ) ,
151- // Check if interactive and wrap in interactiveUpdates
152- dispatch . bind ( null , topLevelType ) ,
153- ) ;
153+ addEventBubbleListener ( element , getRawEventName ( topLevelType ) , dispatch ) ;
154154}
155155
156156/**
@@ -169,26 +169,20 @@ export function trapCapturedEvent(
169169 if ( ! element ) {
170170 return null ;
171171 }
172+
173+ // Check if interactive and wrap in interactiveUpdates
172174 const dispatch = isInteractiveTopLevelEventType ( topLevelType )
173175 ? dispatchInteractiveEvent
174176 : dispatchEvent ;
175177
176- addEventCaptureListener (
177- element ,
178- getRawEventName ( topLevelType ) ,
179- // Check if interactive and wrap in interactiveUpdates
180- dispatch . bind ( null , topLevelType ) ,
181- ) ;
178+ addEventCaptureListener ( element , getRawEventName ( topLevelType ) , dispatch ) ;
182179}
183180
184- function dispatchInteractiveEvent ( topLevelType , nativeEvent ) {
185- interactiveUpdates ( dispatchEvent , topLevelType , nativeEvent ) ;
181+ function dispatchInteractiveEvent ( nativeEvent ) {
182+ interactiveUpdates ( dispatchEvent , nativeEvent ) ;
186183}
187184
188- export function dispatchEvent (
189- topLevelType : DOMTopLevelEventType ,
190- nativeEvent : AnyNativeEvent ,
191- ) {
185+ export function dispatchEvent ( nativeEvent : AnyNativeEvent ) {
192186 if ( ! _enabled ) {
193187 return ;
194188 }
@@ -207,11 +201,7 @@ export function dispatchEvent(
207201 targetInst = null ;
208202 }
209203
210- const bookKeeping = getTopLevelCallbackBookKeeping (
211- topLevelType ,
212- nativeEvent ,
213- targetInst ,
214- ) ;
204+ const bookKeeping = getTopLevelCallbackBookKeeping ( nativeEvent , targetInst ) ;
215205
216206 try {
217207 // Event queue being processed in the same cycle allows
0 commit comments