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

[Concurrent Mode] Add missing event plugin priorities #17914

Merged
merged 1 commit into from Jan 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 45 additions & 9 deletions packages/react-dom/src/events/DOMEventProperties.js
Expand Up @@ -36,11 +36,17 @@ export const topLevelEventsToDispatchConfig: Map<

const eventPriorities = new Map();

// We store all the DOMTopLevelEventTypes and their React Types in pairs of two.
// Furthermore, we ignore prettier so we can keep the formatting sane.
// We store most of the events in this module in pairs of two strings so we can re-use
// the code required to apply the same logic for event prioritization and that of the
// SimpleEventPlugin. This complicates things slightly, but the aim is to reduce code
// duplication (for which there would be quite a bit). For the events that are not needed
// for the SimpleEventPlugin (otherDiscreteEvents) we process them separately as an
// array of top level events.

// Lastly, we ignore prettier so we can keep the formatting sane.

// prettier-ignore
const discreteEvents = [
const discreteEventPairsForSimpleEventPlugin = [
DOMTopLevelEventTypes.TOP_BLUR, 'blur',
DOMTopLevelEventTypes.TOP_CANCEL, 'cancel',
DOMTopLevelEventTypes.TOP_CLICK, 'click',
Expand Down Expand Up @@ -77,8 +83,17 @@ const discreteEvents = [
DOMTopLevelEventTypes.TOP_VOLUME_CHANGE, 'volumeChange',
];

const otherDiscreteEvents = [
DOMTopLevelEventTypes.TOP_CHANGE,
DOMTopLevelEventTypes.TOP_SELECTION_CHANGE,
DOMTopLevelEventTypes.TOP_TEXT_INPUT,
DOMTopLevelEventTypes.TOP_COMPOSITION_START,
DOMTopLevelEventTypes.TOP_COMPOSITION_END,
DOMTopLevelEventTypes.TOP_COMPOSITION_UPDATE,
];

// prettier-ignore
const userBlockingEvents = [
const userBlockingPairsForSimpleEventPlugin = [
DOMTopLevelEventTypes.TOP_DRAG, 'drag',
DOMTopLevelEventTypes.TOP_DRAG_ENTER, 'dragEnter',
DOMTopLevelEventTypes.TOP_DRAG_EXIT, 'dragExit',
Expand All @@ -97,7 +112,7 @@ const userBlockingEvents = [
];

// prettier-ignore
const continuousEvents = [
const continuousPairsForSimpleEventPlugin = [
DOMTopLevelEventTypes.TOP_ABORT, 'abort',
DOMTopLevelEventTypes.TOP_ANIMATION_END, 'animationEnd',
DOMTopLevelEventTypes.TOP_ANIMATION_ITERATION, 'animationIteration',
Expand Down Expand Up @@ -144,7 +159,7 @@ const continuousEvents = [
* ]);
*/

function processTopEventTypesByPriority(
function processSimpleEventPluginPairsByPriority(
eventTypes: Array<DOMTopLevelEventType | string>,
priority: EventPriority,
): void {
Expand Down Expand Up @@ -174,9 +189,30 @@ function processTopEventTypesByPriority(
}
}

processTopEventTypesByPriority(discreteEvents, DiscreteEvent);
processTopEventTypesByPriority(userBlockingEvents, UserBlockingEvent);
processTopEventTypesByPriority(continuousEvents, ContinuousEvent);
function processTopEventPairsByPriority(
eventTypes: Array<DOMTopLevelEventType | string>,
priority: EventPriority,
): void {
for (let i = 0; i < eventTypes.length; i++) {
eventPriorities.set(eventTypes[i], priority);
}
}

// SimpleEventPlugin
processSimpleEventPluginPairsByPriority(
discreteEventPairsForSimpleEventPlugin,
DiscreteEvent,
);
processSimpleEventPluginPairsByPriority(
userBlockingPairsForSimpleEventPlugin,
UserBlockingEvent,
);
processSimpleEventPluginPairsByPriority(
continuousPairsForSimpleEventPlugin,
ContinuousEvent,
);
// Not used by SimpleEventPlugin
processTopEventPairsByPriority(otherDiscreteEvents, DiscreteEvent);

export function getEventPriorityForPluginSystem(
topLevelType: TopLevelType,
Expand Down