Skip to content

Commit 4642011

Browse files
committed
Add getCurrentEventPriority to the host config
1 parent d445451 commit 4642011

File tree

9 files changed

+55
-4
lines changed

9 files changed

+55
-4
lines changed

packages/react-art/src/ReactARTHostConfig.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import Transform from 'art/core/transform';
99
import Mode from 'art/modes/current';
1010
import invariant from 'shared/invariant';
11+
import {DefaultEvent} from 'shared/ReactTypes';
1112

1213
import {TYPES, EVENT_TYPES, childrenAsString} from './ReactARTInternals';
1314

@@ -327,6 +328,10 @@ export function getChildHostContext() {
327328
return NO_CONTEXT;
328329
}
329330

331+
export function getCurrentEventPriority() {
332+
return DefaultEvent;
333+
}
334+
330335
export const scheduleTimeout = setTimeout;
331336
export const cancelTimeout = clearTimeout;
332337
export const noTimeout = -1;

packages/react-dom/src/client/ReactDOMHostConfig.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515
ObserveVisibleRectsCallback,
1616
} from 'react-reconciler/src/ReactTestSelectors';
1717
import type {RootType} from './ReactDOMRoot';
18-
import type {ReactScopeInstance} from 'shared/ReactTypes';
18+
import type {ReactScopeInstance, EventPriority} from 'shared/ReactTypes';
1919

