@samitouri / QOS-React-2 / commits / 8815e4cc72

Cleanup getListener and EventSystemFlags (#18469)

Dominic Gannaway committed Apr 2, 2020 at 23:17 UTC 8815e4cc7277012c196d4a89db4e2b6c80065e33
22 files changed +111 -86
packages/legacy-events/EventSystemFlags.js deleted
-20
@@ -1,20 +0,0 @@
1 -/**
2 - * Copyright (c) Facebook, Inc. and its affiliates.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @flow
8 - */
9 -
10 -export type EventSystemFlags = number;
11 -
12 -export const PLUGIN_EVENT_SYSTEM = 1;
13 -export const RESPONDER_EVENT_SYSTEM = 1 << 1;
14 -export const USE_EVENT_SYSTEM = 1 << 2;
15 -export const IS_TARGET_PHASE_ONLY = 1 << 3;
16 -export const IS_PASSIVE = 1 << 4;
17 -export const PASSIVE_NOT_SUPPORTED = 1 << 5;
18 -export const IS_REPLAYED = 1 << 6;
19 -export const IS_FIRST_ANCESTOR = 1 << 7;
20 -export const LEGACY_FB_SUPPORT = 1 << 8;
packages/legacy-events/PluginModuleType.js
+3 -2
@@ -13,7 +13,6 @@ import type {
13 ReactSyntheticEvent,
14 } from './ReactSyntheticEventType';
15 import type {TopLevelType} from './TopLevelEventTypes';
16 -import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
16
17 export type EventTypes = {[key: string]: DispatchConfig, ...};
18
@@ -21,6 +20,8 @@ export type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | TouchEvent;
20
21 export type PluginName = string;
22
23 +export type EventSystemFlags = number;
24 +
25 export type PluginModule<NativeEvent> = {
26 eventTypes: EventTypes,
27 extractEvents: (
@@ -28,7 +29,7 @@ export type PluginModule<NativeEvent> = {
29 targetInst: null | Fiber,
30 nativeTarget: NativeEvent,
31 nativeEventTarget: null | EventTarget,
31 - eventSystemFlags: EventSystemFlags,
32 + eventSystemFlags?: number,
33 container?: null | EventTarget,
34 ) => ?ReactSyntheticEvent,
35 tapMoveThreshold?: number,
packages/legacy-events/ResponderEventPlugin.js
+25 -3
@@ -10,6 +10,7 @@ import {
10 hasDispatches,
11 executeDispatchesInOrderStopAtTrue,
12 getInstanceFromNode,
13 + getFiberCurrentPropsFromNode,
14 } from './EventPluginUtils';
15 import ResponderSyntheticEvent from './ResponderSyntheticEvent';
16 import ResponderTouchHistoryStore from './ResponderTouchHistoryStore';
@@ -25,10 +26,10 @@ import {
26 moveDependencies,
27 endDependencies,
28 } from './ResponderTopLevelEventTypes';
28 -import getListener from './getListener';
29 import accumulateInto from './accumulateInto';
30 import forEachAccumulated from './forEachAccumulated';
31 import {HostComponent} from 'react-reconciler/src/ReactWorkTags';
32 +import invariant from 'shared/invariant';
33
34 /**
35 * Instance of element that should respond to touch/move types of interactions,
@@ -208,7 +209,7 @@ export function getLowestCommonAncestor(instA, instB) {
209 /**
210 * Return if A is an ancestor of B.
211 */
211 -export function isAncestor(instA, instB) {
212 +function isAncestor(instA, instB) {
213 while (instB) {
214 if (instA === instB || instA === instB.alternate) {
215 return true;
@@ -221,7 +222,7 @@ export function isAncestor(instA, instB) {
222 /**
223 * Simulates the traversal of a two-phase, capture/bubble event dispatch.
224 */
224 -export function traverseTwoPhase(inst, fn, arg) {
225 +function traverseTwoPhase(inst, fn, arg) {
226 const path = [];
227 while (inst) {
228 path.push(inst);
@@ -236,6 +237,27 @@ export function traverseTwoPhase(inst, fn, arg) {
237 }
238 }
239
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 +
261 function listenerAtPhase(inst, event, propagationPhase: PropagationPhases) {
262 const registrationName =
263 event.dispatchConfig.phasedRegistrationNames[propagationPhase];
packages/legacy-events/__tests__/ResponderEventPlugin-test.internal.js
+1 -1
@@ -10,7 +10,7 @@
10 'use strict';
11
12 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');
14
15 let EventBatching;
16 let EventPluginUtils;
packages/react-dom/src/__tests__/ReactBrowserEventEmitter-test.internal.js
+2 -1
@@ -62,7 +62,8 @@ describe('ReactBrowserEventEmitter', () => {
62 LISTENER.mockClear();
63
64 ReactFeatureFlags = require('shared/ReactFeatureFlags');
65 - EventPluginGetListener = require('legacy-events/getListener').default;
65 + EventPluginGetListener = require('react-dom/src/events/getListener')
66 + .default;
67 EventPluginRegistry = require('legacy-events/EventPluginRegistry');
68 React = require('react');
69 ReactDOM = require('react-dom');
packages/react-dom/src/client/ReactDOMHostConfig.js
+2 -1
@@ -78,7 +78,7 @@ import {
78 IS_PASSIVE,
79 PLUGIN_EVENT_SYSTEM,
80 USE_EVENT_SYSTEM,
81 -} from 'legacy-events/EventSystemFlags';
81 +} from '../events/EventSystemFlags';
82 import {
83 isManagedDOMElement,
84 isValidEventTarget,
@@ -102,6 +102,7 @@ export type Type = string;
102 export type Props = {
103 autoFocus?: boolean,
104 children?: mixed,
105 + disabled?: boolean,
106 hidden?: boolean,
107 suppressHydrationWarning?: boolean,
108 dangerouslySetInnerHTML?: mixed,
packages/react-dom/src/events/DOMLegacyEventPluginSystem.js
+2 -5
@@ -10,7 +10,7 @@
10 import type {AnyNativeEvent} from 'legacy-events/PluginModuleType';
11 import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';
12 import type {ElementListenerMap} from '../events/DOMEventListenerMap';
13 -import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
13 +import type {EventSystemFlags} from './EventSystemFlags';
14 import type {Fiber} from 'react-reconciler/src/ReactFiber';
15 import type {PluginModule} from 'legacy-events/PluginModuleType';
16 import type {ReactSyntheticEvent} from 'legacy-events/ReactSyntheticEventType';
@@ -21,10 +21,7 @@ import {
21 HostComponent,
22 HostText,
23 } 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';
25 import {batchedEventUpdates} from 'legacy-events/ReactGenericBatching';
26 import {runEventsInBatch} from 'legacy-events/EventBatching';
27 import {plugins} from 'legacy-events/EventPluginRegistry';
packages/react-dom/src/events/DOMModernPluginEventSystem.js
+2 -2
@@ -13,7 +13,7 @@ import type {
13 ElementListenerMap,
14 ElementListenerMapEntry,
15 } from '../events/DOMEventListenerMap';
16 -import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
16 +import type {EventSystemFlags} from './EventSystemFlags';
17 import type {EventPriority, ReactScopeMethods} from 'shared/ReactTypes';
18 import type {Fiber} from 'react-reconciler/src/ReactFiber';
19 import type {PluginModule} from 'legacy-events/PluginModuleType';
@@ -32,7 +32,7 @@ import {
32 IS_REPLAYED,
33 IS_TARGET_PHASE_ONLY,
34 USE_EVENT_SYSTEM,
35 -} from 'legacy-events/EventSystemFlags';
35 +} from './EventSystemFlags';
36
37 import {HostRoot, HostPortal} from 'react-reconciler/src/ReactWorkTags';
38
packages/react-dom/src/events/DeprecatedDOMEventResponderSystem.js
+1 -1
@@ -10,7 +10,7 @@ import {
10 type EventSystemFlags,
11 IS_PASSIVE,
12 PASSIVE_NOT_SUPPORTED,
13 -} from 'legacy-events/EventSystemFlags';
13 +} from './EventSystemFlags';
14 import type {AnyNativeEvent} from 'legacy-events/PluginModuleType';
15 import {
16 HostComponent,
packages/react-dom/src/events/EnterLeaveEventPlugin.js
+4 -1
@@ -11,7 +11,10 @@ import {
11 TOP_POINTER_OUT,
12 TOP_POINTER_OVER,
13 } 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';
18 import SyntheticMouseEvent from './SyntheticMouseEvent';
19 import SyntheticPointerEvent from './SyntheticPointerEvent';
20 import {
packages/react-dom/src/events/EventSystemFlags.js
+6 -6
@@ -11,10 +11,10 @@ export type EventSystemFlags = number;
11
12 export const PLUGIN_EVENT_SYSTEM = 1;
13 export const RESPONDER_EVENT_SYSTEM = 1 << 1;
14 -export const IS_PASSIVE = 1 << 2;
15 -export const IS_ACTIVE = 1 << 3;
16 -export const PASSIVE_NOT_SUPPORTED = 1 << 4;
17 -export const IS_REPLAYED = 1 << 5;
18 -export const IS_FIRST_ANCESTOR = 1 << 6;
19 -export const IS_TARGET_EVENT_ONLY = 1 << 7;
14 +export const USE_EVENT_SYSTEM = 1 << 2;
15 +export const IS_TARGET_PHASE_ONLY = 1 << 3;
16 +export const IS_PASSIVE = 1 << 4;
17 +export const PASSIVE_NOT_SUPPORTED = 1 << 5;
18 +export const IS_REPLAYED = 1 << 6;
19 +export const IS_FIRST_ANCESTOR = 1 << 7;
20 export const LEGACY_FB_SUPPORT = 1 << 8;
packages/react-dom/src/events/ReactDOMEventListener.js
+1 -1
@@ -42,7 +42,7 @@ import {
42 RESPONDER_EVENT_SYSTEM,
43 IS_PASSIVE,
44 PASSIVE_NOT_SUPPORTED,
45 -} from 'legacy-events/EventSystemFlags';
45 +} from './EventSystemFlags';
46
47 import {
48 addEventBubbleListener,
packages/react-dom/src/events/ReactDOMEventReplaying.js
+2 -2
@@ -11,7 +11,7 @@ import type {AnyNativeEvent} from 'legacy-events/PluginModuleType';
11 import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
12 import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';
13 import type {ElementListenerMap} from '../events/DOMEventListenerMap';
14 -import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
14 +import type {EventSystemFlags} from './EventSystemFlags';
15 import type {FiberRoot} from 'react-reconciler/src/ReactFiberRoot';
16
17 import {
@@ -118,7 +118,7 @@ import {
118 TOP_FOCUS,
119 TOP_BLUR,
120 } from './DOMTopLevelEventTypes';
121 -import {IS_REPLAYED, PLUGIN_EVENT_SYSTEM} from 'legacy-events/EventSystemFlags';
121 +import {IS_REPLAYED, PLUGIN_EVENT_SYSTEM} from './EventSystemFlags';
122 import {legacyListenToTopLevelEvent} from './DOMLegacyEventPluginSystem';
123 import {listenToTopLevelEvent} from './DOMModernPluginEventSystem';
124
packages/react-dom/src/events/SimpleEventPlugin.js
+3 -3
@@ -14,10 +14,10 @@ import type {
14 import type {ReactSyntheticEvent} from 'legacy-events/ReactSyntheticEventType';
15 import type {Fiber} from 'react-reconciler/src/ReactFiber';
16 import type {PluginModule} from 'legacy-events/PluginModuleType';
17 -import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
17 +import type {EventSystemFlags} from './EventSystemFlags';
18
19 import SyntheticEvent from 'legacy-events/SyntheticEvent';
20 -import {IS_TARGET_PHASE_ONLY} from 'legacy-events/EventSystemFlags';
20 +import {IS_TARGET_PHASE_ONLY} from './EventSystemFlags';
21
22 import * as DOMTopLevelEventTypes from './DOMTopLevelEventTypes';
23 import {
@@ -86,7 +86,7 @@ const SimpleEventPlugin: PluginModule<MouseEvent> = {
86 targetInst: null | Fiber,
87 nativeEvent: MouseEvent,
88 nativeEventTarget: null | EventTarget,
89 - eventSystemFlags: EventSystemFlags,
89 + eventSystemFlags?: EventSystemFlags,
90 targetContainer?: null | EventTarget,
91 ): null | ReactSyntheticEvent {
92 const dispatchConfig = topLevelEventsToDispatchConfig.get(topLevelType);
packages/react-dom/src/events/accumulateEnterLeaveListeners.js
+1 -1
@@ -10,8 +10,8 @@
10 import type {Fiber} from 'react-reconciler/src/ReactFiber';
11 import type {ReactSyntheticEvent} from 'legacy-events/ReactSyntheticEventType';
12
13 -import getListener from 'legacy-events/getListener';
13 import {HostComponent} from 'react-reconciler/src/ReactWorkTags';
14 +import getListener from './getListener';
15
16 function getParent(inst: Fiber | null): Fiber | null {
17 if (inst === null) {
packages/react-dom/src/events/accumulateTwoPhaseListeners.js
+1 -1
@@ -20,7 +20,7 @@ import {
20 enableModernEventSystem,
21 } from 'shared/ReactFeatureFlags';
22
23 -import getListener from 'legacy-events/getListener';
23 +import getListener from './getListener';
24 import {getListenersFromTarget} from '../client/ReactDOMComponentTree';
25 import {reactScopeListenerStore} from './DOMModernPluginEventSystem';
26
packages/react-dom/src/events/getListener.js renamed
+14 -9
@@ -7,12 +7,12 @@
7 */
8
9 import type {Fiber} from 'react-reconciler/src/ReactFiber';
10 +import type {Props} from '../client/ReactDOMHostConfig';
11
12 import invariant from 'shared/invariant';
13 +import {getFiberCurrentPropsFromNode} from '../client/ReactDOMComponentTree';
14
13 -import {getFiberCurrentPropsFromNode} from './EventPluginUtils';
14 -
15 -function isInteractive(tag) {
15 +function isInteractive(tag: string): boolean {
16 return (
17 tag === 'button' ||
18 tag === 'input' ||
@@ -21,7 +21,11 @@ function isInteractive(tag) {
21 );
22 }
23
24 -function shouldPreventMouseEvent(name, type, props) {
24 +function shouldPreventMouseEvent(
25 + name: string,
26 + type: string,
27 + props: Props,
28 +): boolean {
29 switch (name) {
30 case 'onClick':
31 case 'onClickCapture':
@@ -45,16 +49,17 @@ function shouldPreventMouseEvent(name, type, props) {
49 * @param {string} registrationName Name of listener (e.g. `onClick`).
50 * @return {?function} The stored callback.
51 */
48 -export default function getListener(inst: Fiber, registrationName: string) {
49 - // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
50 - // live here; needs to be moved to a better place soon
52 +export default function getListener(
53 + inst: Fiber,
54 + registrationName: string,
55 +): Function | null {
56 const stateNode = inst.stateNode;
52 - if (!stateNode) {
57 + if (stateNode === null) {
58 // Work in progress (ex: onload events in incremental mode).
59 return null;
60 }
61 const props = getFiberCurrentPropsFromNode(stateNode);
57 - if (!props) {
62 + if (props === null) {
63 // Work in progress.
64 return null;
65 }
packages/react-dom/src/test-utils/ReactTestUtils.js
+1 -1
@@ -19,7 +19,6 @@ import SyntheticEvent from 'legacy-events/SyntheticEvent';
19 import invariant from 'shared/invariant';
20 import {ELEMENT_NODE} from '../shared/HTMLNodeType';
21 import * as DOMTopLevelEventTypes from '../events/DOMTopLevelEventTypes';
22 -import {PLUGIN_EVENT_SYSTEM} from 'legacy-events/EventSystemFlags';
22 import act from './ReactTestUtilsAct';
23 import forEachAccumulated from 'legacy-events/forEachAccumulated';
24 import accumulateInto from 'legacy-events/accumulateInto';
@@ -62,6 +61,7 @@ let hasWarnedAboutDeprecatedMockComponent = false;
61 */
62 function simulateNativeEventOnNode(topLevelType, node, fakeNativeEvent) {
63 fakeNativeEvent.target = node;
64 + const PLUGIN_EVENT_SYSTEM = 1;
65 dispatchEvent(topLevelType, PLUGIN_EVENT_SYSTEM, null, fakeNativeEvent);
66 }
67
packages/react-native-renderer/src/ReactFabricEventEmitter.js
+1 -8
@@ -8,19 +8,17 @@
8 */
9
10 import type {AnyNativeEvent} from 'legacy-events/PluginModuleType';
11 -import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
11 import type {Fiber} from 'react-reconciler/src/ReactFiber';
12 import type {PluginModule} from 'legacy-events/PluginModuleType';
13 import type {ReactSyntheticEvent} from 'legacy-events/ReactSyntheticEventType';
14 import type {TopLevelType} from 'legacy-events/TopLevelEventTypes';
15
17 -import {PLUGIN_EVENT_SYSTEM} from 'legacy-events/EventSystemFlags';
16 import {registrationNameModules} from 'legacy-events/EventPluginRegistry';
17 import {batchedUpdates} from 'legacy-events/ReactGenericBatching';
18 import accumulateInto from 'legacy-events/accumulateInto';
19
20 import {plugins} from 'legacy-events/EventPluginRegistry';
23 -import getListener from 'legacy-events/getListener';
21 +import getListener from './ReactNativeGetListener';
22 import {runEventsInBatch} from 'legacy-events/EventBatching';
23
24 export {getListener, registrationNameModules as registrationNames};
@@ -37,7 +35,6 @@ function extractPluginEvents(
35 targetInst: null | Fiber,
36 nativeEvent: AnyNativeEvent,
37 nativeEventTarget: null | EventTarget,
40 - eventSystemFlags: EventSystemFlags,
38 ): Array<ReactSyntheticEvent> | ReactSyntheticEvent | null {
39 let events = null;
40 for (let i = 0; i < plugins.length; i++) {
@@ -49,7 +46,6 @@ function extractPluginEvents(
46 targetInst,
47 nativeEvent,
48 nativeEventTarget,
52 - eventSystemFlags,
49 );
50 if (extractedEvents) {
51 events = accumulateInto(events, extractedEvents);
@@ -64,14 +60,12 @@ function runExtractedPluginEventsInBatch(
60 targetInst: null | Fiber,
61 nativeEvent: AnyNativeEvent,
62 nativeEventTarget: null | EventTarget,
67 - eventSystemFlags: EventSystemFlags,
63 ) {
64 const events = extractPluginEvents(
65 topLevelType,
66 targetInst,
67 nativeEvent,
68 nativeEventTarget,
74 - eventSystemFlags,
69 );
70 runEventsInBatch(events);
71 }
@@ -99,7 +93,6 @@ export function dispatchEvent(
93 targetFiber,
94 nativeEvent,
95 eventTarget,
102 - PLUGIN_EVENT_SYSTEM,
96 );
97 });
98 // React Native doesn't use ReactControlledComponent but if it did, here's
packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js
+1 -3
@@ -8,7 +8,6 @@
8 */
9
10 import type {AnyNativeEvent} from 'legacy-events/PluginModuleType';
11 -import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
11 import type {TopLevelType} from 'legacy-events/TopLevelEventTypes';
12 import SyntheticEvent from 'legacy-events/SyntheticEvent';
13 import invariant from 'shared/invariant';
@@ -16,7 +15,7 @@ import invariant from 'shared/invariant';
15 // Module provided by RN:
16 import {ReactNativeViewConfigRegistry} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
17 import accumulateInto from 'legacy-events/accumulateInto';
19 -import getListener from 'legacy-events/getListener';
18 +import getListener from './ReactNativeGetListener';
19 import forEachAccumulated from 'legacy-events/forEachAccumulated';
20 import {HostComponent} from 'react-reconciler/src/ReactWorkTags';
21
@@ -142,7 +141,6 @@ const ReactNativeBridgeEventPlugin = {
141 targetInst: null | Object,
142 nativeEvent: AnyNativeEvent,
143 nativeEventTarget: null | Object,
145 - eventSystemFlags: EventSystemFlags,
144 ): ?Object {
145 if (targetInst == null) {
146 // Probably a node belonging to another renderer's tree.
packages/react-native-renderer/src/ReactNativeEventEmitter.js
+2 -14
@@ -8,18 +8,16 @@
8 */
9
10 import type {AnyNativeEvent} from 'legacy-events/PluginModuleType';
11 -import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
11 import type {Fiber} from 'react-reconciler/src/ReactFiber';
12 import type {PluginModule} from 'legacy-events/PluginModuleType';
13 import type {ReactSyntheticEvent} from 'legacy-events/ReactSyntheticEventType';
14 import type {TopLevelType} from 'legacy-events/TopLevelEventTypes';
15
17 -import {PLUGIN_EVENT_SYSTEM} from 'legacy-events/EventSystemFlags';
16 import {registrationNameModules} from 'legacy-events/EventPluginRegistry';
17 import {batchedUpdates} from 'legacy-events/ReactGenericBatching';
18 import {runEventsInBatch} from 'legacy-events/EventBatching';
19 import {plugins} from 'legacy-events/EventPluginRegistry';
22 -import getListener from 'legacy-events/getListener';
20 +import getListener from './ReactNativeGetListener';
21 import accumulateInto from 'legacy-events/accumulateInto';
22
23 import {getInstanceFromNode} from './ReactNativeComponentTree';
@@ -108,13 +106,7 @@ function _receiveRootNodeIDEvent(
106 }
107
108 batchedUpdates(function() {
111 - runExtractedPluginEventsInBatch(
112 - topLevelType,
113 - inst,
114 - nativeEvent,
115 - target,
116 - PLUGIN_EVENT_SYSTEM,
117 - );
109 + runExtractedPluginEventsInBatch(topLevelType, inst, nativeEvent, target);
110 });
111 // React Native doesn't use ReactControlledComponent but if it did, here's
112 // where it would do it.
@@ -132,7 +124,6 @@ function extractPluginEvents(
124 targetInst: null | Fiber,
125 nativeEvent: AnyNativeEvent,
126 nativeEventTarget: null | EventTarget,
135 - eventSystemFlags: EventSystemFlags,
127 ): Array<ReactSyntheticEvent> | ReactSyntheticEvent | null {
128 let events = null;
129 for (let i = 0; i < plugins.length; i++) {
@@ -144,7 +135,6 @@ function extractPluginEvents(
135 targetInst,
136 nativeEvent,
137 nativeEventTarget,
147 - eventSystemFlags,
138 );
139 if (extractedEvents) {
140 events = accumulateInto(events, extractedEvents);
@@ -159,14 +149,12 @@ function runExtractedPluginEventsInBatch(
149 targetInst: null | Fiber,
150 nativeEvent: AnyNativeEvent,
151 nativeEventTarget: null | EventTarget,
162 - eventSystemFlags: EventSystemFlags,
152 ) {
153 const events = extractPluginEvents(
154 topLevelType,
155 targetInst,
156 nativeEvent,
157 nativeEventTarget,
169 - eventSystemFlags,
158 );
159 runEventsInBatch(events);
160 }
packages/react-native-renderer/src/ReactNativeGetListener.js new
+36
@@ -0,0 +1,36 @@
1 +/**
2 + * Copyright (c) Facebook, Inc. and its affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + * @flow
7 + */
8 +
9 +import type {Fiber} from 'react-reconciler/src/ReactFiber';
10 +
11 +import invariant from 'shared/invariant';
12 +import {getFiberCurrentPropsFromNode} from 'legacy-events/EventPluginUtils';
13 +
14 +export default function getListener(
15 + inst: Fiber,
16 + registrationName: string,
17 +): Function | null {
18 + const stateNode = inst.stateNode;
19 + if (stateNode === null) {
20 + // Work in progress (ex: onload events in incremental mode).
21 + return null;
22 + }
23 + const props = getFiberCurrentPropsFromNode(stateNode);
24 + if (props === null) {
25 + // Work in progress.
26 + return null;
27 + }
28 + const listener = props[registrationName];
29 + invariant(
30 + !listener || typeof listener === 'function',
31 + 'Expected `%s` listener to be a function, instead got a value of `%s` type.',
32 + registrationName,
33 + typeof listener,
34 + );
35 + return listener;
36 +}