6
6
* @flow
7
7
*/
8
8
9
- import { rethrowCaughtError } from 'shared/ReactErrorUtils' ;
10
9
import invariant from 'shared/invariant' ;
11
10
12
11
import {
13
12
injectEventPluginOrder ,
14
13
injectEventPluginsByName ,
15
14
plugins ,
16
15
} from './EventPluginRegistry' ;
17
- import {
18
- executeDispatchesInOrder ,
19
- getFiberCurrentPropsFromNode ,
20
- } from './EventPluginUtils' ;
16
+ import { getFiberCurrentPropsFromNode } from './EventPluginUtils' ;
21
17
import accumulateInto from './accumulateInto' ;
22
- import forEachAccumulated from './forEachAccumulated ' ;
18
+ import { runEventsInBatch } from './EventBatching ' ;
23
19
24
20
import type { PluginModule } from './PluginModuleType' ;
25
21
import type { ReactSyntheticEvent } from './ReactSyntheticEventType' ;
26
22
import type { Fiber } from 'react-reconciler/src/ReactFiber' ;
27
23
import type { AnyNativeEvent } from './PluginModuleType' ;
28
24
import type { TopLevelType } from './TopLevelEventTypes' ;
29
25
30
- /**
31
- * Internal queue of events that have accumulated their dispatches and are
32
- * waiting to have their dispatches executed.
33
- */
34
- let eventQueue : ?( Array < ReactSyntheticEvent > | ReactSyntheticEvent ) = null ;
35
-
36
- /**
37
- * Dispatches an event and releases it back into the pool, unless persistent.
38
- *
39
- * @param {?object } event Synthetic event to be dispatched.
40
- * @private
41
- */
42
- const executeDispatchesAndRelease = function ( event : ReactSyntheticEvent ) {
43
- if ( event ) {
44
- executeDispatchesInOrder ( event ) ;
45
-
46
- if ( ! event . isPersistent ( ) ) {
47
- event . constructor . release ( event ) ;
48
- }
49
- }
50
- } ;
51
- const executeDispatchesAndReleaseTopLevel = function ( e ) {
52
- return executeDispatchesAndRelease ( e ) ;
53
- } ;
54
-
55
26
function isInteractive ( tag ) {
56
27
return (
57
28
tag === 'button' ||
@@ -158,7 +129,7 @@ export function getListener(inst: Fiber, registrationName: string) {
158
129
* @return {* } An accumulation of synthetic events.
159
130
* @internal
160
131
*/
161
- function extractEvents (
132
+ function extractPluginEvents (
162
133
topLevelType : TopLevelType ,
163
134
targetInst : null | Fiber ,
164
135
nativeEvent : AnyNativeEvent ,
@@ -183,39 +154,13 @@ function extractEvents(
183
154
return events ;
184
155
}
185
156
186
- export function runEventsInBatch (
187
- events : Array < ReactSyntheticEvent > | ReactSyntheticEvent | null ,
188
- ) {
189
- if ( events !== null ) {
190
- eventQueue = accumulateInto ( eventQueue , events ) ;
191
- }
192
-
193
- // Set `eventQueue` to null before processing it so that we can tell if more
194
- // events get enqueued while processing.
195
- const processingEventQueue = eventQueue ;
196
- eventQueue = null ;
197
-
198
- if ( ! processingEventQueue ) {
199
- return ;
200
- }
201
-
202
- forEachAccumulated ( processingEventQueue , executeDispatchesAndReleaseTopLevel ) ;
203
- invariant (
204
- ! eventQueue ,
205
- 'processEventQueue(): Additional events were enqueued while processing ' +
206
- 'an event queue. Support for this has not yet been implemented.' ,
207
- ) ;
208
- // This would be a good time to rethrow if any of the event handlers threw.
209
- rethrowCaughtError ( ) ;
210
- }
211
-
212
- export function runExtractedEventsInBatch (
157
+ export function runExtractedPluginEventsInBatch (
213
158
topLevelType : TopLevelType ,
214
159
targetInst : null | Fiber ,
215
160
nativeEvent : AnyNativeEvent ,
216
161
nativeEventTarget : EventTarget ,
217
162
) {
218
- const events = extractEvents (
163
+ const events = extractPluginEvents (
219
164
topLevelType ,
220
165
targetInst ,
221
166
nativeEvent ,
0 commit comments