MCPcopy Index your code
hub / github.com/react/react / dispatchEvent

Function dispatchEvent

packages/react-native-renderer/src/ReactFabricEventEmitter.js:84–139  ·  view source on GitHub ↗
(
  target: null | Object,
  topLevelType: RNTopLevelEventType,
  nativeEvent: AnyNativeEvent,
)

Source from the content-addressed store, hash-verified

82}
83
84export function dispatchEvent(
85 target: null | Object,
86 topLevelType: RNTopLevelEventType,
87 nativeEvent: AnyNativeEvent,
88) {
89 const targetFiber = (target: null | Fiber);
90
91 let eventTarget = null;
92 if (targetFiber != null) {
93 const stateNode = targetFiber.stateNode;
94 // Guard against Fiber being unmounted
95 if (stateNode != null) {
96 // $FlowExpectedError[incompatible-cast] public instances in Fabric do not implement `EventTarget` yet.
97 eventTarget = (getPublicInstance(stateNode): EventTarget);
98 }
99 }
100
101 batchedUpdates(function () {
102 // Emit event to the RawEventEmitter. This is an unused-by-default EventEmitter
103 // that can be used to instrument event performance monitoring (primarily - could be useful
104 // for other things too).
105 //
106 // NOTE: this merely emits events into the EventEmitter below.
107 // If *you* do not add listeners to the `RawEventEmitter`,
108 // then all of these emitted events will just blackhole and are no-ops.
109 // It is available (although not officially supported... yet) if you want to collect
110 // perf data on event latency in your application, and could also be useful for debugging
111 // low-level events issues.
112 //
113 // If you do not have any event perf monitoring and are extremely concerned about event perf,
114 // it is safe to disable these "emit" statements; it will prevent checking the size of
115 // an empty array twice and prevent two no-ops. Practically the overhead is so low that
116 // we don't think it's worth thinking about in prod; your perf issues probably lie elsewhere.
117 //
118 // We emit two events here: one for listeners to this specific event,
119 // and one for the catchall listener '*', for any listeners that want
120 // to be notified for all events.
121 // Note that extracted events are *not* emitted,
122 // only events that have a 1:1 mapping with a native event, at least for now.
123 const event = {eventName: topLevelType, nativeEvent};
124 // $FlowFixMe[class-object-subtyping] found when upgrading Flow
125 RawEventEmitter.emit(topLevelType, event);
126 // $FlowFixMe[class-object-subtyping] found when upgrading Flow
127 RawEventEmitter.emit('*', event);
128
129 // Heritage plugin event system
130 runExtractedPluginEventsInBatch(
131 topLevelType,
132 targetFiber,
133 nativeEvent,
134 eventTarget,
135 );
136 });
137 // React Native doesn't use ReactControlledComponent but if it did, here's
138 // where it would do it.
139}

Callers 1

Calls 4

getPublicInstanceFunction · 0.90
batchedUpdatesFunction · 0.90
emitMethod · 0.45

Tested by

no test coverage detected