Skip to content

Commit b319235

Browse files
committed
Do not bind topLevelType to dispatch
A previous change made it such that all top level event types correspond to their associated native event string values. This commit eliminates the .bind attached to dispatch and fixes a related flow type.
1 parent f6fb03e commit b319235

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
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 | Touch;
19+
export type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | TouchEvent;
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, b) {
24-
return fn(a, b);
23+
let _interactiveUpdatesImpl = function(fn, a) {
24+
return fn(a);
2525
};
2626
let _flushInteractiveUpdatesImpl = function() {};
2727

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

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

5959
export function flushInteractiveUpdates() {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ 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';
2425

2526
const {isInteractiveTopLevelEventType} = SimpleEventPlugin;
2627

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

4950
// Used to store ancestor hierarchy in top level callback
5051
function getTopLevelCallbackBookKeeping(
51-
topLevelType,
5252
nativeEvent,
5353
targetInst,
5454
): {
@@ -57,6 +57,8 @@ function getTopLevelCallbackBookKeeping(
5757
targetInst: Fiber | null,
5858
ancestors: Array<Fiber>,
5959
} {
60+
const topLevelType = unsafeCastStringToDOMTopLevelType(nativeEvent.type);
61+
6062
if (callbackBookkeepingPool.length) {
6163
const instance = callbackBookkeepingPool.pop();
6264
instance.topLevelType = topLevelType;
@@ -149,7 +151,7 @@ export function trapBubbledEvent(
149151
element,
150152
getRawEventName(topLevelType),
151153
// Check if interactive and wrap in interactiveUpdates
152-
dispatch.bind(null, topLevelType),
154+
dispatch,
153155
);
154156
}
155157

@@ -177,16 +179,15 @@ export function trapCapturedEvent(
177179
element,
178180
getRawEventName(topLevelType),
179181
// Check if interactive and wrap in interactiveUpdates
180-
dispatch.bind(null, topLevelType),
182+
dispatch,
181183
);
182184
}
183185

184-
function dispatchInteractiveEvent(topLevelType, nativeEvent) {
185-
interactiveUpdates(dispatchEvent, topLevelType, nativeEvent);
186+
function dispatchInteractiveEvent(nativeEvent) {
187+
interactiveUpdates(dispatchEvent, nativeEvent);
186188
}
187189

188190
export function dispatchEvent(
189-
topLevelType: DOMTopLevelEventType,
190191
nativeEvent: AnyNativeEvent,
191192
) {
192193
if (!_enabled) {
@@ -208,7 +209,6 @@ export function dispatchEvent(
208209
}
209210

210211
const bookKeeping = getTopLevelCallbackBookKeeping(
211-
topLevelType,
212212
nativeEvent,
213213
targetInst,
214214
);

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

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

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

4749
let hasWarnedAboutDeprecatedMockComponent = false;
4850

@@ -59,7 +61,7 @@ let hasWarnedAboutDeprecatedMockComponent = false;
5961
*/
6062
function simulateNativeEventOnNode(topLevelType, node, fakeNativeEvent) {
6163
fakeNativeEvent.target = node;
62-
dispatchEvent(topLevelType, fakeNativeEvent);
64+
dispatchEvent(fakeNativeEvent);
6365
}
6466

6567
/**

0 commit comments

Comments
 (0)