Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Do not bind topLevelType to dispatch" #13674

Merged
merged 4 commits into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | TouchEvent;
export type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | Touch;

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) {
return fn(a);
let _interactiveUpdatesImpl = function(fn, a, b) {
return fn(a, b);
};
let _flushInteractiveUpdatesImpl = function() {};

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

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

export function flushInteractiveUpdates() {
Expand Down
38 changes: 24 additions & 14 deletions packages/react-dom/src/events/ReactDOMEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ 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 @@ -49,6 +48,7 @@ function findRootContainerNode(inst) {

// Used to store ancestor hierarchy in top level callback
function getTopLevelCallbackBookKeeping(
topLevelType,
nativeEvent,
targetInst,
): {
Expand All @@ -57,9 +57,6 @@ function getTopLevelCallbackBookKeeping(
targetInst: Fiber | null,
ancestors: Array<Fiber>,
} {
// This is safe because DOMTopLevelTypes are always native event type strings
const topLevelType = unsafeCastStringToDOMTopLevelType(nativeEvent.type);

if (callbackBookkeepingPool.length) {
const instance = callbackBookkeepingPool.pop();
instance.topLevelType = topLevelType;
Expand Down Expand Up @@ -144,13 +141,16 @@ export function trapBubbledEvent(
if (!element) {
return null;
}

// Check if interactive and wrap in interactiveUpdates
const dispatch = isInteractiveTopLevelEventType(topLevelType)
? dispatchInteractiveEvent
: dispatchEvent;

addEventBubbleListener(element, getRawEventName(topLevelType), dispatch);
addEventBubbleListener(
element,
getRawEventName(topLevelType),
// Check if interactive and wrap in interactiveUpdates
dispatch.bind(null, topLevelType),
);
}

/**
Expand All @@ -169,20 +169,26 @@ export function trapCapturedEvent(
if (!element) {
return null;
}

// Check if interactive and wrap in interactiveUpdates
const dispatch = isInteractiveTopLevelEventType(topLevelType)
? dispatchInteractiveEvent
: dispatchEvent;

addEventCaptureListener(element, getRawEventName(topLevelType), dispatch);
addEventCaptureListener(
element,
getRawEventName(topLevelType),
// Check if interactive and wrap in interactiveUpdates
dispatch.bind(null, topLevelType),
);
}

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

export function dispatchEvent(nativeEvent: AnyNativeEvent) {
export function dispatchEvent(
topLevelType: DOMTopLevelEventType,
nativeEvent: AnyNativeEvent,
) {
if (!_enabled) {
return;
}
Expand All @@ -201,7 +207,11 @@ export function dispatchEvent(nativeEvent: AnyNativeEvent) {
targetInst = null;
}

const bookKeeping = getTopLevelCallbackBookKeeping(nativeEvent, targetInst);
const bookKeeping = getTopLevelCallbackBookKeeping(
topLevelType,
nativeEvent,
targetInst,
);

try {
// Event queue being processed in the same cycle allows
Expand Down
6 changes: 2 additions & 4 deletions packages/react-dom/src/test-utils/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ const [
runEventsInBatch,
] = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events;

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

let hasWarnedAboutDeprecatedMockComponent = false;

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

/**
Expand Down