Skip to content

Use Lanes instead of priority event constants #20762

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

Merged
merged 1 commit into from
Feb 8, 2021
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
30 changes: 18 additions & 12 deletions packages/react-dom/src/events/ReactDOMEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {AnyNativeEvent} from '../events/PluginModuleType';
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
import type {DOMEventName} from '../events/DOMEventNames';
import type {EventPriority} from 'shared/ReactTypes';

// Intentionally not named imports because Rollup would use dynamic dispatch for
// CommonJS interop named imports.
Expand Down Expand Up @@ -44,27 +43,36 @@ import {
decoupleUpdatePriorityFromScheduler,
enableNewReconciler,
} from 'shared/ReactFeatureFlags';
import {ContinuousEvent, DefaultEvent, DiscreteEvent} from 'shared/ReactTypes';
import {dispatchEventForPluginEventSystem} from './DOMPluginEventSystem';
import {
flushDiscreteUpdatesIfNeeded,
discreteUpdates,
} from './ReactDOMUpdateBatching';

import {
InputDiscreteLanePriority as InputDiscreteLanePriority_old,
InputContinuousLanePriority as InputContinuousLanePriority_old,
DefaultLanePriority as DefaultLanePriority_old,
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_old,
setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_old,
} from 'react-reconciler/src/ReactFiberLane.old';
import {
InputDiscreteLanePriority as InputDiscreteLanePriority_new,
InputContinuousLanePriority as InputContinuousLanePriority_new,
DefaultLanePriority as DefaultLanePriority_new,
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_new,
setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_new,
} from 'react-reconciler/src/ReactFiberLane.new';

const InputDiscreteLanePriority = enableNewReconciler
? InputDiscreteLanePriority_new
: InputDiscreteLanePriority_old;
const InputContinuousLanePriority = enableNewReconciler
? InputContinuousLanePriority_new
: InputContinuousLanePriority_old;
const DefaultLanePriority = enableNewReconciler
? DefaultLanePriority_new
: DefaultLanePriority_old;
const getCurrentUpdateLanePriority = enableNewReconciler
? getCurrentUpdateLanePriority_new
: getCurrentUpdateLanePriority_old;
Expand Down Expand Up @@ -108,16 +116,16 @@ export function createEventListenerWrapperWithPriority(
domEventName: DOMEventName,
eventSystemFlags: EventSystemFlags,
): Function {
const eventPriority = getEventPriorityForPluginSystem(domEventName);
const eventPriority = getEventPriority(domEventName);
let listenerWrapper;
switch (eventPriority) {
case DiscreteEvent:
case InputDiscreteLanePriority:
listenerWrapper = dispatchDiscreteEvent;
break;
case ContinuousEvent:
case InputContinuousLanePriority:
listenerWrapper = dispatchContinuousEvent;
break;
case DefaultEvent:
case DefaultLanePriority:
default:
listenerWrapper = dispatchEvent;
break;
Expand Down Expand Up @@ -340,9 +348,7 @@ export function attemptToDispatchEvent(
return null;
}

function getEventPriorityForPluginSystem(
domEventName: DOMEventName,
): EventPriority {
function getEventPriority(domEventName: DOMEventName) {
switch (domEventName) {
// Used by SimpleEventPlugin:
case 'cancel':
Expand Down Expand Up @@ -391,7 +397,7 @@ function getEventPriorityForPluginSystem(
// eslint-disable-next-line no-fallthrough
case 'beforeblur':
case 'afterblur':
return DiscreteEvent;
return InputDiscreteLanePriority;
case 'drag':
case 'dragenter':
case 'dragexit':
Expand All @@ -407,8 +413,8 @@ function getEventPriorityForPluginSystem(
case 'toggle':
case 'touchmove':
case 'wheel':
return ContinuousEvent;
return InputContinuousLanePriority;
default:
return DefaultEvent;
return DefaultLanePriority;
}
}
6 changes: 0 additions & 6 deletions packages/shared/ReactTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ export type RefObject = {|
current: any,
|};

export type EventPriority = 0 | 1 | 2;

export const DiscreteEvent: EventPriority = 0;
export const ContinuousEvent: EventPriority = 1;
export const DefaultEvent: EventPriority = 2;

export type ReactScope = {|
$$typeof: Symbol | number,
|};
Expand Down