Use Lanes instead of priority event constants (#20762)
Dan Abramov committed
Feb 8, 2021 at 22:30 UTC
35f7441d374bfa7be8e3e9576fd1388333df49cb
2 files changed
+18
-18
packages/react-dom/src/events/ReactDOMEventListener.js
+18
-12
@@ -11,7 +11,6 @@ import type {AnyNativeEvent} from '../events/PluginModuleType';
11
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
12
import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
13
import type {DOMEventName} from '../events/DOMEventNames';
14
-import type {EventPriority} from 'shared/ReactTypes';
14
15
// Intentionally not named imports because Rollup would use dynamic dispatch for
16
// CommonJS interop named imports.
@@ -44,7 +43,6 @@ import {
43
decoupleUpdatePriorityFromScheduler,
44
enableNewReconciler,
45
} from 'shared/ReactFeatureFlags';
47
-import {ContinuousEvent, DefaultEvent, DiscreteEvent} from 'shared/ReactTypes';
46
import {dispatchEventForPluginEventSystem} from './DOMPluginEventSystem';
47
import {
48
flushDiscreteUpdatesIfNeeded,
@@ -52,19 +50,29 @@ import {
50
} from './ReactDOMUpdateBatching';
51
52
import {
53
+ InputDiscreteLanePriority as InputDiscreteLanePriority_old,
54
InputContinuousLanePriority as InputContinuousLanePriority_old,
55
+ DefaultLanePriority as DefaultLanePriority_old,
56
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_old,
57
setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_old,
58
} from 'react-reconciler/src/ReactFiberLane.old';
59
import {
60
+ InputDiscreteLanePriority as InputDiscreteLanePriority_new,
61
InputContinuousLanePriority as InputContinuousLanePriority_new,
62
+ DefaultLanePriority as DefaultLanePriority_new,
63
getCurrentUpdateLanePriority as getCurrentUpdateLanePriority_new,
64
setCurrentUpdateLanePriority as setCurrentUpdateLanePriority_new,
65
} from 'react-reconciler/src/ReactFiberLane.new';
66
67
+const InputDiscreteLanePriority = enableNewReconciler
68
+ ? InputDiscreteLanePriority_new
69
+ : InputDiscreteLanePriority_old;
70
const InputContinuousLanePriority = enableNewReconciler
71
? InputContinuousLanePriority_new
72
: InputContinuousLanePriority_old;
73
+const DefaultLanePriority = enableNewReconciler
74
+ ? DefaultLanePriority_new
75
+ : DefaultLanePriority_old;
76
const getCurrentUpdateLanePriority = enableNewReconciler
77
? getCurrentUpdateLanePriority_new
78
: getCurrentUpdateLanePriority_old;
@@ -108,16 +116,16 @@ export function createEventListenerWrapperWithPriority(
116
domEventName: DOMEventName,
117
eventSystemFlags: EventSystemFlags,
118
): Function {
111
- const eventPriority = getEventPriorityForPluginSystem(domEventName);
119
+ const eventPriority = getEventPriority(domEventName);
120
let listenerWrapper;
121
switch (eventPriority) {
114
- case DiscreteEvent:
122
+ case InputDiscreteLanePriority:
123
listenerWrapper = dispatchDiscreteEvent;
124
break;
117
- case ContinuousEvent:
125
+ case InputContinuousLanePriority:
126
listenerWrapper = dispatchContinuousEvent;
127
break;
120
- case DefaultEvent:
128
+ case DefaultLanePriority:
129
default:
130
listenerWrapper = dispatchEvent;
131
break;
@@ -340,9 +348,7 @@ export function attemptToDispatchEvent(
348
return null;
349
}
350
343
-function getEventPriorityForPluginSystem(
344
- domEventName: DOMEventName,
345
-): EventPriority {
351
+function getEventPriority(domEventName: DOMEventName) {
352
switch (domEventName) {
353
// Used by SimpleEventPlugin:
354
case 'cancel':
@@ -391,7 +397,7 @@ function getEventPriorityForPluginSystem(
397
// eslint-disable-next-line no-fallthrough
398
case 'beforeblur':
399
case 'afterblur':
394
- return DiscreteEvent;
400
+ return InputDiscreteLanePriority;
401
case 'drag':
402
case 'dragenter':
403
case 'dragexit':
@@ -407,8 +413,8 @@ function getEventPriorityForPluginSystem(
413
case 'toggle':
414
case 'touchmove':
415
case 'wheel':
410
- return ContinuousEvent;
416
+ return InputContinuousLanePriority;
417
default:
412
- return DefaultEvent;
418
+ return DefaultLanePriority;
419
}
420
}
packages/shared/ReactTypes.js
-6
@@ -86,12 +86,6 @@ export type RefObject = {|
86
current: any,
87
|};
88
89
-export type EventPriority = 0 | 1 | 2;
90
-
91
-export const DiscreteEvent: EventPriority = 0;
92
-export const ContinuousEvent: EventPriority = 1;
93
-export const DefaultEvent: EventPriority = 2;
94
-
89
export type ReactScope = {|
90
$$typeof: Symbol | number,
91
|};