Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed Mar 19, 2020
1 parent 66f7c8d commit ea3ae21
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
8 changes: 7 additions & 1 deletion packages/react-dom/src/events/DOMModernPluginEventSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import {
TOP_RATE_CHANGE,
TOP_PROGRESS,
TOP_PLAYING,
TOP_CLICK,
} from './DOMTopLevelEventTypes';
import {
getClosestInstanceFromNode,
Expand Down Expand Up @@ -229,7 +230,7 @@ function willDeferLaterForLegacyFBSupport(
topLevelType: DOMTopLevelEventType,
targetContainer: EventTarget,
): boolean {
if ((topLevelType: any) !== 'click') {
if (topLevelType !== TOP_CLICK) {
return false;
}
// We defer all click events with legacy FB support mode on.
Expand Down Expand Up @@ -290,7 +291,12 @@ export function dispatchEventForPluginEventSystem(
// time event listener so we can defer the event.
if (
enableLegacyFBSupport &&
// We do not want to defer if the event system has already been
// set to LEGACY_FB_SUPPORT. LEGACY_FB_SUPPORT only gets set when
// we call willDeferLaterForLegacyFBSupport, thus not bailing out
// will result in endless cycles like an infinite loop.
(eventSystemFlags & LEGACY_FB_SUPPORT) === 0 &&
// We also don't want to defer during event replaying.
(eventSystemFlags & IS_REPLAYED) === 0 &&
willDeferLaterForLegacyFBSupport(topLevelType, targetContainer)
) {
Expand Down
20 changes: 10 additions & 10 deletions packages/react-dom/src/events/ReactDOMEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function addTrappedEventListener(
targetContainer: EventTarget,
topLevelType: DOMTopLevelEventType,
capture: boolean,
legacyFBSupport?: boolean,
isDeferredListenerForLegacyFBSupport?: boolean,
passive?: boolean,
priority?: EventPriority,
): any => void {
Expand Down Expand Up @@ -161,7 +161,7 @@ export function addTrappedEventListener(
passive = false;
}
const eventSystemFlags =
enableLegacyFBSupport && legacyFBSupport
enableLegacyFBSupport && isDeferredListenerForLegacyFBSupport
? PLUGIN_EVENT_SYSTEM | LEGACY_FB_SUPPORT
: PLUGIN_EVENT_SYSTEM;

Expand All @@ -182,8 +182,8 @@ export function addTrappedEventListener(
targetContainer = document;
}

const targetContainerToUse =
enableLegacyFBSupport && legacyFBSupport
targetContainer =
enableLegacyFBSupport && isDeferredListenerForLegacyFBSupport
? (targetContainer: any).ownerDocument
: targetContainer;

Expand All @@ -201,14 +201,14 @@ export function addTrappedEventListener(
// browsers do not support this today, and given this is
// to support legacy code patterns, it's likely they'll
// need support for such browsers.
if (enableLegacyFBSupport && legacyFBSupport) {
if (enableLegacyFBSupport && isDeferredListenerForLegacyFBSupport) {
const originalListener = listener;
listener = function(...p) {
try {
return originalListener.apply(this, p);
} finally {
removeEventListener(
targetContainerToUse,
targetContainer,
rawEventName,
unsubscribeListener,
capture,
Expand All @@ -220,14 +220,14 @@ export function addTrappedEventListener(
if (enableUseEventAPI && passive !== undefined) {
// This is only used with passive is either true or false.
unsubscribeListener = addEventCaptureListenerWithPassiveFlag(
targetContainerToUse,
targetContainer,
rawEventName,
listener,
passive,
);
} else {
unsubscribeListener = addEventCaptureListener(
targetContainerToUse,
targetContainer,
rawEventName,
listener,
);
Expand All @@ -236,14 +236,14 @@ export function addTrappedEventListener(
if (enableUseEventAPI && passive !== undefined) {
// This is only used with passive is either true or false.
unsubscribeListener = addEventBubbleListenerWithPassiveFlag(
targetContainerToUse,
targetContainer,
rawEventName,
listener,
passive,
);
} else {
unsubscribeListener = addEventBubbleListener(
targetContainerToUse,
targetContainer,
rawEventName,
listener,
);
Expand Down

0 comments on commit ea3ae21

Please sign in to comment.