Skip to content

Commit a210b5b

Browse files
authored
Revert "Do not bind topLevelType to dispatch" (#13674)
* Revert "Do not bind topLevelType to dispatch (#13618)" This reverts commit 0c9c591.
1 parent 2f54a04 commit a210b5b

File tree

4 files changed

+31
-23
lines changed

4 files changed

+31
-23
lines changed

packages/events/PluginModuleType.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {TopLevelType} from './TopLevelEventTypes';
1616

1717
export type EventTypes = {[key: string]: DispatchConfig};
1818

19-
export type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | TouchEvent;
19+
export type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | Touch;
2020

2121
export type PluginName = string;
2222

packages/events/ReactGenericBatching.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import {
2020
let _batchedUpdatesImpl = function(fn, bookkeeping) {
2121
return fn(bookkeeping);
2222
};
23-
let _interactiveUpdatesImpl = function(fn, a) {
24-
return fn(a);
23+
let _interactiveUpdatesImpl = function(fn, a, b) {
24+
return fn(a, b);
2525
};
2626
let _flushInteractiveUpdatesImpl = function() {};
2727

@@ -52,8 +52,8 @@ export function batchedUpdates(fn, bookkeeping) {
5252
}
5353
}
5454

55-
export function interactiveUpdates(fn, a) {
56-
return _interactiveUpdatesImpl(fn, a);
55+
export function interactiveUpdates(fn, a, b) {
56+
return _interactiveUpdatesImpl(fn, a, b);
5757
}
5858

5959
export function flushInteractiveUpdates() {

packages/react-dom/src/events/ReactDOMEventListener.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import getEventTarget from './getEventTarget';
2121
import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree';
2222
import SimpleEventPlugin from './SimpleEventPlugin';
2323
import {getRawEventName} from './DOMTopLevelEventTypes';
24-
import {unsafeCastStringToDOMTopLevelType} from 'events/TopLevelEventTypes';
2524

2625
const {isInteractiveTopLevelEventType} = SimpleEventPlugin;
2726

@@ -49,6 +48,7 @@ function findRootContainerNode(inst) {
4948

5049
// Used to store ancestor hierarchy in top level callback
5150
function getTopLevelCallbackBookKeeping(
51+
topLevelType,
5252
nativeEvent,
5353
targetInst,
5454
): {
@@ -57,9 +57,6 @@ 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-
6360
if (callbackBookkeepingPool.length) {
6461
const instance = callbackBookkeepingPool.pop();
6562
instance.topLevelType = topLevelType;
@@ -144,13 +141,16 @@ export function trapBubbledEvent(
144141
if (!element) {
145142
return null;
146143
}
147-
148-
// Check if interactive and wrap in interactiveUpdates
149144
const dispatch = isInteractiveTopLevelEventType(topLevelType)
150145
? dispatchInteractiveEvent
151146
: dispatchEvent;
152147

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+
);
154154
}
155155

156156
/**
@@ -169,20 +169,26 @@ export function trapCapturedEvent(
169169
if (!element) {
170170
return null;
171171
}
172-
173-
// Check if interactive and wrap in interactiveUpdates
174172
const dispatch = isInteractiveTopLevelEventType(topLevelType)
175173
? dispatchInteractiveEvent
176174
: dispatchEvent;
177175

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+
);
179182
}
180183

181-
function dispatchInteractiveEvent(nativeEvent) {
182-
interactiveUpdates(dispatchEvent, nativeEvent);
184+
function dispatchInteractiveEvent(topLevelType, nativeEvent) {
185+
interactiveUpdates(dispatchEvent, topLevelType, nativeEvent);
183186
}
184187

185-
export function dispatchEvent(nativeEvent: AnyNativeEvent) {
188+
export function dispatchEvent(
189+
topLevelType: DOMTopLevelEventType,
190+
nativeEvent: AnyNativeEvent,
191+
) {
186192
if (!_enabled) {
187193
return;
188194
}
@@ -201,7 +207,11 @@ export function dispatchEvent(nativeEvent: AnyNativeEvent) {
201207
targetInst = null;
202208
}
203209

204-
const bookKeeping = getTopLevelCallbackBookKeeping(nativeEvent, targetInst);
210+
const bookKeeping = getTopLevelCallbackBookKeeping(
211+
topLevelType,
212+
nativeEvent,
213+
targetInst,
214+
);
205215

206216
try {
207217
// Event queue being processed in the same cycle allows

packages/react-dom/src/test-utils/ReactTestUtils.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ const [
4242
runEventsInBatch,
4343
] = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events;
4444

45-
function Event(type) {
46-
this.type = type;
47-
}
45+
function Event(suffix) {}
4846

4947
let hasWarnedAboutDeprecatedMockComponent = false;
5048

@@ -61,7 +59,7 @@ let hasWarnedAboutDeprecatedMockComponent = false;
6159
*/
6260
function simulateNativeEventOnNode(topLevelType, node, fakeNativeEvent) {
6361
fakeNativeEvent.target = node;
64-
dispatchEvent(fakeNativeEvent);
62+
dispatchEvent(topLevelType, fakeNativeEvent);
6563
}
6664

6765
/**

0 commit comments

Comments
 (0)