1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | 'use strict';
|
10 |
|
11 | var EventPluginHub = require('./EventPluginHub');
|
12 | var EventPluginUtils = require('./EventPluginUtils');
|
13 |
|
14 | var accumulateInto = require('./accumulateInto');
|
15 | var forEachAccumulated = require('./forEachAccumulated');
|
16 | var warning = require('fbjs/lib/warning');
|
17 |
|
18 | var getListener = EventPluginHub.getListener;
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | function listenerAtPhase(inst, event, propagationPhase) {
|
25 | var registrationName = event.dispatchConfig.phasedRegistrationNames[propagationPhase];
|
26 | return getListener(inst, registrationName);
|
27 | }
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | function accumulateDirectionalDispatches(inst, phase, event) {
|
36 | if (process.env.NODE_ENV !== 'production') {
|
37 | process.env.NODE_ENV !== 'production' ? warning(inst, 'Dispatching inst must not be null') : void 0;
|
38 | }
|
39 | var listener = listenerAtPhase(inst, event, phase);
|
40 | if (listener) {
|
41 | event._dispatchListeners = accumulateInto(event._dispatchListeners, listener);
|
42 | event._dispatchInstances = accumulateInto(event._dispatchInstances, inst);
|
43 | }
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | function accumulateTwoPhaseDispatchesSingle(event) {
|
54 | if (event && event.dispatchConfig.phasedRegistrationNames) {
|
55 | EventPluginUtils.traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event);
|
56 | }
|
57 | }
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | function accumulateTwoPhaseDispatchesSingleSkipTarget(event) {
|
63 | if (event && event.dispatchConfig.phasedRegistrationNames) {
|
64 | var targetInst = event._targetInst;
|
65 | var parentInst = targetInst ? EventPluginUtils.getParentInstance(targetInst) : null;
|
66 | EventPluginUtils.traverseTwoPhase(parentInst, accumulateDirectionalDispatches, event);
|
67 | }
|
68 | }
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | function accumulateDispatches(inst, ignoredDirection, event) {
|
76 | if (event && event.dispatchConfig.registrationName) {
|
77 | var registrationName = event.dispatchConfig.registrationName;
|
78 | var listener = getListener(inst, registrationName);
|
79 | if (listener) {
|
80 | event._dispatchListeners = accumulateInto(event._dispatchListeners, listener);
|
81 | event._dispatchInstances = accumulateInto(event._dispatchInstances, inst);
|
82 | }
|
83 | }
|
84 | }
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | function accumulateDirectDispatchesSingle(event) {
|
92 | if (event && event.dispatchConfig.registrationName) {
|
93 | accumulateDispatches(event._targetInst, null, event);
|
94 | }
|
95 | }
|
96 |
|
97 | function accumulateTwoPhaseDispatches(events) {
|
98 | forEachAccumulated(events, accumulateTwoPhaseDispatchesSingle);
|
99 | }
|
100 |
|
101 | function accumulateTwoPhaseDispatchesSkipTarget(events) {
|
102 | forEachAccumulated(events, accumulateTwoPhaseDispatchesSingleSkipTarget);
|
103 | }
|
104 |
|
105 | function accumulateEnterLeaveDispatches(leave, enter, from, to) {
|
106 | EventPluginUtils.traverseEnterLeave(from, to, accumulateDispatches, leave, enter);
|
107 | }
|
108 |
|
109 | function accumulateDirectDispatches(events) {
|
110 | forEachAccumulated(events, accumulateDirectDispatchesSingle);
|
111 | }
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | var EventPropagators = {
|
125 | accumulateTwoPhaseDispatches: accumulateTwoPhaseDispatches,
|
126 | accumulateTwoPhaseDispatchesSkipTarget: accumulateTwoPhaseDispatchesSkipTarget,
|
127 | accumulateDirectDispatches: accumulateDirectDispatches,
|
128 | accumulateEnterLeaveDispatches: accumulateEnterLeaveDispatches
|
129 | };
|
130 |
|
131 | module.exports = EventPropagators; |
\ | No newline at end of file |