Skip to content

Commit

Permalink
[react-events] Remove lastNativeEvent in favor of SystemFlags (#17585)
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm authored Dec 13, 2019
1 parent b15bf36 commit be603f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/legacy-events/EventSystemFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export const IS_PASSIVE = 1 << 2;
export const IS_ACTIVE = 1 << 3;
export const PASSIVE_NOT_SUPPORTED = 1 << 4;
export const IS_REPLAYED = 1 << 5;
export const IS_FIRST_ANCESTOR = 1 << 6;
15 changes: 5 additions & 10 deletions packages/react-dom/src/events/EnterLeaveEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
TOP_POINTER_OUT,
TOP_POINTER_OVER,
} from './DOMTopLevelEventTypes';
import {IS_REPLAYED} from 'legacy-events/EventSystemFlags';
import {IS_REPLAYED, IS_FIRST_ANCESTOR} from 'legacy-events/EventSystemFlags';
import SyntheticMouseEvent from './SyntheticMouseEvent';
import SyntheticPointerEvent from './SyntheticPointerEvent';
import {
Expand Down Expand Up @@ -42,12 +42,6 @@ const eventTypes = {
},
};

// We track the lastNativeEvent to ensure that when we encounter
// cases where we process the same nativeEvent multiple times,
// which can happen when have multiple ancestors, that we don't
// duplicate enter
let lastNativeEvent;

const EnterLeaveEventPlugin = {
eventTypes: eventTypes,

Expand Down Expand Up @@ -169,11 +163,12 @@ const EnterLeaveEventPlugin = {

accumulateEnterLeaveDispatches(leave, enter, from, to);

if (nativeEvent === lastNativeEvent) {
lastNativeEvent = null;
// If we are not processing the first ancestor, then we
// should not process the same nativeEvent again, as we
// will have already processed it in the first ancestor.
if ((eventSystemFlags & IS_FIRST_ANCESTOR) === 0) {
return [leave];
}
lastNativeEvent = nativeEvent;

return [leave, enter];
},
Expand Down
9 changes: 8 additions & 1 deletion packages/react-dom/src/events/ReactDOMEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
IS_PASSIVE,
IS_ACTIVE,
PASSIVE_NOT_SUPPORTED,
IS_FIRST_ANCESTOR,
} from 'legacy-events/EventSystemFlags';

import {
Expand Down Expand Up @@ -175,13 +176,19 @@ function handleTopLevel(bookKeeping: BookKeepingInstance) {
const eventTarget = getEventTarget(bookKeeping.nativeEvent);
const topLevelType = ((bookKeeping.topLevelType: any): DOMTopLevelEventType);
const nativeEvent = ((bookKeeping.nativeEvent: any): AnyNativeEvent);
let eventSystemFlags = bookKeeping.eventSystemFlags;

// If this is the first ancestor, we mark it on the system flags
if (i === 0) {
eventSystemFlags |= IS_FIRST_ANCESTOR;
}

runExtractedPluginEventsInBatch(
topLevelType,
targetInst,
nativeEvent,
eventTarget,
bookKeeping.eventSystemFlags,
eventSystemFlags,
);
}
}
Expand Down

0 comments on commit be603f5

Please sign in to comment.