3
3
*
4
4
* This source code is licensed under the MIT license found in the
5
5
* LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow
6
8
*/
7
9
8
- import {
9
- getParentInstance ,
10
- traverseTwoPhase ,
11
- traverseEnterLeave ,
12
- } from 'shared/ReactTreeTraversal' ;
10
+ import type { Fiber } from 'react-reconciler/src/ReactFiber' ;
11
+ import type { ReactSyntheticEvent } from 'legacy-events/ReactSyntheticEventType' ;
13
12
14
13
import getListener from 'legacy-events/getListener' ;
14
+
15
+ import { traverseEnterLeave } from 'shared/ReactTreeTraversal' ;
15
16
import accumulateInto from './accumulateInto' ;
16
17
import forEachAccumulated from './forEachAccumulated' ;
17
18
18
- type PropagationPhases = 'bubbled' | 'captured' ;
19
-
20
- /**
21
- * Some event types have a notion of different registration names for different
22
- * "phases" of propagation. This finds listeners by a given phase.
23
- */
24
- function listenerAtPhase ( inst , event , propagationPhase : PropagationPhases ) {
25
- const registrationName =
26
- event . dispatchConfig . phasedRegistrationNames [ propagationPhase ] ;
27
- return getListener ( inst , registrationName ) ;
28
- }
29
-
30
19
/**
31
20
* A small set of propagation patterns, each of which will accept a small amount
32
21
* of information, and generate a set of "dispatch ready event objects" - which
@@ -37,58 +26,16 @@ function listenerAtPhase(inst, event, propagationPhase: PropagationPhases) {
37
26
* single one.
38
27
*/
39
28
40
- /**
41
- * Tags a `SyntheticEvent` with dispatched listeners. Creating this function
42
- * here, allows us to not have to bind or create functions for each event.
43
- * Mutating the event's members allows us to not have to create a wrapping
44
- * "dispatch" object that pairs the event with the listener.
45
- */
46
- function accumulateDirectionalDispatches ( inst , phase , event ) {
47
- if ( __DEV__ ) {
48
- if ( ! inst ) {
49
- console . error ( 'Dispatching inst must not be null' ) ;
50
- }
51
- }
52
- const listener = listenerAtPhase ( inst , event , phase ) ;
53
- if ( listener ) {
54
- event . _dispatchListeners = accumulateInto (
55
- event . _dispatchListeners ,
56
- listener ,
57
- ) ;
58
- event . _dispatchInstances = accumulateInto ( event . _dispatchInstances , inst ) ;
59
- }
60
- }
61
-
62
- /**
63
- * Collect dispatches (must be entirely collected before dispatching - see unit
64
- * tests). Lazily allocate the array to conserve memory. We must loop through
65
- * each event and perform the traversal for each one. We cannot perform a
66
- * single traversal for the entire collection of events because each event may
67
- * have a different target.
68
- */
69
- export function accumulateTwoPhaseDispatchesSingle ( event ) {
70
- if ( event && event . dispatchConfig . phasedRegistrationNames ) {
71
- traverseTwoPhase ( event . _targetInst , accumulateDirectionalDispatches , event ) ;
72
- }
73
- }
74
-
75
- /**
76
- * Same as `accumulateTwoPhaseDispatchesSingle`, but skips over the targetID.
77
- */
78
- function accumulateTwoPhaseDispatchesSingleSkipTarget ( event ) {
79
- if ( event && event . dispatchConfig . phasedRegistrationNames ) {
80
- const targetInst = event . _targetInst ;
81
- const parentInst = targetInst ? getParentInstance ( targetInst ) : null ;
82
- traverseTwoPhase ( parentInst , accumulateDirectionalDispatches , event ) ;
83
- }
84
- }
85
-
86
29
/**
87
30
* Accumulates without regard to direction, does not look for phased
88
31
* registration names. Same as `accumulateDirectDispatchesSingle` but without
89
32
* requiring that the `dispatchMarker` be the same as the dispatched ID.
90
33
*/
91
- function accumulateDispatches ( inst , ignoredDirection , event ) {
34
+ function accumulateDispatches (
35
+ inst : Fiber ,
36
+ ignoredDirection : ?boolean ,
37
+ event : ReactSyntheticEvent ,
38
+ ) : void {
92
39
if ( inst && event && event . dispatchConfig . registrationName ) {
93
40
const registrationName = event . dispatchConfig . registrationName ;
94
41
const listener = getListener ( inst , registrationName ) ;
@@ -107,24 +54,23 @@ function accumulateDispatches(inst, ignoredDirection, event) {
107
54
* `dispatchMarker`.
108
55
* @param {SyntheticEvent } event
109
56
*/
110
- function accumulateDirectDispatchesSingle ( event ) {
57
+ function accumulateDirectDispatchesSingle ( event : ReactSyntheticEvent ) {
111
58
if ( event && event . dispatchConfig . registrationName ) {
112
59
accumulateDispatches ( event . _targetInst , null , event ) ;
113
60
}
114
61
}
115
62
116
- export function accumulateTwoPhaseDispatches ( events ) {
117
- forEachAccumulated ( events , accumulateTwoPhaseDispatchesSingle ) ;
118
- }
119
-
120
- export function accumulateTwoPhaseDispatchesSkipTarget ( events ) {
121
- forEachAccumulated ( events , accumulateTwoPhaseDispatchesSingleSkipTarget ) ;
122
- }
123
-
124
- export function accumulateEnterLeaveDispatches ( leave , enter , from , to ) {
63
+ export function accumulateEnterLeaveDispatches (
64
+ leave : ReactSyntheticEvent ,
65
+ enter : ReactSyntheticEvent ,
66
+ from : Fiber ,
67
+ to : Fiber ,
68
+ ) {
125
69
traverseEnterLeave ( from , to , accumulateDispatches , leave , enter ) ;
126
70
}
127
71
128
- export function accumulateDirectDispatches ( events ) {
72
+ export function accumulateDirectDispatches (
73
+ events : ?( Array < ReactSyntheticEvent > | ReactSyntheticEvent ) ,
74
+ ) {
129
75
forEachAccumulated ( events , accumulateDirectDispatchesSingle ) ;
130
76
}
0 commit comments