1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 | var _prodInvariant = require('./reactProdInvariant');
|
13 |
|
14 | var invariant = require('fbjs/lib/invariant');
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | var eventPluginOrder = null;
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | var namesToPlugins = {};
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | function recomputePluginOrdering() {
|
32 | if (!eventPluginOrder) {
|
33 |
|
34 | return;
|
35 | }
|
36 | for (var pluginName in namesToPlugins) {
|
37 | var pluginModule = namesToPlugins[pluginName];
|
38 | var pluginIndex = eventPluginOrder.indexOf(pluginName);
|
39 | !(pluginIndex > -1) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Cannot inject event plugins that do not exist in the plugin ordering, `%s`.', pluginName) : _prodInvariant('96', pluginName) : void 0;
|
40 | if (EventPluginRegistry.plugins[pluginIndex]) {
|
41 | continue;
|
42 | }
|
43 | !pluginModule.extractEvents ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Event plugins must implement an `extractEvents` method, but `%s` does not.', pluginName) : _prodInvariant('97', pluginName) : void 0;
|
44 | EventPluginRegistry.plugins[pluginIndex] = pluginModule;
|
45 | var publishedEvents = pluginModule.eventTypes;
|
46 | for (var eventName in publishedEvents) {
|
47 | !publishEventForPlugin(publishedEvents[eventName], pluginModule, eventName) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Failed to publish event `%s` for plugin `%s`.', eventName, pluginName) : _prodInvariant('98', eventName, pluginName) : void 0;
|
48 | }
|
49 | }
|
50 | }
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | function publishEventForPlugin(dispatchConfig, pluginModule, eventName) {
|
61 | !!EventPluginRegistry.eventNameDispatchConfigs.hasOwnProperty(eventName) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginHub: More than one plugin attempted to publish the same event name, `%s`.', eventName) : _prodInvariant('99', eventName) : void 0;
|
62 | EventPluginRegistry.eventNameDispatchConfigs[eventName] = dispatchConfig;
|
63 |
|
64 | var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
|
65 | if (phasedRegistrationNames) {
|
66 | for (var phaseName in phasedRegistrationNames) {
|
67 | if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
|
68 | var phasedRegistrationName = phasedRegistrationNames[phaseName];
|
69 | publishRegistrationName(phasedRegistrationName, pluginModule, eventName);
|
70 | }
|
71 | }
|
72 | return true;
|
73 | } else if (dispatchConfig.registrationName) {
|
74 | publishRegistrationName(dispatchConfig.registrationName, pluginModule, eventName);
|
75 | return true;
|
76 | }
|
77 | return false;
|
78 | }
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | function publishRegistrationName(registrationName, pluginModule, eventName) {
|
89 | !!EventPluginRegistry.registrationNameModules[registrationName] ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginHub: More than one plugin attempted to publish the same registration name, `%s`.', registrationName) : _prodInvariant('100', registrationName) : void 0;
|
90 | EventPluginRegistry.registrationNameModules[registrationName] = pluginModule;
|
91 | EventPluginRegistry.registrationNameDependencies[registrationName] = pluginModule.eventTypes[eventName].dependencies;
|
92 |
|
93 | if (process.env.NODE_ENV !== 'production') {
|
94 | var lowerCasedName = registrationName.toLowerCase();
|
95 | EventPluginRegistry.possibleRegistrationNames[lowerCasedName] = registrationName;
|
96 |
|
97 | if (registrationName === 'onDoubleClick') {
|
98 | EventPluginRegistry.possibleRegistrationNames.ondblclick = registrationName;
|
99 | }
|
100 | }
|
101 | }
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | var EventPluginRegistry = {
|
109 | |
110 |
|
111 |
|
112 | plugins: [],
|
113 |
|
114 | |
115 |
|
116 |
|
117 | eventNameDispatchConfigs: {},
|
118 |
|
119 | |
120 |
|
121 |
|
122 | registrationNameModules: {},
|
123 |
|
124 | |
125 |
|
126 |
|
127 | registrationNameDependencies: {},
|
128 |
|
129 | |
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 | possibleRegistrationNames: process.env.NODE_ENV !== 'production' ? {} : null,
|
136 |
|
137 |
|
138 | |
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | injectEventPluginOrder: function (injectedEventPluginOrder) {
|
148 | !!eventPluginOrder ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Cannot inject event plugin ordering more than once. You are likely trying to load more than one copy of React.') : _prodInvariant('101') : void 0;
|
149 |
|
150 | eventPluginOrder = Array.prototype.slice.call(injectedEventPluginOrder);
|
151 | recomputePluginOrdering();
|
152 | },
|
153 |
|
154 | |
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 | injectEventPluginsByName: function (injectedNamesToPlugins) {
|
165 | var isOrderingDirty = false;
|
166 | for (var pluginName in injectedNamesToPlugins) {
|
167 | if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
|
168 | continue;
|
169 | }
|
170 | var pluginModule = injectedNamesToPlugins[pluginName];
|
171 | if (!namesToPlugins.hasOwnProperty(pluginName) || namesToPlugins[pluginName] !== pluginModule) {
|
172 | !!namesToPlugins[pluginName] ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Cannot inject two different event plugins using the same name, `%s`.', pluginName) : _prodInvariant('102', pluginName) : void 0;
|
173 | namesToPlugins[pluginName] = pluginModule;
|
174 | isOrderingDirty = true;
|
175 | }
|
176 | }
|
177 | if (isOrderingDirty) {
|
178 | recomputePluginOrdering();
|
179 | }
|
180 | },
|
181 |
|
182 | |
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 | getPluginModuleForEvent: function (event) {
|
190 | var dispatchConfig = event.dispatchConfig;
|
191 | if (dispatchConfig.registrationName) {
|
192 | return EventPluginRegistry.registrationNameModules[dispatchConfig.registrationName] || null;
|
193 | }
|
194 | if (dispatchConfig.phasedRegistrationNames !== undefined) {
|
195 |
|
196 |
|
197 | var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
|
198 |
|
199 | for (var phase in phasedRegistrationNames) {
|
200 | if (!phasedRegistrationNames.hasOwnProperty(phase)) {
|
201 | continue;
|
202 | }
|
203 | var pluginModule = EventPluginRegistry.registrationNameModules[phasedRegistrationNames[phase]];
|
204 | if (pluginModule) {
|
205 | return pluginModule;
|
206 | }
|
207 | }
|
208 | }
|
209 | return null;
|
210 | },
|
211 |
|
212 | |
213 |
|
214 |
|
215 |
|
216 | _resetEventPlugins: function () {
|
217 | eventPluginOrder = null;
|
218 | for (var pluginName in namesToPlugins) {
|
219 | if (namesToPlugins.hasOwnProperty(pluginName)) {
|
220 | delete namesToPlugins[pluginName];
|
221 | }
|
222 | }
|
223 | EventPluginRegistry.plugins.length = 0;
|
224 |
|
225 | var eventNameDispatchConfigs = EventPluginRegistry.eventNameDispatchConfigs;
|
226 | for (var eventName in eventNameDispatchConfigs) {
|
227 | if (eventNameDispatchConfigs.hasOwnProperty(eventName)) {
|
228 | delete eventNameDispatchConfigs[eventName];
|
229 | }
|
230 | }
|
231 |
|
232 | var registrationNameModules = EventPluginRegistry.registrationNameModules;
|
233 | for (var registrationName in registrationNameModules) {
|
234 | if (registrationNameModules.hasOwnProperty(registrationName)) {
|
235 | delete registrationNameModules[registrationName];
|
236 | }
|
237 | }
|
238 |
|
239 | if (process.env.NODE_ENV !== 'production') {
|
240 | var possibleRegistrationNames = EventPluginRegistry.possibleRegistrationNames;
|
241 | for (var lowerCasedName in possibleRegistrationNames) {
|
242 | if (possibleRegistrationNames.hasOwnProperty(lowerCasedName)) {
|
243 | delete possibleRegistrationNames[lowerCasedName];
|
244 | }
|
245 | }
|
246 | }
|
247 | }
|
248 | };
|
249 |
|
250 | module.exports = EventPluginRegistry; |
\ | No newline at end of file |