react 0.7.0 → 0.9.0

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 (217) hide show
  1. package/README.md +10 -231
  2. package/addons.js +1 -0
  3. package/lib/AutoFocusMixin.js +30 -0
  4. package/lib/CSSCore.js +115 -0
  5. package/lib/CSSProperty.js +121 -0
  6. package/lib/CSSPropertyOperations.js +97 -0
  7. package/lib/ChangeEventPlugin.js +387 -0
  8. package/lib/ClientReactRootIndex.js +30 -0
  9. package/lib/CompositionEventPlugin.js +260 -0
  10. package/lib/DOMChildrenOperations.js +165 -0
  11. package/lib/DOMProperty.js +268 -0
  12. package/lib/DOMPropertyOperations.js +181 -0
  13. package/lib/Danger.js +187 -0
  14. package/lib/DefaultDOMPropertyConfig.js +203 -0
  15. package/lib/DefaultEventPluginOrder.js +44 -0
  16. package/lib/EnterLeaveEventPlugin.js +145 -0
  17. package/lib/EventConstants.js +76 -0
  18. package/lib/EventListener.js +69 -0
  19. package/lib/EventPluginHub.js +293 -0
  20. package/lib/EventPluginRegistry.js +281 -0
  21. package/lib/EventPluginUtils.js +214 -0
  22. package/lib/EventPropagators.js +143 -0
  23. package/lib/ExecutionEnvironment.js +44 -0
  24. package/lib/LinkedStateMixin.js +46 -0
  25. package/lib/LinkedValueUtils.js +161 -0
  26. package/lib/MobileSafariClickEventPlugin.js +63 -0
  27. package/lib/PooledClass.js +119 -0
  28. package/lib/React.js +95 -0
  29. package/lib/ReactCSSTransitionGroup.js +65 -0
  30. package/lib/ReactCSSTransitionGroupChild.js +138 -0
  31. package/lib/ReactChildren.js +132 -0
  32. package/lib/ReactComponent.js +550 -0
  33. package/lib/ReactComponentBrowserEnvironment.js +158 -0
  34. package/lib/ReactComponentEnvironment.js +26 -0
  35. package/lib/ReactCompositeComponent.js +1455 -0
  36. package/lib/ReactContext.js +67 -0
  37. package/lib/ReactCurrentOwner.js +39 -0
  38. package/lib/ReactDOM.js +207 -0
  39. package/lib/ReactDOMButton.js +68 -0
  40. package/lib/ReactDOMComponent.js +399 -0
  41. package/lib/ReactDOMForm.js +59 -0
  42. package/lib/ReactDOMIDOperations.js +218 -0
  43. package/lib/ReactDOMImg.js +58 -0
  44. package/lib/ReactDOMInput.js +181 -0
  45. package/lib/ReactDOMOption.js +51 -0
  46. package/lib/ReactDOMSelect.js +179 -0
  47. package/lib/ReactDOMSelection.js +189 -0
  48. package/lib/ReactDOMTextarea.js +140 -0
  49. package/lib/ReactDefaultBatchingStrategy.js +75 -0
  50. package/lib/ReactDefaultInjection.js +115 -0
  51. package/lib/ReactDefaultPerf.js +244 -0
  52. package/lib/ReactDefaultPerfAnalysis.js +199 -0
  53. package/lib/ReactErrorUtils.js +37 -0
  54. package/lib/ReactEventEmitter.js +339 -0
  55. package/lib/ReactEventEmitterMixin.js +57 -0
  56. package/lib/ReactEventTopLevelCallback.js +149 -0
  57. package/lib/ReactInjection.js +39 -0
  58. package/lib/ReactInputSelection.js +140 -0
  59. package/lib/ReactInstanceHandles.js +338 -0
  60. package/lib/ReactLink.js +54 -0
  61. package/lib/ReactMarkupChecksum.js +53 -0
  62. package/lib/ReactMount.js +641 -0
  63. package/lib/ReactMountReady.js +95 -0
  64. package/lib/ReactMultiChild.js +425 -0
  65. package/lib/ReactMultiChildUpdateTypes.js +38 -0
  66. package/lib/ReactOwner.js +154 -0
  67. package/lib/ReactPerf.js +85 -0
  68. package/lib/ReactPropTransferer.js +147 -0
  69. package/lib/ReactPropTypeLocationNames.js +31 -0
  70. package/lib/ReactPropTypeLocations.js +29 -0
  71. package/lib/ReactPropTypes.js +359 -0
  72. package/lib/ReactPutListenerQueue.js +61 -0
  73. package/lib/ReactReconcileTransaction.js +181 -0
  74. package/lib/ReactRootIndex.js +36 -0
  75. package/lib/ReactServerRendering.js +59 -0
  76. package/lib/ReactStateSetters.js +111 -0
  77. package/lib/ReactTestUtils.js +394 -0
  78. package/lib/ReactTextComponent.js +99 -0
  79. package/lib/ReactTransitionChildMapping.js +106 -0
  80. package/lib/ReactTransitionEvents.js +97 -0
  81. package/lib/ReactTransitionGroup.js +187 -0
  82. package/lib/ReactUpdates.js +148 -0
  83. package/lib/ReactWithAddons.js +51 -0
  84. package/lib/SelectEventPlugin.js +200 -0
  85. package/lib/ServerReactRootIndex.js +36 -0
  86. package/lib/SimpleEventPlugin.js +413 -0
  87. package/lib/SyntheticClipboardEvent.js +51 -0
  88. package/lib/SyntheticCompositionEvent.js +51 -0
  89. package/lib/SyntheticDragEvent.js +44 -0
  90. package/lib/SyntheticEvent.js +164 -0
  91. package/lib/SyntheticFocusEvent.js +44 -0
  92. package/lib/SyntheticKeyboardEvent.js +58 -0
  93. package/lib/SyntheticMouseEvent.js +85 -0
  94. package/lib/SyntheticTouchEvent.js +50 -0
  95. package/lib/SyntheticUIEvent.js +45 -0
  96. package/lib/SyntheticWheelEvent.js +66 -0
  97. package/lib/Transaction.js +276 -0
  98. package/lib/ViewportMetrics.js +37 -0
  99. package/lib/accumulate.js +54 -0
  100. package/lib/adler32.js +39 -0
  101. package/lib/cloneWithProps.js +59 -0
  102. package/lib/containsNode.js +49 -0
  103. package/lib/copyProperties.js +54 -0
  104. package/lib/createArrayFrom.js +91 -0
  105. package/lib/createFullPageComponent.js +63 -0
  106. package/lib/createNodesFromMarkup.js +93 -0
  107. package/lib/createObjectFrom.js +61 -0
  108. package/lib/cx.js +44 -0
  109. package/lib/dangerousStyleValue.js +57 -0
  110. package/lib/emptyFunction.js +43 -0
  111. package/lib/escapeTextForBrowser.js +47 -0
  112. package/lib/flattenChildren.js +57 -0
  113. package/lib/forEachAccumulated.js +36 -0
  114. package/lib/getActiveElement.js +34 -0
  115. package/lib/getEventKey.js +85 -0
  116. package/lib/getEventTarget.js +36 -0
  117. package/lib/getMarkupWrap.js +118 -0
  118. package/lib/getNodeForCharacterOffset.js +80 -0
  119. package/lib/getReactRootElementInContainer.js +40 -0
  120. package/lib/getTextContentAccessor.js +42 -0
  121. package/lib/getUnboundedScrollPosition.js +45 -0
  122. package/lib/hyphenate.js +35 -0
  123. package/lib/invariant.js +62 -0
  124. package/lib/isEventSupported.js +70 -0
  125. package/lib/isNode.js +33 -0
  126. package/lib/isTextInputElement.js +49 -0
  127. package/lib/isTextNode.js +30 -0
  128. package/lib/joinClasses.js +44 -0
  129. package/lib/keyMirror.js +58 -0
  130. package/lib/keyOf.js +41 -0
  131. package/lib/memoizeStringOnly.js +39 -0
  132. package/lib/merge.js +37 -0
  133. package/lib/mergeHelpers.js +136 -0
  134. package/lib/mergeInto.js +45 -0
  135. package/lib/mixInto.js +34 -0
  136. package/lib/objMap.js +47 -0
  137. package/lib/objMapKeyVal.js +47 -0
  138. package/lib/onlyChild.js +43 -0
  139. package/lib/performanceNow.js +42 -0
  140. package/lib/shallowEqual.js +49 -0
  141. package/lib/shouldUpdateReactComponent.js +58 -0
  142. package/lib/toArray.js +75 -0
  143. package/lib/traverseAllChildren.js +189 -0
  144. package/lib/warning.js +48 -0
  145. package/package.json +33 -21
  146. package/react.js +1 -0
  147. package/.npmignore +0 -7
  148. package/.travis.yml +0 -7
  149. package/Jakefile.js +0 -39
  150. package/LICENSE +0 -19
  151. package/browser-test/dist.html +0 -90
  152. package/browser-test/index.html +0 -86
  153. package/browser-test/min.html +0 -90
  154. package/dist/react.js +0 -3141
  155. package/dist/react.min.js +0 -22
  156. package/doc/advanced.md +0 -174
  157. package/doc/color-def.graffle +0 -938
  158. package/doc/color-def.png +0 -0
  159. package/doc/simple.dot +0 -25
  160. package/doc/simple.png +0 -0
  161. package/examples/longer-example.js +0 -41
  162. package/examples/simple.js +0 -45
  163. package/examples/using-ast-directly.js +0 -30
  164. package/examples/using-events1.js +0 -79
  165. package/examples/using-log-events.js +0 -43
  166. package/lib/base-task.js +0 -120
  167. package/lib/cb-task.js +0 -84
  168. package/lib/core.js +0 -138
  169. package/lib/dsl.js +0 -138
  170. package/lib/error.js +0 -55
  171. package/lib/event-collector.js +0 -81
  172. package/lib/event-manager.js +0 -89
  173. package/lib/eventemitter.js +0 -20
  174. package/lib/finalcb-first-task.js +0 -68
  175. package/lib/finalcb-task.js +0 -65
  176. package/lib/id.js +0 -22
  177. package/lib/input-parser.js +0 -56
  178. package/lib/log-events.js +0 -101
  179. package/lib/parse.js +0 -41
  180. package/lib/promise-resolve.js +0 -50
  181. package/lib/promise-task.js +0 -93
  182. package/lib/react.js +0 -59
  183. package/lib/ret-task.js +0 -71
  184. package/lib/sprintf.js +0 -18
  185. package/lib/status.js +0 -14
  186. package/lib/task.js +0 -251
  187. package/lib/track-tasks.js +0 -74
  188. package/lib/validate.js +0 -159
  189. package/lib/vcon.js +0 -113
  190. package/lib/when-task.js +0 -84
  191. package/src/dist.build.requirejs +0 -20
  192. package/test/ast.mocha.js +0 -136
  193. package/test/cb-task.mocha.js +0 -220
  194. package/test/core-deferred.mocha.js +0 -143
  195. package/test/core-when.mocha.js +0 -96
  196. package/test/core.mocha.js +0 -589
  197. package/test/dsl.mocha.js +0 -352
  198. package/test/event-manager.mocha.js +0 -119
  199. package/test/exec-options.mocha.js +0 -48
  200. package/test/finalcb-task.mocha.js +0 -58
  201. package/test/input-parser.mocha.js +0 -86
  202. package/test/log-events.mocha.js +0 -88
  203. package/test/mocha.opts +0 -2
  204. package/test/module-use.mocha.js +0 -164
  205. package/test/promise-auto-resolve.mocha.js +0 -68
  206. package/test/ret-task.mocha.js +0 -220
  207. package/test/task.mocha.js +0 -42
  208. package/test/validate-cb-task.mocha.js +0 -100
  209. package/test/validate-ret-task.mocha.js +0 -110
  210. package/test/validate.mocha.js +0 -324
  211. package/test/vcon.mocha.js +0 -193
  212. package/vendor/chai/chai.js +0 -4251
  213. package/vendor/jquery/jquery-1.7.1.js +0 -9266
  214. package/vendor/jquery/jquery-1.7.1.min.js +0 -4
  215. package/vendor/node/util.js +0 -531
  216. package/vendor/requirejs/require.js +0 -2045
  217. package/vendor/requirejs/require.min.js +0 -36
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @providesModule EventListener
3
+ */
4
+
5
+ var emptyFunction = require("./emptyFunction");
6
+
7
+ /**
8
+ * Upstream version of event listener. Does not take into account specific
9
+ * nature of platform.
10
+ */
11
+ var EventListener = {
12
+ /**
13
+ * Listen to DOM events during the bubble phase.
14
+ *
15
+ * @param {DOMEventTarget} target DOM element to register listener on.
16
+ * @param {string} eventType Event type, e.g. 'click' or 'mouseover'.
17
+ * @param {function} callback Callback function.
18
+ * @return {object} Object with a `remove` method.
19
+ */
20
+ listen: function(target, eventType, callback) {
21
+ if (target.addEventListener) {
22
+ target.addEventListener(eventType, callback, false);
23
+ return {
24
+ remove: function() {
25
+ target.removeEventListener(eventType, callback, false);
26
+ }
27
+ };
28
+ } else if (target.attachEvent) {
29
+ target.attachEvent('on' + eventType, callback);
30
+ return {
31
+ remove: function() {
32
+ target.detachEvent(eventType, callback);
33
+ }
34
+ };
35
+ }
36
+ },
37
+
38
+ /**
39
+ * Listen to DOM events during the capture phase.
40
+ *
41
+ * @param {DOMEventTarget} target DOM element to register listener on.
42
+ * @param {string} eventType Event type, e.g. 'click' or 'mouseover'.
43
+ * @param {function} callback Callback function.
44
+ * @return {object} Object with a `remove` method.
45
+ */
46
+ capture: function(target, eventType, callback) {
47
+ if (!target.addEventListener) {
48
+ if ("production" !== process.env.NODE_ENV) {
49
+ console.error(
50
+ 'Attempted to listen to events during the capture phase on a ' +
51
+ 'browser that does not support the capture phase. Your application ' +
52
+ 'will not receive some events.'
53
+ );
54
+ }
55
+ return {
56
+ remove: emptyFunction
57
+ };
58
+ } else {
59
+ target.addEventListener(eventType, callback, true);
60
+ return {
61
+ remove: function() {
62
+ target.removeEventListener(eventType, callback, true);
63
+ }
64
+ };
65
+ }
66
+ }
67
+ };
68
+
69
+ module.exports = EventListener;
@@ -0,0 +1,293 @@
1
+ /**
2
+ * Copyright 2013-2014 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule EventPluginHub
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var EventPluginRegistry = require("./EventPluginRegistry");
22
+ var EventPluginUtils = require("./EventPluginUtils");
23
+ var ExecutionEnvironment = require("./ExecutionEnvironment");
24
+
25
+ var accumulate = require("./accumulate");
26
+ var forEachAccumulated = require("./forEachAccumulated");
27
+ var invariant = require("./invariant");
28
+ var isEventSupported = require("./isEventSupported");
29
+
30
+ /**
31
+ * Internal store for event listeners
32
+ */
33
+ var listenerBank = {};
34
+
35
+ /**
36
+ * Internal queue of events that have accumulated their dispatches and are
37
+ * waiting to have their dispatches executed.
38
+ */
39
+ var eventQueue = null;
40
+
41
+ /**
42
+ * Dispatches an event and releases it back into the pool, unless persistent.
43
+ *
44
+ * @param {?object} event Synthetic event to be dispatched.
45
+ * @private
46
+ */
47
+ var executeDispatchesAndRelease = function(event) {
48
+ if (event) {
49
+ var executeDispatch = EventPluginUtils.executeDispatch;
50
+ // Plugins can provide custom behavior when dispatching events.
51
+ var PluginModule = EventPluginRegistry.getPluginModuleForEvent(event);
52
+ if (PluginModule && PluginModule.executeDispatch) {
53
+ executeDispatch = PluginModule.executeDispatch;
54
+ }
55
+ EventPluginUtils.executeDispatchesInOrder(event, executeDispatch);
56
+
57
+ if (!event.isPersistent()) {
58
+ event.constructor.release(event);
59
+ }
60
+ }
61
+ };
62
+
63
+ /**
64
+ * - `InstanceHandle`: [required] Module that performs logical traversals of DOM
65
+ * hierarchy given ids of the logical DOM elements involved.
66
+ */
67
+ var InstanceHandle = null;
68
+
69
+ function validateInstanceHandle() {
70
+ var invalid = !InstanceHandle||
71
+ !InstanceHandle.traverseTwoPhase ||
72
+ !InstanceHandle.traverseEnterLeave;
73
+ if (invalid) {
74
+ throw new Error('InstanceHandle not injected before use!');
75
+ }
76
+ }
77
+
78
+ /**
79
+ * This is a unified interface for event plugins to be installed and configured.
80
+ *
81
+ * Event plugins can implement the following properties:
82
+ *
83
+ * `extractEvents` {function(string, DOMEventTarget, string, object): *}
84
+ * Required. When a top-level event is fired, this method is expected to
85
+ * extract synthetic events that will in turn be queued and dispatched.
86
+ *
87
+ * `eventTypes` {object}
88
+ * Optional, plugins that fire events must publish a mapping of registration
89
+ * names that are used to register listeners. Values of this mapping must
90
+ * be objects that contain `registrationName` or `phasedRegistrationNames`.
91
+ *
92
+ * `executeDispatch` {function(object, function, string)}
93
+ * Optional, allows plugins to override how an event gets dispatched. By
94
+ * default, the listener is simply invoked.
95
+ *
96
+ * Each plugin that is injected into `EventsPluginHub` is immediately operable.
97
+ *
98
+ * @public
99
+ */
100
+ var EventPluginHub = {
101
+
102
+ /**
103
+ * Methods for injecting dependencies.
104
+ */
105
+ injection: {
106
+
107
+ /**
108
+ * @param {object} InjectedMount
109
+ * @public
110
+ */
111
+ injectMount: EventPluginUtils.injection.injectMount,
112
+
113
+ /**
114
+ * @param {object} InjectedInstanceHandle
115
+ * @public
116
+ */
117
+ injectInstanceHandle: function(InjectedInstanceHandle) {
118
+ InstanceHandle = InjectedInstanceHandle;
119
+ if ("production" !== process.env.NODE_ENV) {
120
+ validateInstanceHandle();
121
+ }
122
+ },
123
+
124
+ getInstanceHandle: function() {
125
+ if ("production" !== process.env.NODE_ENV) {
126
+ validateInstanceHandle();
127
+ }
128
+ return InstanceHandle;
129
+ },
130
+
131
+ /**
132
+ * @param {array} InjectedEventPluginOrder
133
+ * @public
134
+ */
135
+ injectEventPluginOrder: EventPluginRegistry.injectEventPluginOrder,
136
+
137
+ /**
138
+ * @param {object} injectedNamesToPlugins Map from names to plugin modules.
139
+ */
140
+ injectEventPluginsByName: EventPluginRegistry.injectEventPluginsByName
141
+
142
+ },
143
+
144
+ eventNameDispatchConfigs: EventPluginRegistry.eventNameDispatchConfigs,
145
+
146
+ registrationNameModules: EventPluginRegistry.registrationNameModules,
147
+
148
+ /**
149
+ * Stores `listener` at `listenerBank[registrationName][id]`. Is idempotent.
150
+ *
151
+ * @param {string} id ID of the DOM element.
152
+ * @param {string} registrationName Name of listener (e.g. `onClick`).
153
+ * @param {?function} listener The callback to store.
154
+ */
155
+ putListener: function(id, registrationName, listener) {
156
+ ("production" !== process.env.NODE_ENV ? invariant(
157
+ ExecutionEnvironment.canUseDOM,
158
+ 'Cannot call putListener() in a non-DOM environment.'
159
+ ) : invariant(ExecutionEnvironment.canUseDOM));
160
+ ("production" !== process.env.NODE_ENV ? invariant(
161
+ !listener || typeof listener === 'function',
162
+ 'Expected %s listener to be a function, instead got type %s',
163
+ registrationName, typeof listener
164
+ ) : invariant(!listener || typeof listener === 'function'));
165
+
166
+ if ("production" !== process.env.NODE_ENV) {
167
+ // IE8 has no API for event capturing and the `onScroll` event doesn't
168
+ // bubble.
169
+ if (registrationName === 'onScroll' &&
170
+ !isEventSupported('scroll', true)) {
171
+ console.warn('This browser doesn\'t support the `onScroll` event');
172
+ }
173
+ }
174
+ var bankForRegistrationName =
175
+ listenerBank[registrationName] || (listenerBank[registrationName] = {});
176
+ bankForRegistrationName[id] = listener;
177
+ },
178
+
179
+ /**
180
+ * @param {string} id ID of the DOM element.
181
+ * @param {string} registrationName Name of listener (e.g. `onClick`).
182
+ * @return {?function} The stored callback.
183
+ */
184
+ getListener: function(id, registrationName) {
185
+ var bankForRegistrationName = listenerBank[registrationName];
186
+ return bankForRegistrationName && bankForRegistrationName[id];
187
+ },
188
+
189
+ /**
190
+ * Deletes a listener from the registration bank.
191
+ *
192
+ * @param {string} id ID of the DOM element.
193
+ * @param {string} registrationName Name of listener (e.g. `onClick`).
194
+ */
195
+ deleteListener: function(id, registrationName) {
196
+ var bankForRegistrationName = listenerBank[registrationName];
197
+ if (bankForRegistrationName) {
198
+ delete bankForRegistrationName[id];
199
+ }
200
+ },
201
+
202
+ /**
203
+ * Deletes all listeners for the DOM element with the supplied ID.
204
+ *
205
+ * @param {string} id ID of the DOM element.
206
+ */
207
+ deleteAllListeners: function(id) {
208
+ for (var registrationName in listenerBank) {
209
+ delete listenerBank[registrationName][id];
210
+ }
211
+ },
212
+
213
+ /**
214
+ * Allows registered plugins an opportunity to extract events from top-level
215
+ * native browser events.
216
+ *
217
+ * @param {string} topLevelType Record from `EventConstants`.
218
+ * @param {DOMEventTarget} topLevelTarget The listening component root node.
219
+ * @param {string} topLevelTargetID ID of `topLevelTarget`.
220
+ * @param {object} nativeEvent Native browser event.
221
+ * @return {*} An accumulation of synthetic events.
222
+ * @internal
223
+ */
224
+ extractEvents: function(
225
+ topLevelType,
226
+ topLevelTarget,
227
+ topLevelTargetID,
228
+ nativeEvent) {
229
+ var events;
230
+ var plugins = EventPluginRegistry.plugins;
231
+ for (var i = 0, l = plugins.length; i < l; i++) {
232
+ // Not every plugin in the ordering may be loaded at runtime.
233
+ var possiblePlugin = plugins[i];
234
+ if (possiblePlugin) {
235
+ var extractedEvents = possiblePlugin.extractEvents(
236
+ topLevelType,
237
+ topLevelTarget,
238
+ topLevelTargetID,
239
+ nativeEvent
240
+ );
241
+ if (extractedEvents) {
242
+ events = accumulate(events, extractedEvents);
243
+ }
244
+ }
245
+ }
246
+ return events;
247
+ },
248
+
249
+ /**
250
+ * Enqueues a synthetic event that should be dispatched when
251
+ * `processEventQueue` is invoked.
252
+ *
253
+ * @param {*} events An accumulation of synthetic events.
254
+ * @internal
255
+ */
256
+ enqueueEvents: function(events) {
257
+ if (events) {
258
+ eventQueue = accumulate(eventQueue, events);
259
+ }
260
+ },
261
+
262
+ /**
263
+ * Dispatches all synthetic events on the event queue.
264
+ *
265
+ * @internal
266
+ */
267
+ processEventQueue: function() {
268
+ // Set `eventQueue` to null before processing it so that we can tell if more
269
+ // events get enqueued while processing.
270
+ var processingEventQueue = eventQueue;
271
+ eventQueue = null;
272
+ forEachAccumulated(processingEventQueue, executeDispatchesAndRelease);
273
+ ("production" !== process.env.NODE_ENV ? invariant(
274
+ !eventQueue,
275
+ 'processEventQueue(): Additional events were enqueued while processing ' +
276
+ 'an event queue. Support for this has not yet been implemented.'
277
+ ) : invariant(!eventQueue));
278
+ },
279
+
280
+ /**
281
+ * These are needed for tests only. Do not use!
282
+ */
283
+ __purge: function() {
284
+ listenerBank = {};
285
+ },
286
+
287
+ __getListenerBank: function() {
288
+ return listenerBank;
289
+ }
290
+
291
+ };
292
+
293
+ module.exports = EventPluginHub;
@@ -0,0 +1,281 @@
1
+ /**
2
+ * Copyright 2013-2014 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule EventPluginRegistry
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var invariant = require("./invariant");
23
+
24
+ /**
25
+ * Injectable ordering of event plugins.
26
+ */
27
+ var EventPluginOrder = null;
28
+
29
+ /**
30
+ * Injectable mapping from names to event plugin modules.
31
+ */
32
+ var namesToPlugins = {};
33
+
34
+ /**
35
+ * Recomputes the plugin list using the injected plugins and plugin ordering.
36
+ *
37
+ * @private
38
+ */
39
+ function recomputePluginOrdering() {
40
+ if (!EventPluginOrder) {
41
+ // Wait until an `EventPluginOrder` is injected.
42
+ return;
43
+ }
44
+ for (var pluginName in namesToPlugins) {
45
+ var PluginModule = namesToPlugins[pluginName];
46
+ var pluginIndex = EventPluginOrder.indexOf(pluginName);
47
+ ("production" !== process.env.NODE_ENV ? invariant(
48
+ pluginIndex > -1,
49
+ 'EventPluginRegistry: Cannot inject event plugins that do not exist in ' +
50
+ 'the plugin ordering, `%s`.',
51
+ pluginName
52
+ ) : invariant(pluginIndex > -1));
53
+ if (EventPluginRegistry.plugins[pluginIndex]) {
54
+ continue;
55
+ }
56
+ ("production" !== process.env.NODE_ENV ? invariant(
57
+ PluginModule.extractEvents,
58
+ 'EventPluginRegistry: Event plugins must implement an `extractEvents` ' +
59
+ 'method, but `%s` does not.',
60
+ pluginName
61
+ ) : invariant(PluginModule.extractEvents));
62
+ EventPluginRegistry.plugins[pluginIndex] = PluginModule;
63
+ var publishedEvents = PluginModule.eventTypes;
64
+ for (var eventName in publishedEvents) {
65
+ ("production" !== process.env.NODE_ENV ? invariant(
66
+ publishEventForPlugin(
67
+ publishedEvents[eventName],
68
+ PluginModule,
69
+ eventName
70
+ ),
71
+ 'EventPluginRegistry: Failed to publish event `%s` for plugin `%s`.',
72
+ eventName,
73
+ pluginName
74
+ ) : invariant(publishEventForPlugin(
75
+ publishedEvents[eventName],
76
+ PluginModule,
77
+ eventName
78
+ )));
79
+ }
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Publishes an event so that it can be dispatched by the supplied plugin.
85
+ *
86
+ * @param {object} dispatchConfig Dispatch configuration for the event.
87
+ * @param {object} PluginModule Plugin publishing the event.
88
+ * @return {boolean} True if the event was successfully published.
89
+ * @private
90
+ */
91
+ function publishEventForPlugin(dispatchConfig, PluginModule, eventName) {
92
+ ("production" !== process.env.NODE_ENV ? invariant(
93
+ !EventPluginRegistry.eventNameDispatchConfigs[eventName],
94
+ 'EventPluginHub: More than one plugin attempted to publish the same ' +
95
+ 'event name, `%s`.',
96
+ eventName
97
+ ) : invariant(!EventPluginRegistry.eventNameDispatchConfigs[eventName]));
98
+ EventPluginRegistry.eventNameDispatchConfigs[eventName] = dispatchConfig;
99
+
100
+ var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
101
+ if (phasedRegistrationNames) {
102
+ for (var phaseName in phasedRegistrationNames) {
103
+ if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
104
+ var phasedRegistrationName = phasedRegistrationNames[phaseName];
105
+ publishRegistrationName(
106
+ phasedRegistrationName,
107
+ PluginModule,
108
+ eventName
109
+ );
110
+ }
111
+ }
112
+ return true;
113
+ } else if (dispatchConfig.registrationName) {
114
+ publishRegistrationName(
115
+ dispatchConfig.registrationName,
116
+ PluginModule,
117
+ eventName
118
+ );
119
+ return true;
120
+ }
121
+ return false;
122
+ }
123
+
124
+ /**
125
+ * Publishes a registration name that is used to identify dispatched events and
126
+ * can be used with `EventPluginHub.putListener` to register listeners.
127
+ *
128
+ * @param {string} registrationName Registration name to add.
129
+ * @param {object} PluginModule Plugin publishing the event.
130
+ * @private
131
+ */
132
+ function publishRegistrationName(registrationName, PluginModule, eventName) {
133
+ ("production" !== process.env.NODE_ENV ? invariant(
134
+ !EventPluginRegistry.registrationNameModules[registrationName],
135
+ 'EventPluginHub: More than one plugin attempted to publish the same ' +
136
+ 'registration name, `%s`.',
137
+ registrationName
138
+ ) : invariant(!EventPluginRegistry.registrationNameModules[registrationName]));
139
+ EventPluginRegistry.registrationNameModules[registrationName] = PluginModule;
140
+ EventPluginRegistry.registrationNameDependencies[registrationName] =
141
+ PluginModule.eventTypes[eventName].dependencies;
142
+ }
143
+
144
+ /**
145
+ * Registers plugins so that they can extract and dispatch events.
146
+ *
147
+ * @see {EventPluginHub}
148
+ */
149
+ var EventPluginRegistry = {
150
+
151
+ /**
152
+ * Ordered list of injected plugins.
153
+ */
154
+ plugins: [],
155
+
156
+ /**
157
+ * Mapping from event name to dispatch config
158
+ */
159
+ eventNameDispatchConfigs: {},
160
+
161
+ /**
162
+ * Mapping from registration name to plugin module
163
+ */
164
+ registrationNameModules: {},
165
+
166
+ /**
167
+ * Mapping from registration name to event name
168
+ */
169
+ registrationNameDependencies: {},
170
+
171
+ /**
172
+ * Injects an ordering of plugins (by plugin name). This allows the ordering
173
+ * to be decoupled from injection of the actual plugins so that ordering is
174
+ * always deterministic regardless of packaging, on-the-fly injection, etc.
175
+ *
176
+ * @param {array} InjectedEventPluginOrder
177
+ * @internal
178
+ * @see {EventPluginHub.injection.injectEventPluginOrder}
179
+ */
180
+ injectEventPluginOrder: function(InjectedEventPluginOrder) {
181
+ ("production" !== process.env.NODE_ENV ? invariant(
182
+ !EventPluginOrder,
183
+ 'EventPluginRegistry: Cannot inject event plugin ordering more than once.'
184
+ ) : invariant(!EventPluginOrder));
185
+ // Clone the ordering so it cannot be dynamically mutated.
186
+ EventPluginOrder = Array.prototype.slice.call(InjectedEventPluginOrder);
187
+ recomputePluginOrdering();
188
+ },
189
+
190
+ /**
191
+ * Injects plugins to be used by `EventPluginHub`. The plugin names must be
192
+ * in the ordering injected by `injectEventPluginOrder`.
193
+ *
194
+ * Plugins can be injected as part of page initialization or on-the-fly.
195
+ *
196
+ * @param {object} injectedNamesToPlugins Map from names to plugin modules.
197
+ * @internal
198
+ * @see {EventPluginHub.injection.injectEventPluginsByName}
199
+ */
200
+ injectEventPluginsByName: function(injectedNamesToPlugins) {
201
+ var isOrderingDirty = false;
202
+ for (var pluginName in injectedNamesToPlugins) {
203
+ if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
204
+ continue;
205
+ }
206
+ var PluginModule = injectedNamesToPlugins[pluginName];
207
+ if (namesToPlugins[pluginName] !== PluginModule) {
208
+ ("production" !== process.env.NODE_ENV ? invariant(
209
+ !namesToPlugins[pluginName],
210
+ 'EventPluginRegistry: Cannot inject two different event plugins ' +
211
+ 'using the same name, `%s`.',
212
+ pluginName
213
+ ) : invariant(!namesToPlugins[pluginName]));
214
+ namesToPlugins[pluginName] = PluginModule;
215
+ isOrderingDirty = true;
216
+ }
217
+ }
218
+ if (isOrderingDirty) {
219
+ recomputePluginOrdering();
220
+ }
221
+ },
222
+
223
+ /**
224
+ * Looks up the plugin for the supplied event.
225
+ *
226
+ * @param {object} event A synthetic event.
227
+ * @return {?object} The plugin that created the supplied event.
228
+ * @internal
229
+ */
230
+ getPluginModuleForEvent: function(event) {
231
+ var dispatchConfig = event.dispatchConfig;
232
+ if (dispatchConfig.registrationName) {
233
+ return EventPluginRegistry.registrationNameModules[
234
+ dispatchConfig.registrationName
235
+ ] || null;
236
+ }
237
+ for (var phase in dispatchConfig.phasedRegistrationNames) {
238
+ if (!dispatchConfig.phasedRegistrationNames.hasOwnProperty(phase)) {
239
+ continue;
240
+ }
241
+ var PluginModule = EventPluginRegistry.registrationNameModules[
242
+ dispatchConfig.phasedRegistrationNames[phase]
243
+ ];
244
+ if (PluginModule) {
245
+ return PluginModule;
246
+ }
247
+ }
248
+ return null;
249
+ },
250
+
251
+ /**
252
+ * Exposed for unit testing.
253
+ * @private
254
+ */
255
+ _resetEventPlugins: function() {
256
+ EventPluginOrder = null;
257
+ for (var pluginName in namesToPlugins) {
258
+ if (namesToPlugins.hasOwnProperty(pluginName)) {
259
+ delete namesToPlugins[pluginName];
260
+ }
261
+ }
262
+ EventPluginRegistry.plugins.length = 0;
263
+
264
+ var eventNameDispatchConfigs = EventPluginRegistry.eventNameDispatchConfigs;
265
+ for (var eventName in eventNameDispatchConfigs) {
266
+ if (eventNameDispatchConfigs.hasOwnProperty(eventName)) {
267
+ delete eventNameDispatchConfigs[eventName];
268
+ }
269
+ }
270
+
271
+ var registrationNameModules = EventPluginRegistry.registrationNameModules;
272
+ for (var registrationName in registrationNameModules) {
273
+ if (registrationNameModules.hasOwnProperty(registrationName)) {
274
+ delete registrationNameModules[registrationName];
275
+ }
276
+ }
277
+ }
278
+
279
+ };
280
+
281
+ module.exports = EventPluginRegistry;