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