2020
import {
2121
precacheFiberNode,
@@ -59,6 +59,7 @@ import {
5959
import dangerousStyleValue from '../shared/dangerousStyleValue';
6060

6161
import {REACT_OPAQUE_ID_TYPE} from 'shared/ReactSymbols';
62+
import {getEventPriorityForPluginSystem} from '../events/DOMEventProperties';
6263
import {retryIfBlockedOn} from '../events/ReactDOMEventReplaying';
6364

6465
import {
@@ -68,6 +69,7 @@ import {
6869
} from 'shared/ReactFeatureFlags';
6970
import {HostComponent, HostText} from 'react-reconciler/src/ReactWorkTags';
7071
import {listenToAllSupportedEvents} from '../events/DOMPluginEventSystem';
72+
import {DefaultEvent} from 'shared/ReactTypes';
7173

7274
export type Type = string;
7375
export type Props = {
@@ -372,6 +374,15 @@ export function createTextInstance(
372374
return textNode;
373375
}
374376

377+
export function getCurrentEventPriority(): EventPriority {
378+
const currentEvent = window.event;
379+
if (currentEvent === undefined) {
380+
return DefaultEvent;
381+
}
382+
// TODO: Is this fast enough? It reads from a Map.
383+
return getEventPriorityForPluginSystem(currentEvent.type);
384+
}
385+
375386
export const isPrimaryRenderer = true;
376387
export const warnsIfNotActing = true;
377388
// This initialization code may run even on server environments

packages/react-native-renderer/src/ReactFabricHostConfig.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ import type {
1717
ReactNativeBaseComponentViewConfig,
1818
TouchedViewDataAtPoint,
1919
} from './ReactNativeTypes';
20+
import type {EventPriority} from 'shared/ReactTypes';
2021

2122
import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils';
2223
import {create, diff} from './ReactNativeAttributePayload';
2324

2425
import invariant from 'shared/invariant';
26+
import {DefaultEvent} from 'shared/ReactTypes';
2527

2628
import {dispatchEvent} from './ReactFabricEventEmitter';
2729

@@ -339,6 +341,10 @@ export function shouldSetTextContent(type: string, props: Props): boolean {
339341
return false;
340342
}
341343

344+
export function getCurrentEventPriority(): EventPriority {
345+
return DefaultEvent;
346+
}
347+
342348
// The Fabric renderer is secondary to the existing React Native renderer.
343349
export const isPrimaryRenderer = false;
344350

packages/react-native-renderer/src/ReactNativeHostConfig.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import type {TouchedViewDataAtPoint} from './ReactNativeTypes';
11+
import type {EventPriority} from 'shared/ReactTypes';
1112

1213
import invariant from 'shared/invariant';
1314

@@ -25,6 +26,7 @@ import {
2526
updateFiberProps,
2627
} from './ReactNativeComponentTree';
2728
import ReactNativeFiberHostComponent from './ReactNativeFiberHostComponent';
29+
import {DefaultEvent} from 'shared/ReactTypes';
2830

2931
const {get: getViewConfigForType} = ReactNativeViewConfigRegistry;
3032

@@ -241,6 +243,10 @@ export function resetAfterCommit(containerInfo: Container): void {
241243
// Noop
242244
}
243245

246+
export function getCurrentEventPriority(): EventPriority {
247+
return DefaultEvent;
248+
}
249+
244250
export const isPrimaryRenderer = true;
245251
export const warnsIfNotActing = true;
246252

packages/react-noop-renderer/src/createReactNoop.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616

1717
import type {Fiber} from 'react-reconciler/src/ReactInternalTypes';
1818
import type {UpdateQueue} from 'react-reconciler/src/ReactUpdateQueue';
19-
import type {ReactNodeList, Thenable} from 'shared/ReactTypes';
19+
import type {ReactNodeList, Thenable, EventPriority} from 'shared/ReactTypes';
2020
import type {RootTag} from 'react-reconciler/src/ReactRootTags';
2121

2222
import * as Scheduler from 'scheduler/unstable_mock';
2323
import {REACT_FRAGMENT_TYPE, REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';
24+
import {DefaultEvent} from 'shared/ReactTypes';
2425
import {
2526
ConcurrentRoot,
2627
BlockingRoot,
@@ -391,6 +392,10 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
391392

392393
resetAfterCommit(): void {},
393394

395+
getCurrentEventPriority(): EventPriority {
396+
return DefaultEvent;
397+
},
398+
394399
now: Scheduler.unstable_now,
395400

396401
isPrimaryRenderer: true,

packages/react-reconciler/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ This is a property (not a function) that should be set to something that can nev
207207

208208
You can proxy this to `queueMicrotask` or its equivalent in your environment.
209209

210+
#### `getCurrentEventPriority(fn)`
211+
212+
If there is no ongoing event (like `window.event` in the DOM), return `0`.
213+
214+
Else, return one of the numbers depending on the ongoing event type:
215+
216+
- For events originating from user input where each event is intentional (e.g. clicks), return `2`.
217+
- For events originating from continuous user input (e.g. mouse move), return `1`.
218+
- For any other events, return `0`.
219+
210220
#### `isPrimaryRenderer`
211221

212222
This is a property (not a function) that should be set to `true` if your renderer is the main one on the page. For example, if you're writing a renderer for the Terminal, it makes sense to set it to `true`, but if your renderer is used *on top of* React DOM or some other existing renderer, set it to `false`.

packages/react-reconciler/src/forks/ReactFiberHostConfig.custom.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const finalizeInitialChildren = $$$hostConfig.finalizeInitialChildren;
5252
export const prepareUpdate = $$$hostConfig.prepareUpdate;
5353
export const shouldSetTextContent = $$$hostConfig.shouldSetTextContent;
5454
export const createTextInstance = $$$hostConfig.createTextInstance;
55+
export const getCurrentEventPriority = $$$hostConfig.getCurrentEventPriority;
5556
export const scheduleTimeout = $$$hostConfig.scheduleTimeout;
5657
export const cancelTimeout = $$$hostConfig.cancelTimeout;
5758
export const scheduleMicrotask = $$$hostConfig.scheduleMicrotask;

packages/react-test-renderer/src/ReactTestHostConfig.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
* @flow
88
*/
99

10+
import type {EventPriority} from 'shared/ReactTypes';
11+
1012
import {REACT_OPAQUE_ID_TYPE} from 'shared/ReactSymbols';
13+
import {DefaultEvent} from 'shared/ReactTypes';
1114

1215
export type Type = string;
1316
export type Props = Object;
@@ -213,6 +216,10 @@ export function createTextInstance(
213216
};
214217
}
215218

219+
export function getCurrentEventPriority(): EventPriority {
220+
return DefaultEvent;
221+
}
222+
216223
export const isPrimaryRenderer = false;
217224
export const warnsIfNotActing = true;
218225

packages/shared/ReactTypes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ export type RefObject = {|
8888

8989
export type EventPriority = 0 | 1 | 2;
9090

91-
export const DiscreteEvent: EventPriority = 0;
91+
export const DefaultEvent: EventPriority = 0;
9292
export const ContinuousEvent: EventPriority = 1;
93-
export const DefaultEvent: EventPriority = 2;
93+
export const DiscreteEvent: EventPriority = 2;
9494

9595
export type ReactScope = {|
9696
$$typeof: Symbol | number,

0 commit comments

Comments
 (0)