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