react-test-renderer 15.5.0 → 15.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/lib/ReactShallowRenderer.js +6 -0
  2. package/lib/shallow/ARIADOMPropertyConfig.js +73 -0
  3. package/lib/shallow/AutoFocusUtils.js +23 -0
  4. package/lib/shallow/BeforeInputEventPlugin.js +384 -0
  5. package/lib/shallow/CSSProperty.js +147 -0
  6. package/lib/shallow/CSSPropertyOperations.js +208 -0
  7. package/lib/shallow/CallbackQueue.js +118 -0
  8. package/lib/shallow/ChangeEventPlugin.js +345 -0
  9. package/lib/shallow/DOMChildrenOperations.js +224 -0
  10. package/lib/shallow/DOMLazyTree.js +117 -0
  11. package/lib/shallow/DOMNamespaces.js +19 -0
  12. package/lib/shallow/DOMProperty.js +209 -0
  13. package/lib/shallow/DOMPropertyOperations.js +236 -0
  14. package/lib/shallow/Danger.js +47 -0
  15. package/lib/shallow/DefaultEventPluginOrder.js +25 -0
  16. package/lib/shallow/EnterLeaveEventPlugin.js +99 -0
  17. package/lib/shallow/EventConstants.js +91 -0
  18. package/lib/shallow/EventPluginHub.js +277 -0
  19. package/lib/shallow/EventPluginRegistry.js +254 -0
  20. package/lib/shallow/EventPluginUtils.js +225 -0
  21. package/lib/shallow/EventPropagators.js +133 -0
  22. package/lib/shallow/FallbackCompositionState.js +94 -0
  23. package/lib/shallow/HTMLDOMPropertyConfig.js +235 -0
  24. package/lib/shallow/KeyEscapeUtils.js +58 -0
  25. package/lib/shallow/LinkedValueUtils.js +137 -0
  26. package/lib/shallow/PluginModuleType.js +12 -0
  27. package/lib/shallow/PooledClass.js +111 -0
  28. package/lib/shallow/ReactBrowserEventEmitter.js +327 -0
  29. package/lib/shallow/ReactChildFiber.js +243 -0
  30. package/lib/shallow/ReactChildReconciler.js +153 -0
  31. package/lib/shallow/ReactComponentBrowserEnvironment.js +29 -0
  32. package/lib/shallow/ReactComponentEnvironment.js +45 -0
  33. package/lib/shallow/ReactCompositeComponent.js +901 -0
  34. package/lib/shallow/ReactCoroutine.js +80 -0
  35. package/lib/shallow/ReactDOM.js +110 -0
  36. package/lib/shallow/ReactDOMComponent.js +1000 -0
  37. package/lib/shallow/ReactDOMComponentFlags.js +17 -0
  38. package/lib/shallow/ReactDOMComponentTree.js +194 -0
  39. package/lib/shallow/ReactDOMContainerInfo.js +32 -0
  40. package/lib/shallow/ReactDOMEmptyComponent.js +59 -0
  41. package/lib/shallow/ReactDOMFeatureFlags.js +18 -0
  42. package/lib/shallow/ReactDOMFiber.js +97 -0
  43. package/lib/shallow/ReactDOMIDOperations.js +33 -0
  44. package/lib/shallow/ReactDOMInput.js +284 -0
  45. package/lib/shallow/ReactDOMInvalidARIAHook.js +92 -0
  46. package/lib/shallow/ReactDOMNullInputValuePropHook.js +42 -0
  47. package/lib/shallow/ReactDOMOption.js +122 -0
  48. package/lib/shallow/ReactDOMSelect.js +199 -0
  49. package/lib/shallow/ReactDOMSelection.js +211 -0
  50. package/lib/shallow/ReactDOMServer.js +25 -0
  51. package/lib/shallow/ReactDOMTextComponent.js +163 -0
  52. package/lib/shallow/ReactDOMTextarea.js +159 -0
  53. package/lib/shallow/ReactDOMTreeTraversal.js +135 -0
  54. package/lib/shallow/ReactDOMUnknownPropertyHook.js +111 -0
  55. package/lib/shallow/ReactDebugTool.js +358 -0
  56. package/lib/shallow/ReactDefaultBatchingStrategy.js +67 -0
  57. package/lib/shallow/ReactDefaultInjection.js +85 -0
  58. package/lib/shallow/ReactElementSymbol.js +19 -0
  59. package/lib/shallow/ReactEmptyComponent.js +29 -0
  60. package/lib/shallow/ReactErrorUtils.js +75 -0
  61. package/lib/shallow/ReactEventEmitterMixin.js +32 -0
  62. package/lib/shallow/ReactEventListener.js +154 -0
  63. package/lib/shallow/ReactFeatureFlags.js +21 -0
  64. package/lib/shallow/ReactFiber.js +190 -0
  65. package/lib/shallow/ReactFiberBeginWork.js +380 -0
  66. package/lib/shallow/ReactFiberCommitWork.js +78 -0
  67. package/lib/shallow/ReactFiberCompleteWork.js +208 -0
  68. package/lib/shallow/ReactFiberReconciler.js +64 -0
  69. package/lib/shallow/ReactFiberRoot.js +29 -0
  70. package/lib/shallow/ReactFiberScheduler.js +331 -0
  71. package/lib/shallow/ReactFiberUpdateQueue.js +77 -0
  72. package/lib/shallow/ReactHostComponent.js +67 -0
  73. package/lib/shallow/ReactHostOperationHistoryHook.js +33 -0
  74. package/lib/shallow/ReactInjection.js +33 -0
  75. package/lib/shallow/ReactInputSelection.js +123 -0
  76. package/lib/shallow/ReactInstanceMap.js +47 -0
  77. package/lib/shallow/ReactInstanceType.js +12 -0
  78. package/lib/shallow/ReactInstrumentation.js +23 -0
  79. package/lib/shallow/ReactInvalidSetStateWarningHook.js +36 -0
  80. package/lib/shallow/ReactMarkupChecksum.js +49 -0
  81. package/lib/shallow/ReactMount.js +537 -0
  82. package/lib/shallow/ReactMultiChild.js +449 -0
  83. package/lib/shallow/ReactMultiChildUpdateTypes.js +18 -0
  84. package/lib/shallow/ReactNodeTypes.js +39 -0
  85. package/lib/shallow/ReactOwner.js +93 -0
  86. package/lib/shallow/ReactPerf.js +500 -0
  87. package/lib/shallow/ReactPriorityLevel.js +20 -0
  88. package/lib/shallow/ReactPropTypeLocationNames.js +24 -0
  89. package/lib/shallow/ReactPropTypeLocations.js +12 -0
  90. package/lib/shallow/ReactPropTypesSecret.js +16 -0
  91. package/lib/shallow/ReactReconcileTransaction.js +177 -0
  92. package/lib/shallow/ReactReconciler.js +167 -0
  93. package/lib/shallow/ReactRef.js +88 -0
  94. package/lib/shallow/ReactReifiedYield.js +30 -0
  95. package/lib/shallow/ReactServerBatchingStrategy.js +21 -0
  96. package/lib/shallow/ReactServerRendering.js +89 -0
  97. package/lib/shallow/ReactServerRenderingTransaction.js +89 -0
  98. package/lib/shallow/ReactServerUpdateQueue.js +138 -0
  99. package/lib/shallow/ReactShallowRenderer.js +150 -0
  100. package/lib/shallow/ReactSimpleEmptyComponent.js +36 -0
  101. package/lib/shallow/ReactSyntheticEventType.js +14 -0
  102. package/lib/shallow/ReactTestEmptyComponent.js +36 -0
  103. package/lib/shallow/ReactTestMount.js +131 -0
  104. package/lib/shallow/ReactTestReconcileTransaction.js +128 -0
  105. package/lib/shallow/ReactTestRenderer.js +139 -0
  106. package/lib/shallow/ReactTestTextComponent.js +40 -0
  107. package/lib/shallow/ReactTypeOfWork.js +23 -0
  108. package/lib/shallow/ReactTypes.js +12 -0
  109. package/lib/shallow/ReactUpdateQueue.js +235 -0
  110. package/lib/shallow/ReactUpdates.js +250 -0
  111. package/lib/shallow/ReactVersion.js +13 -0
  112. package/lib/shallow/ResponderEventPlugin.js +507 -0
  113. package/lib/shallow/ResponderSyntheticEvent.js +38 -0
  114. package/lib/shallow/ResponderTouchHistoryStore.js +183 -0
  115. package/lib/shallow/SVGDOMPropertyConfig.js +301 -0
  116. package/lib/shallow/SelectEventPlugin.js +190 -0
  117. package/lib/shallow/SimpleEventPlugin.js +227 -0
  118. package/lib/shallow/SyntheticAnimationEvent.js +38 -0
  119. package/lib/shallow/SyntheticClipboardEvent.js +37 -0
  120. package/lib/shallow/SyntheticCompositionEvent.js +35 -0
  121. package/lib/shallow/SyntheticDragEvent.js +35 -0
  122. package/lib/shallow/SyntheticEvent.js +267 -0
  123. package/lib/shallow/SyntheticFocusEvent.js +35 -0
  124. package/lib/shallow/SyntheticInputEvent.js +36 -0
  125. package/lib/shallow/SyntheticKeyboardEvent.js +83 -0
  126. package/lib/shallow/SyntheticMouseEvent.js +71 -0
  127. package/lib/shallow/SyntheticTouchEvent.js +44 -0
  128. package/lib/shallow/SyntheticTransitionEvent.js +38 -0
  129. package/lib/shallow/SyntheticUIEvent.js +58 -0
  130. package/lib/shallow/SyntheticWheelEvent.js +53 -0
  131. package/lib/shallow/TapEventPlugin.js +115 -0
  132. package/lib/shallow/TouchHistoryMath.js +98 -0
  133. package/lib/shallow/Transaction.js +224 -0
  134. package/lib/shallow/ViewportMetrics.js +26 -0
  135. package/lib/shallow/accumulate.js +45 -0
  136. package/lib/shallow/accumulateInto.js +57 -0
  137. package/lib/shallow/adler32.js +43 -0
  138. package/lib/shallow/canDefineProperty.js +25 -0
  139. package/lib/shallow/checkReactTypeSpec.js +86 -0
  140. package/lib/shallow/createMicrosoftUnsafeLocalFunction.js +31 -0
  141. package/lib/shallow/dangerousStyleValue.js +78 -0
  142. package/lib/shallow/deprecated.js +56 -0
  143. package/lib/shallow/escapeTextContentForBrowser.js +122 -0
  144. package/lib/shallow/findDOMNode.js +59 -0
  145. package/lib/shallow/flattenChildren.js +75 -0
  146. package/lib/shallow/forEachAccumulated.js +30 -0
  147. package/lib/shallow/getEventCharCode.js +49 -0
  148. package/lib/shallow/getEventKey.js +101 -0
  149. package/lib/shallow/getEventModifierState.js +42 -0
  150. package/lib/shallow/getEventTarget.js +34 -0
  151. package/lib/shallow/getHostComponentFromComposite.js +29 -0
  152. package/lib/shallow/getIteratorFn.js +40 -0
  153. package/lib/shallow/getNodeForCharacterOffset.js +73 -0
  154. package/lib/shallow/getTextContentAccessor.js +32 -0
  155. package/lib/shallow/getVendorPrefixedEventName.js +100 -0
  156. package/lib/shallow/instantiateReactComponent.js +128 -0
  157. package/lib/shallow/isEventSupported.js +59 -0
  158. package/lib/shallow/isTextInputElement.js +50 -0
  159. package/lib/shallow/quoteAttributeValueForBrowser.js +25 -0
  160. package/lib/shallow/reactProdInvariant.js +38 -0
  161. package/lib/shallow/renderSubtreeIntoContainer.js +15 -0
  162. package/lib/shallow/setInnerHTML.js +97 -0
  163. package/lib/shallow/setTextContent.js +51 -0
  164. package/lib/shallow/shouldUpdateReactComponent.js +41 -0
  165. package/lib/shallow/traverseAllChildren.js +175 -0
  166. package/lib/shallow/validateDOMNesting.js +376 -0
  167. package/package.json +1 -1
  168. package/shallow.js +1 -1
