@@ -21,6 +21,7 @@ import getEventTarget from './getEventTarget';
21
21
import { getClosestInstanceFromNode } from '../client/ReactDOMComponentTree' ;
22
22
import SimpleEventPlugin from './SimpleEventPlugin' ;
23
23
import { getRawEventName } from './DOMTopLevelEventTypes' ;
24
+ import { unsafeCastStringToDOMTopLevelType } from 'events/TopLevelEventTypes' ;
24
25
25
26
const { isInteractiveTopLevelEventType} = SimpleEventPlugin ;
26
27
@@ -48,7 +49,6 @@ function findRootContainerNode(inst) {
48
49
49
50
// Used to store ancestor hierarchy in top level callback
50
51
function getTopLevelCallbackBookKeeping (
51
- topLevelType ,
52
52
nativeEvent ,
53
53
targetInst ,
54
54
) : {
@@ -57,6 +57,9 @@ function getTopLevelCallbackBookKeeping(
57
57
targetInst : Fiber | null ,
58
58
ancestors : Array < Fiber > ,
59
59
} {
60
+ // This is safe because DOMTopLevelTypes are always native event type strings
61
+ const topLevelType = unsafeCastStringToDOMTopLevelType ( nativeEvent . type ) ;
62
+
60
63
if ( callbackBookkeepingPool . length ) {
61
64
const instance = callbackBookkeepingPool . pop ( ) ;
62
65
instance . topLevelType = topLevelType ;
@@ -141,16 +144,13 @@ export function trapBubbledEvent(
141
144
if ( ! element ) {
142
145
return null ;
143
146
}
147
+
148
+ // Check if interactive and wrap in interactiveUpdates
144
149
const dispatch = isInteractiveTopLevelEventType ( topLevelType )
145
150
? dispatchInteractiveEvent
146
151
: dispatchEvent ;
147
152
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 ) ;
154
154
}
155
155
156
156
/**
@@ -169,26 +169,20 @@ export function trapCapturedEvent(
169
169
if ( ! element ) {
170
170
return null ;
171
171
}
172
+
173
+ // Check if interactive and wrap in interactiveUpdates
172
174
const dispatch = isInteractiveTopLevelEventType ( topLevelType )
173
175
? dispatchInteractiveEvent
174
176
: dispatchEvent ;
175
177
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 ) ;
182
179
}
183
180
184
- function dispatchInteractiveEvent ( topLevelType , nativeEvent ) {
185
- interactiveUpdates ( dispatchEvent , topLevelType , nativeEvent ) ;
181
+ function dispatchInteractiveEvent ( nativeEvent ) {
182
+ interactiveUpdates ( dispatchEvent , nativeEvent ) ;
186
183
}
187
184
188
- export function dispatchEvent (
189
- topLevelType : DOMTopLevelEventType ,
190
- nativeEvent : AnyNativeEvent ,
191
- ) {
185
+ export function dispatchEvent ( nativeEvent : AnyNativeEvent ) {
192
186
if ( ! _enabled ) {
193
187
return ;
194
188
}
@@ -207,11 +201,7 @@ export function dispatchEvent(
207
201
targetInst = null ;
208
202
}
209
203
210
- const bookKeeping = getTopLevelCallbackBookKeeping (
211
- topLevelType ,
212
- nativeEvent ,
213
- targetInst ,
214
- ) ;
204
+ const bookKeeping = getTopLevelCallbackBookKeeping ( nativeEvent , targetInst ) ;
215
205
216
206
try {
217
207
// Event queue being processed in the same cycle allows
0 commit comments