Skip to content

Commit 8815e4c

Browse files
authored
Cleanup getListener and EventSystemFlags (#18469)
1 parent 5e46454 commit 8815e4c

22 files changed

Lines changed: 111 additions & 86 deletions

packages/legacy-events/EventSystemFlags.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/legacy-events/PluginModuleType.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@ import type {
1313
ReactSyntheticEvent,
1414
} from './ReactSyntheticEventType';
1515
import type {TopLevelType} from './TopLevelEventTypes';
16-
import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
1716

1817
export type EventTypes = {[key: string]: DispatchConfig, ...};
1918

2019
export type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | TouchEvent;
2120

2221
export type PluginName = string;
2322

23+
export type EventSystemFlags = number;
24+
2425
export type PluginModule<NativeEvent> = {
2526
eventTypes: EventTypes,
2627
extractEvents: (
2728
topLevelType: TopLevelType,
2829
targetInst: null | Fiber,
2930
nativeTarget: NativeEvent,
3031
nativeEventTarget: null | EventTarget,
31-
eventSystemFlags: EventSystemFlags,
32+
eventSystemFlags?: number,
3233
container?: null | EventTarget,
3334
) => ?ReactSyntheticEvent,
3435
tapMoveThreshold?: number,

packages/legacy-events/ResponderEventPlugin.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
hasDispatches,
1111
executeDispatchesInOrderStopAtTrue,
1212
getInstanceFromNode,
13+
getFiberCurrentPropsFromNode,
1314
} from './EventPluginUtils';
1415
import ResponderSyntheticEvent from './ResponderSyntheticEvent';
1516
import ResponderTouchHistoryStore from './ResponderTouchHistoryStore';
@@ -25,10 +26,10 @@ import {
2526
moveDependencies,
2627
endDependencies,
2728
} from './ResponderTopLevelEventTypes';
28-
import getListener from './getListener';
2929
import accumulateInto from './accumulateInto';
3030
import forEachAccumulated from './forEachAccumulated';
3131
import {HostComponent} from 'react-reconciler/src/ReactWorkTags';
32+
import invariant from 'shared/invariant';
3233

3334
/**
3435
* Instance of element that should respond to touch/move types of interactions,
@@ -208,7 +209,7 @@ export function getLowestCommonAncestor(instA, instB) {
208209
/**
209210
* Return if A is an ancestor of B.
210211
*/
211-
export function isAncestor(instA, instB) {
212+
function isAncestor(instA, instB) {
212213
while (instB) {
213214
if (instA === instB || instA === instB.alternate) {
214215
return true;
@@ -221,7 +222,7 @@ export function isAncestor(instA, instB) {
221222
/**
222223
* Simulates the traversal of a two-phase, capture/bubble event dispatch.
223224
*/
224-
export function traverseTwoPhase(inst, fn, arg) {
225+
function traverseTwoPhase(inst, fn, arg) {
225226
const path = [];
226227
while (inst) {
227228
path.push(inst);
@@ -236,6 +237,27 @@ export function traverseTwoPhase(inst, fn, arg) {
236237
}
237238
}
238239

240+
function getListener(inst, registrationName) {
241+
const stateNode = inst.stateNode;
242+
if (stateNode === null) {
243+
// Work in progress (ex: onload events in incremental mode).
244+
return null;
245+
}
246+
const props = getFiberCurrentPropsFromNode(stateNode);
247+
if (props === null) {
248+
// Work in progress.
249+
return null;
250+
}
251+
const listener = props[registrationName];
252+
invariant(
253+
!listener || typeof listener === 'function',
254+
'Expected `%s` listener to be a function, instead got a value of `%s` type.',
255+
registrationName,
256+
typeof listener,
257+
);
258+
return listener;
259+
}
260+
239261
function listenerAtPhase(inst, event, propagationPhase: PropagationPhases) {
240262
const registrationName =
241263
event.dispatchConfig.phasedRegistrationNames[propagationPhase];

packages/legacy-events/__tests__/ResponderEventPlugin-test.internal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'use strict';
1111

1212
const {HostComponent} = require('react-reconciler/src/ReactWorkTags');
13-
const {PLUGIN_EVENT_SYSTEM} = require('legacy-events/EventSystemFlags');
13+
const {PLUGIN_EVENT_SYSTEM} = require('react-dom/src/events/EventSystemFlags');
1414

1515
let EventBatching;
1616
let EventPluginUtils;

packages/react-dom/src/__tests__/ReactBrowserEventEmitter-test.internal.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ describe('ReactBrowserEventEmitter', () => {
6262
LISTENER.mockClear();
6363

6464
ReactFeatureFlags = require('shared/ReactFeatureFlags');
65-
EventPluginGetListener = require('legacy-events/getListener').default;
65+
EventPluginGetListener = require('react-dom/src/events/getListener')
66+
.default;
6667
EventPluginRegistry = require('legacy-events/EventPluginRegistry');
6768
React = require('react');
6869
ReactDOM = require('react-dom');

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ import {
7878
IS_PASSIVE,
7979
PLUGIN_EVENT_SYSTEM,
8080
USE_EVENT_SYSTEM,
81-
} from 'legacy-events/EventSystemFlags';
81+
} from '../events/EventSystemFlags';
8282
import {
8383
isManagedDOMElement,
8484
isValidEventTarget,
@@ -102,6 +102,7 @@ export type Type = string;
102102
export type Props = {
103103
autoFocus?: boolean,
104104
children?: mixed,
105+
disabled?: boolean,
105106
hidden?: boolean,
106107
suppressHydrationWarning?: boolean,
107108
dangerouslySetInnerHTML?: mixed,

packages/react-dom/src/events/DOMLegacyEventPluginSystem.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import type {AnyNativeEvent} from 'legacy-events/PluginModuleType';
1111
import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';
1212
import type {ElementListenerMap} from '../events/DOMEventListenerMap';
13-
import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
13+
import type {EventSystemFlags} from './EventSystemFlags';
1414
import type {Fiber} from 'react-reconciler/src/ReactFiber';
1515
import type {PluginModule} from 'legacy-events/PluginModuleType';
1616
import type {ReactSyntheticEvent} from 'legacy-events/ReactSyntheticEventType';
@@ -21,10 +21,7 @@ import {
2121
HostComponent,
2222
HostText,
2323
} from 'react-reconciler/src/ReactWorkTags';
24-
import {
25-
IS_FIRST_ANCESTOR,
26-
PLUGIN_EVENT_SYSTEM,
27-
} from 'legacy-events/EventSystemFlags';
24+
import {IS_FIRST_ANCESTOR, PLUGIN_EVENT_SYSTEM} from './EventSystemFlags';
2825
import {batchedEventUpdates} from 'legacy-events/ReactGenericBatching';
2926
import {runEventsInBatch} from 'legacy-events/EventBatching';
3027
import {plugins} from 'legacy-events/EventPluginRegistry';

packages/react-dom/src/events/DOMModernPluginEventSystem.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
ElementListenerMap,
1414
ElementListenerMapEntry,
1515
} from '../events/DOMEventListenerMap';
16-
import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
16+
import type {EventSystemFlags} from './EventSystemFlags';
1717
import type {EventPriority, ReactScopeMethods} from 'shared/ReactTypes';
1818
import type {Fiber} from 'react-reconciler/src/ReactFiber';
1919
import type {PluginModule} from 'legacy-events/PluginModuleType';
@@ -32,7 +32,7 @@ import {
3232
IS_REPLAYED,
3333
IS_TARGET_PHASE_ONLY,
3434
USE_EVENT_SYSTEM,
35-
} from 'legacy-events/EventSystemFlags';
35+
} from './EventSystemFlags';
3636

3737
import {HostRoot, HostPortal} from 'react-reconciler/src/ReactWorkTags';
3838

packages/react-dom/src/events/DeprecatedDOMEventResponderSystem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
type EventSystemFlags,
1111
IS_PASSIVE,
1212
PASSIVE_NOT_SUPPORTED,
13-
} from 'legacy-events/EventSystemFlags';
13+
} from './EventSystemFlags';
1414
import type {AnyNativeEvent} from 'legacy-events/PluginModuleType';
1515
import {
1616
HostComponent,

packages/react-dom/src/events/EnterLeaveEventPlugin.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import {
1111
TOP_POINTER_OUT,
1212
TOP_POINTER_OVER,
1313
} from './DOMTopLevelEventTypes';
14-
import {IS_REPLAYED, IS_FIRST_ANCESTOR} from 'legacy-events/EventSystemFlags';
14+
import {
15+
IS_REPLAYED,
16+
IS_FIRST_ANCESTOR,
17+
} from 'react-dom/src/events/EventSystemFlags';
1518
import SyntheticMouseEvent from './SyntheticMouseEvent';
1619
import SyntheticPointerEvent from './SyntheticPointerEvent';
1720
import {

0 commit comments

Comments
 (0)