Skip to content

Commit

Permalink
Do not bind topLevelType to dispatch
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nhunzaker committed Sep 11, 2018
1 parent f6fb03e commit a88ce01
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/events/PluginModuleType.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {TopLevelType} from './TopLevelEventTypes';

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

export type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | Touch;
export type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | TouchEvent;

export type PluginName = string;

Expand Down
8 changes: 4 additions & 4 deletions packages/events/ReactGenericBatching.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {
let _batchedUpdatesImpl = function(fn, bookkeeping) {
return fn(bookkeeping);
};
let _interactiveUpdatesImpl = function(fn, a, b) {
return fn(a, b);
let _interactiveUpdatesImpl = function(fn, a) {
return fn(a);
};
let _flushInteractiveUpdatesImpl = function() {};

Expand Down Expand Up @@ -52,8 +52,8 @@ export function batchedUpdates(fn, bookkeeping) {
}
}

export function interactiveUpdates(fn, a, b) {
return _interactiveUpdatesImpl(fn, a, b);
export function interactiveUpdates(fn, a) {
return _interactiveUpdatesImpl(fn, a);
}

export function flushInteractiveUpdates() {
Expand Down
14 changes: 7 additions & 7 deletions packages/react-dom/src/events/ReactDOMEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import getEventTarget from './getEventTarget';
import {getClosestInstanceFromNode} from '../client/ReactDOMComponentTree';
import SimpleEventPlugin from './SimpleEventPlugin';
import {getRawEventName} from './DOMTopLevelEventTypes';
import {unsafeCastStringToDOMTopLevelType} from 'events/TopLevelEventTypes';

const {isInteractiveTopLevelEventType} = SimpleEventPlugin;

Expand Down Expand Up @@ -48,7 +49,6 @@ function findRootContainerNode(inst) {

// Used to store ancestor hierarchy in top level callback
function getTopLevelCallbackBookKeeping(
topLevelType,
nativeEvent,
targetInst,
): {
Expand All @@ -57,6 +57,8 @@ function getTopLevelCallbackBookKeeping(
targetInst: Fiber | null,
ancestors: Array<Fiber>,
} {
const topLevelType = unsafeCastStringToDOMTopLevelType(nativeEvent.type);

if (callbackBookkeepingPool.length) {
const instance = callbackBookkeepingPool.pop();
instance.topLevelType = topLevelType;
Expand Down Expand Up @@ -149,7 +151,7 @@ export function trapBubbledEvent(
element,
getRawEventName(topLevelType),
// Check if interactive and wrap in interactiveUpdates
dispatch.bind(null, topLevelType),
dispatch,
);
}

Expand Down Expand Up @@ -177,16 +179,15 @@ export function trapCapturedEvent(
element,
getRawEventName(topLevelType),
// Check if interactive and wrap in interactiveUpdates
dispatch.bind(null, topLevelType),
dispatch,
);
}

function dispatchInteractiveEvent(topLevelType, nativeEvent) {
interactiveUpdates(dispatchEvent, topLevelType, nativeEvent);
function dispatchInteractiveEvent(nativeEvent) {
interactiveUpdates(dispatchEvent, nativeEvent);
}

export function dispatchEvent(
topLevelType: DOMTopLevelEventType,
nativeEvent: AnyNativeEvent,
) {
if (!_enabled) {
Expand All @@ -208,7 +209,6 @@ export function dispatchEvent(
}

const bookKeeping = getTopLevelCallbackBookKeeping(
topLevelType,
nativeEvent,
targetInst,
);
Expand Down
6 changes: 4 additions & 2 deletions packages/react-dom/src/test-utils/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const [
runEventsInBatch,
] = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events;

function Event(suffix) {}
function Event(type) {
this.type = type;
}

let hasWarnedAboutDeprecatedMockComponent = false;

Expand All @@ -59,7 +61,7 @@ let hasWarnedAboutDeprecatedMockComponent = false;
*/
function simulateNativeEventOnNode(topLevelType, node, fakeNativeEvent) {
fakeNativeEvent.target = node;
dispatchEvent(topLevelType, fakeNativeEvent);
ReactDOMEventListener.dispatchEvent(fakeNativeEvent);
}

/**
Expand Down

0 comments on commit a88ce01

Please sign in to comment.