@@ -0,0 +1,277 @@
1
+ /**
2
+ * Copyright 2013-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ var _prodInvariant = require('./reactProdInvariant');
14
+
15
+ var EventPluginRegistry = require('./EventPluginRegistry');
16
+ var EventPluginUtils = require('./EventPluginUtils');
17
+ var ReactErrorUtils = require('./ReactErrorUtils');
18
+
19
+ var accumulateInto = require('./accumulateInto');
20
+ var forEachAccumulated = require('./forEachAccumulated');
21
+ var invariant = require('fbjs/lib/invariant');
22
+
23
+ /**
24
+ * Internal store for event listeners
25
+ */
26
+ var listenerBank = {};
27
+
28
+ /**
29
+ * Internal queue of events that have accumulated their dispatches and are
30
+ * waiting to have their dispatches executed.
31
+ */
32
+ var eventQueue = null;
33
+
34
+ /**
35
+ * Dispatches an event and releases it back into the pool, unless persistent.
36
+ *
37
+ * @param {?object} event Synthetic event to be dispatched.
38
+ * @param {boolean} simulated If the event is simulated (changes exn behavior)
39
+ * @private
40
+ */
41
+ var executeDispatchesAndRelease = function (event, simulated) {
42
+ if (event) {
43
+ EventPluginUtils.executeDispatchesInOrder(event, simulated);
44
+
45
+ if (!event.isPersistent()) {
46
+ event.constructor.release(event);
47
+ }
48
+ }
49
+ };
50
+ var executeDispatchesAndReleaseSimulated = function (e) {
51
+ return executeDispatchesAndRelease(e, true);
52
+ };
53
+ var executeDispatchesAndReleaseTopLevel = function (e) {
54
+ return executeDispatchesAndRelease(e, false);
55
+ };
56
+
57
+ var getDictionaryKey = function (inst) {
58
+ // Prevents V8 performance issue:
59
+ // https://github.com/facebook/react/pull/7232
60
+ return '.' + inst._rootNodeID;
61
+ };
62
+
63
+ function isInteractive(tag) {
64
+ return tag === 'button' || tag === 'input' || tag === 'select' || tag === 'textarea';
65
+ }
66
+
67
+ function shouldPreventMouseEvent(name, type, props) {
68
+ switch (name) {
69
+ case 'onClick':
70
+ case 'onClickCapture':
71
+ case 'onDoubleClick':
72
+ case 'onDoubleClickCapture':
73
+ case 'onMouseDown':
74
+ case 'onMouseDownCapture':
75
+ case 'onMouseMove':
76
+ case 'onMouseMoveCapture':
77
+ case 'onMouseUp':
78
+ case 'onMouseUpCapture':
79
+ return !!(props.disabled && isInteractive(type));
80
+ default:
81
+ return false;
82
+ }
83
+ }
84
+
85
+ /**
86
+ * This is a unified interface for event plugins to be installed and configured.
87
+ *
88
+ * Event plugins can implement the following properties:
89
+ *
90
+ * `extractEvents` {function(string, DOMEventTarget, string, object): *}
91
+ * Required. When a top-level event is fired, this method is expected to
92
+ * extract synthetic events that will in turn be queued and dispatched.
93
+ *
94
+ * `eventTypes` {object}
95
+ * Optional, plugins that fire events must publish a mapping of registration
96
+ * names that are used to register listeners. Values of this mapping must
97
+ * be objects that contain `registrationName` or `phasedRegistrationNames`.
98
+ *
99
+ * `executeDispatch` {function(object, function, string)}
100
+ * Optional, allows plugins to override how an event gets dispatched. By
101
+ * default, the listener is simply invoked.
102
+ *
103
+ * Each plugin that is injected into `EventsPluginHub` is immediately operable.
104
+ *
105
+ * @public
106
+ */
107
+ var EventPluginHub = {
108
+
109
+ /**
110
+ * Methods for injecting dependencies.
111
+ */
112
+ injection: {
113
+
114
+ /**
115
+ * @param {array} InjectedEventPluginOrder
116
+ * @public
117
+ */
118
+ injectEventPluginOrder: EventPluginRegistry.injectEventPluginOrder,
119
+
120
+ /**
121
+ * @param {object} injectedNamesToPlugins Map from names to plugin modules.
122
+ */
123
+ injectEventPluginsByName: EventPluginRegistry.injectEventPluginsByName
124
+
125
+ },
126
+
127
+ /**
128
+ * Stores `listener` at `listenerBank[registrationName][key]`. Is idempotent.
129
+ *
130
+ * @param {object} inst The instance, which is the source of events.
131
+ * @param {string} registrationName Name of listener (e.g. `onClick`).
132
+ * @param {function} listener The callback to store.
133
+ */
134
+ putListener: function (inst, registrationName, listener) {
135
+ !(typeof listener === 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Expected %s listener to be a function, instead got type %s', registrationName, typeof listener) : _prodInvariant('94', registrationName, typeof listener) : void 0;
136
+
137
+ var key = getDictionaryKey(inst);
138
+ var bankForRegistrationName = listenerBank[registrationName] || (listenerBank[registrationName] = {});
139
+ bankForRegistrationName[key] = listener;
140
+
141
+ var PluginModule = EventPluginRegistry.registrationNameModules[registrationName];
142
+ if (PluginModule && PluginModule.didPutListener) {
143
+ PluginModule.didPutListener(inst, registrationName, listener);
144
+ }
145
+ },
146
+
147
+ /**
148
+ * @param {object} inst The instance, which is the source of events.
149
+ * @param {string} registrationName Name of listener (e.g. `onClick`).
150
+ * @return {?function} The stored callback.
151
+ */
152
+ getListener: function (inst, registrationName) {
153
+ // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
154
+ // live here; needs to be moved to a better place soon
155
+ var bankForRegistrationName = listenerBank[registrationName];
156
+ if (shouldPreventMouseEvent(registrationName, inst._currentElement.type, inst._currentElement.props)) {
157
+ return null;
158
+ }
159
+ var key = getDictionaryKey(inst);
160
+ return bankForRegistrationName && bankForRegistrationName[key];
161
+ },
162
+
163
+ /**
164
+ * Deletes a listener from the registration bank.
165
+ *
166
+ * @param {object} inst The instance, which is the source of events.
167
+ * @param {string} registrationName Name of listener (e.g. `onClick`).
168
+ */
169
+ deleteListener: function (inst, registrationName) {
170
+ var PluginModule = EventPluginRegistry.registrationNameModules[registrationName];
171
+ if (PluginModule && PluginModule.willDeleteListener) {
172
+ PluginModule.willDeleteListener(inst, registrationName);
173
+ }
174
+
175
+ var bankForRegistrationName = listenerBank[registrationName];
176
+ // TODO: This should never be null -- when is it?
177
+ if (bankForRegistrationName) {
178
+ var key = getDictionaryKey(inst);
179
+ delete bankForRegistrationName[key];
180
+ }
181
+ },
182
+
183
+ /**
184
+ * Deletes all listeners for the DOM element with the supplied ID.
185
+ *
186
+ * @param {object} inst The instance, which is the source of events.
187
+ */
188
+ deleteAllListeners: function (inst) {
189
+ var key = getDictionaryKey(inst);
190
+ for (var registrationName in listenerBank) {
191
+ if (!listenerBank.hasOwnProperty(registrationName)) {
192
+ continue;
193
+ }
194
+
195
+ if (!listenerBank[registrationName][key]) {
196
+ continue;
197
+ }
198
+
199
+ var PluginModule = EventPluginRegistry.registrationNameModules[registrationName];
200
+ if (PluginModule && PluginModule.willDeleteListener) {
201
+ PluginModule.willDeleteListener(inst, registrationName);
202
+ }
203
+
204
+ delete listenerBank[registrationName][key];
205
+ }
206
+ },
207
+
208
+ /**
209
+ * Allows registered plugins an opportunity to extract events from top-level
210
+ * native browser events.
211
+ *
212
+ * @return {*} An accumulation of synthetic events.
213
+ * @internal
214
+ */
215
+ extractEvents: function (topLevelType, targetInst, nativeEvent, nativeEventTarget) {
216
+ var events;
217
+ var plugins = EventPluginRegistry.plugins;
218
+ for (var i = 0; i < plugins.length; i++) {
219
+ // Not every plugin in the ordering may be loaded at runtime.
220
+ var possiblePlugin = plugins[i];
221
+ if (possiblePlugin) {
222
+ var extractedEvents = possiblePlugin.extractEvents(topLevelType, targetInst, nativeEvent, nativeEventTarget);
223
+ if (extractedEvents) {
224
+ events = accumulateInto(events, extractedEvents);
225
+ }
226
+ }
227
+ }
228
+ return events;
229
+ },
230
+
231
+ /**
232
+ * Enqueues a synthetic event that should be dispatched when
233
+ * `processEventQueue` is invoked.
234
+ *
235
+ * @param {*} events An accumulation of synthetic events.
236
+ * @internal
237
+ */
238
+ enqueueEvents: function (events) {
239
+ if (events) {
240
+ eventQueue = accumulateInto(eventQueue, events);
241
+ }
242
+ },
243
+
244
+ /**
245
+ * Dispatches all synthetic events on the event queue.
246
+ *
247
+ * @internal
248
+ */
249
+ processEventQueue: function (simulated) {
250
+ // Set `eventQueue` to null before processing it so that we can tell if more
251
+ // events get enqueued while processing.
252
+ var processingEventQueue = eventQueue;
253
+ eventQueue = null;
254
+ if (simulated) {
255
+ forEachAccumulated(processingEventQueue, executeDispatchesAndReleaseSimulated);
256
+ } else {
257
+ forEachAccumulated(processingEventQueue, executeDispatchesAndReleaseTopLevel);
258
+ }
259
+ !!eventQueue ? process.env.NODE_ENV !== 'production' ? invariant(false, 'processEventQueue(): Additional events were enqueued while processing an event queue. Support for this has not yet been implemented.') : _prodInvariant('95') : void 0;
260
+ // This would be a good time to rethrow if any of the event handlers threw.
261
+ ReactErrorUtils.rethrowCaughtError();
262
+ },
263
+
264
+ /**
265
+ * These are needed for tests only. Do not use!
266
+ */
267
+ __purge: function () {
268
+ listenerBank = {};
269
+ },
270
+
271
+ __getListenerBank: function () {
272
+ return listenerBank;
273
+ }
274
+
275
+ };
276
+
277
+ module.exports = EventPluginHub;
@@ -0,0 +1,254 @@
1
+ /**
2
+ * Copyright 2013-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ *
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ var _prodInvariant = require('./reactProdInvariant');
15
+
16
+ var invariant = require('fbjs/lib/invariant');
17
+
18
+ /**
19
+ * Injectable ordering of event plugins.
20
+ */
21
+ var eventPluginOrder = null;
22
+
23
+ /**
24
+ * Injectable mapping from names to event plugin modules.
25
+ */
26
+ var namesToPlugins = {};
27
+
28
+ /**
29
+ * Recomputes the plugin list using the injected plugins and plugin ordering.
30
+ *
31
+ * @private
32
+ */
33
+ function recomputePluginOrdering() {
34
+ if (!eventPluginOrder) {
35
+ // Wait until an `eventPluginOrder` is injected.
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
+ * Publishes an event so that it can be dispatched by the supplied plugin.
56
+ *
57
+ * @param {object} dispatchConfig Dispatch configuration for the event.
58
+ * @param {object} PluginModule Plugin publishing the event.
59
+ * @return {boolean} True if the event was successfully published.
60
+ * @private
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
+ * Publishes a registration name that is used to identify dispatched events and
84
+ * can be used with `EventPluginHub.putListener` to register listeners.
85
+ *
86
+ * @param {string} registrationName Registration name to add.
87
+ * @param {object} PluginModule Plugin publishing the event.
88
+ * @private
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
+ * Registers plugins so that they can extract and dispatch events.
107
+ *
108
+ * @see {EventPluginHub}
109
+ */
110
+ var EventPluginRegistry = {
111
+
112
+ /**
113
+ * Ordered list of injected plugins.
114
+ */
115
+ plugins: [],
116
+
117
+ /**
118
+ * Mapping from event name to dispatch config
119
+ */
120
+ eventNameDispatchConfigs: {},
121
+
122
+ /**
123
+ * Mapping from registration name to plugin module
124
+ */
125
+ registrationNameModules: {},
126
+
127
+ /**
128
+ * Mapping from registration name to event name
129
+ */
130
+ registrationNameDependencies: {},
131
+
132
+ /**
133
+ * Mapping from lowercase registration names to the properly cased version,
134
+ * used to warn in the case of missing event handlers. Available
135
+ * only in __DEV__.
136
+ * @type {Object}
137
+ */
138
+ possibleRegistrationNames: process.env.NODE_ENV !== 'production' ? {} : null,
139
+ // Trust the developer to only use possibleRegistrationNames in __DEV__
140
+
141
+ /**
142
+ * Injects an ordering of plugins (by plugin name). This allows the ordering
143
+ * to be decoupled from injection of the actual plugins so that ordering is
144
+ * always deterministic regardless of packaging, on-the-fly injection, etc.
145
+ *
146
+ * @param {array} InjectedEventPluginOrder
147
+ * @internal
148
+ * @see {EventPluginHub.injection.injectEventPluginOrder}
149
+ */
150
+ injectEventPluginOrder: function (injectedEventPluginOrder) {
151
+ !!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;
152
+ // Clone the ordering so it cannot be dynamically mutated.
153
+ eventPluginOrder = Array.prototype.slice.call(injectedEventPluginOrder);
154
+ recomputePluginOrdering();
155
+ },
156
+
157
+ /**
158
+ * Injects plugins to be used by `EventPluginHub`. The plugin names must be
159
+ * in the ordering injected by `injectEventPluginOrder`.
160
+ *
161
+ * Plugins can be injected as part of page initialization or on-the-fly.
162
+ *
163
+ * @param {object} injectedNamesToPlugins Map from names to plugin modules.
164
+ * @internal
165
+ * @see {EventPluginHub.injection.injectEventPluginsByName}
166
+ */
167
+ injectEventPluginsByName: function (injectedNamesToPlugins) {
168
+ var isOrderingDirty = false;
169
+ for (var pluginName in injectedNamesToPlugins) {
170
+ if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
171
+ continue;
172
+ }
173
+ var pluginModule = injectedNamesToPlugins[pluginName];
174
+ if (!namesToPlugins.hasOwnProperty(pluginName) || namesToPlugins[pluginName] !== pluginModule) {
175
+ !!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;
176
+ namesToPlugins[pluginName] = pluginModule;
177
+ isOrderingDirty = true;
178
+ }
179
+ }
180
+ if (isOrderingDirty) {
181
+ recomputePluginOrdering();
182
+ }
183
+ },
184
+
185
+ /**
186
+ * Looks up the plugin for the supplied event.
187
+ *
188
+ * @param {object} event A synthetic event.
189
+ * @return {?object} The plugin that created the supplied event.
190
+ * @internal
191
+ */
192
+ getPluginModuleForEvent: function (event) {
193
+ var dispatchConfig = event.dispatchConfig;
194
+ if (dispatchConfig.registrationName) {
195
+ return EventPluginRegistry.registrationNameModules[dispatchConfig.registrationName] || null;
196
+ }
197
+ if (dispatchConfig.phasedRegistrationNames !== undefined) {
198
+ // pulling phasedRegistrationNames out of dispatchConfig helps Flow see
199
+ // that it is not undefined.
200
+ var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
201
+
202
+ for (var phase in phasedRegistrationNames) {
203
+ if (!phasedRegistrationNames.hasOwnProperty(phase)) {
204
+ continue;
205
+ }
206
+ var pluginModule = EventPluginRegistry.registrationNameModules[phasedRegistrationNames[phase]];
207
+ if (pluginModule) {
208
+ return pluginModule;
209
+ }
210
+ }
211
+ }
212
+ return null;
213
+ },
214
+
215
+ /**
216
+ * Exposed for unit testing.
217
+ * @private
218
+ */
219
+ _resetEventPlugins: function () {
220
+ eventPluginOrder = null;
221
+ for (var pluginName in namesToPlugins) {
222
+ if (namesToPlugins.hasOwnProperty(pluginName)) {
223
+ delete namesToPlugins[pluginName];
224
+ }
225
+ }
226
+ EventPluginRegistry.plugins.length = 0;
227
+
228
+ var eventNameDispatchConfigs = EventPluginRegistry.eventNameDispatchConfigs;
229
+ for (var eventName in eventNameDispatchConfigs) {
230
+ if (eventNameDispatchConfigs.hasOwnProperty(eventName)) {
231
+ delete eventNameDispatchConfigs[eventName];
232
+ }
233
+ }
234
+
235
+ var registrationNameModules = EventPluginRegistry.registrationNameModules;
236
+ for (var registrationName in registrationNameModules) {
237
+ if (registrationNameModules.hasOwnProperty(registrationName)) {
238
+ delete registrationNameModules[registrationName];
239
+ }
240
+ }
241
+
242
+ if (process.env.NODE_ENV !== 'production') {
243
+ var possibleRegistrationNames = EventPluginRegistry.possibleRegistrationNames;
244
+ for (var lowerCasedName in possibleRegistrationNames) {
245
+ if (possibleRegistrationNames.hasOwnProperty(lowerCasedName)) {
246
+ delete possibleRegistrationNames[lowerCasedName];
247
+ }
248
+ }
249
+ }
250
+ }
251
+
252
+ };
253
+
254
+ module.exports = EventPluginRegistry;