react 0.12.2 → 0.13.0-beta.2

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 (184) hide show
  1. package/dist/JSXTransformer.js +986 -511
  2. package/dist/react-with-addons.js +6076 -4560
  3. package/dist/react-with-addons.min.js +6 -7
  4. package/dist/react.js +5386 -4170
  5. package/dist/react.min.js +6 -7
  6. package/lib/AutoFocusMixin.js +2 -2
  7. package/lib/BeforeInputEventPlugin.js +388 -115
  8. package/lib/CSSCore.js +1 -1
  9. package/lib/CSSProperty.js +2 -2
  10. package/lib/CSSPropertyOperations.js +58 -11
  11. package/lib/CallbackQueue.js +3 -3
  12. package/lib/ChangeEventPlugin.js +4 -4
  13. package/lib/ClientReactRootIndex.js +2 -2
  14. package/lib/DOMChildrenOperations.js +10 -47
  15. package/lib/DOMProperty.js +2 -2
  16. package/lib/DOMPropertyOperations.js +11 -16
  17. package/lib/Danger.js +8 -7
  18. package/lib/DefaultEventPluginOrder.js +3 -4
  19. package/lib/EnterLeaveEventPlugin.js +2 -2
  20. package/lib/EventConstants.js +2 -2
  21. package/lib/EventListener.js +1 -1
  22. package/lib/EventPluginHub.js +10 -8
  23. package/lib/EventPluginRegistry.js +2 -2
  24. package/lib/EventPluginUtils.js +4 -4
  25. package/lib/EventPropagators.js +2 -2
  26. package/lib/ExecutionEnvironment.js +3 -4
  27. package/lib/FallbackCompositionState.js +89 -0
  28. package/lib/HTMLDOMPropertyConfig.js +23 -10
  29. package/lib/LinkedStateMixin.js +2 -2
  30. package/lib/LinkedValueUtils.js +4 -4
  31. package/lib/LocalEventTrapMixin.js +10 -3
  32. package/lib/MobileSafariClickEventPlugin.js +2 -2
  33. package/lib/Object.assign.js +4 -2
  34. package/lib/PooledClass.js +2 -2
  35. package/lib/React.js +19 -58
  36. package/lib/ReactBrowserComponentMixin.js +4 -14
  37. package/lib/ReactBrowserEventEmitter.js +6 -8
  38. package/lib/ReactCSSTransitionGroup.js +5 -2
  39. package/lib/ReactCSSTransitionGroupChild.js +20 -7
  40. package/lib/ReactChildReconciler.js +125 -0
  41. package/lib/ReactChildren.js +13 -10
  42. package/lib/ReactClass.js +918 -0
  43. package/lib/ReactComponent.js +98 -406
  44. package/lib/ReactComponentBrowserEnvironment.js +11 -84
  45. package/lib/ReactComponentEnvironment.js +57 -0
  46. package/lib/ReactComponentWithPureRenderMixin.js +2 -2
  47. package/lib/ReactCompositeComponent.js +574 -1140
  48. package/lib/ReactContext.js +17 -3
  49. package/lib/ReactCurrentOwner.js +2 -2
  50. package/lib/ReactDOM.js +4 -9
  51. package/lib/ReactDOMButton.js +6 -7
  52. package/lib/ReactDOMComponent.js +123 -105
  53. package/lib/ReactDOMForm.js +6 -7
  54. package/lib/ReactDOMIDOperations.js +59 -77
  55. package/lib/ReactDOMIframe.js +43 -0
  56. package/lib/ReactDOMImg.js +5 -7
  57. package/lib/ReactDOMInput.js +6 -7
  58. package/lib/ReactDOMOption.js +6 -7
  59. package/lib/ReactDOMSelect.js +58 -66
  60. package/lib/ReactDOMSelection.js +7 -3
  61. package/lib/{ReactTextComponent.js → ReactDOMTextComponent.js} +48 -37
  62. package/lib/ReactDOMTextarea.js +6 -7
  63. package/lib/ReactDefaultBatchingStrategy.js +5 -5
  64. package/lib/ReactDefaultInjection.js +39 -9
  65. package/lib/ReactDefaultPerf.js +17 -8
  66. package/lib/ReactDefaultPerfAnalysis.js +2 -2
  67. package/lib/ReactElement.js +23 -15
  68. package/lib/ReactElementValidator.js +206 -89
  69. package/lib/ReactEmptyComponent.js +33 -15
  70. package/lib/ReactErrorUtils.js +1 -1
  71. package/lib/ReactEventEmitterMixin.js +2 -2
  72. package/lib/ReactEventListener.js +4 -5
  73. package/lib/ReactFragment.js +172 -0
  74. package/lib/ReactInjection.js +8 -6
  75. package/lib/ReactInputSelection.js +4 -5
  76. package/lib/ReactInstanceHandles.js +4 -3
  77. package/lib/ReactInstanceMap.js +47 -0
  78. package/lib/ReactLifeCycle.js +35 -0
  79. package/lib/ReactLink.js +2 -2
  80. package/lib/ReactMarkupChecksum.js +2 -2
  81. package/lib/ReactMount.js +264 -71
  82. package/lib/ReactMultiChild.js +50 -48
  83. package/lib/ReactMultiChildUpdateTypes.js +2 -2
  84. package/lib/ReactNativeComponent.js +59 -25
  85. package/lib/ReactOwner.js +5 -49
  86. package/lib/ReactPerf.js +22 -2
  87. package/lib/ReactPropTransferer.js +3 -58
  88. package/lib/ReactPropTypeLocationNames.js +2 -2
  89. package/lib/ReactPropTypeLocations.js +2 -2
  90. package/lib/ReactPropTypes.js +17 -25
  91. package/lib/ReactPutListenerQueue.js +2 -2
  92. package/lib/ReactReconcileTransaction.js +2 -2
  93. package/lib/ReactReconciler.js +121 -0
  94. package/lib/ReactRef.js +69 -0
  95. package/lib/ReactRootIndex.js +2 -2
  96. package/lib/ReactServerRendering.js +6 -4
  97. package/lib/ReactServerRenderingTransaction.js +2 -2
  98. package/lib/ReactStateSetters.js +2 -2
  99. package/lib/ReactTestUtils.js +113 -27
  100. package/lib/ReactTransitionChildMapping.js +8 -4
  101. package/lib/ReactTransitionEvents.js +2 -2
  102. package/lib/ReactTransitionGroup.js +53 -12
  103. package/lib/ReactUpdateQueue.js +295 -0
  104. package/lib/ReactUpdates.js +54 -62
  105. package/lib/ReactWithAddons.js +4 -2
  106. package/lib/SVGDOMPropertyConfig.js +2 -2
  107. package/lib/SelectEventPlugin.js +4 -4
  108. package/lib/ServerReactRootIndex.js +2 -2
  109. package/lib/SimpleEventPlugin.js +4 -4
  110. package/lib/SyntheticClipboardEvent.js +2 -3
  111. package/lib/SyntheticCompositionEvent.js +2 -3
  112. package/lib/SyntheticDragEvent.js +2 -2
  113. package/lib/SyntheticEvent.js +12 -4
  114. package/lib/SyntheticFocusEvent.js +2 -2
  115. package/lib/SyntheticInputEvent.js +2 -3
  116. package/lib/SyntheticKeyboardEvent.js +2 -2
  117. package/lib/SyntheticMouseEvent.js +3 -5
  118. package/lib/SyntheticTouchEvent.js +2 -2
  119. package/lib/SyntheticUIEvent.js +2 -2
  120. package/lib/SyntheticWheelEvent.js +2 -2
  121. package/lib/Transaction.js +4 -4
  122. package/lib/ViewportMetrics.js +3 -6
  123. package/lib/accumulateInto.js +2 -2
  124. package/lib/adler32.js +2 -2
  125. package/lib/camelize.js +1 -1
  126. package/lib/camelizeStyleName.js +1 -1
  127. package/lib/cloneWithProps.js +4 -4
  128. package/lib/containsNode.js +1 -1
  129. package/lib/{createArrayFrom.js → createArrayFromMixed.js} +6 -6
  130. package/lib/createFullPageComponent.js +4 -4
  131. package/lib/createNodesFromMarkup.js +4 -4
  132. package/lib/cx.js +1 -1
  133. package/lib/dangerousStyleValue.js +2 -2
  134. package/lib/emptyFunction.js +1 -1
  135. package/lib/emptyObject.js +1 -1
  136. package/lib/{escapeTextForBrowser.js → escapeTextContentForBrowser.js} +10 -11
  137. package/lib/findDOMNode.js +51 -0
  138. package/lib/flattenChildren.js +12 -23
  139. package/lib/focusNode.js +1 -1
  140. package/lib/forEachAccumulated.js +2 -2
  141. package/lib/getActiveElement.js +1 -1
  142. package/lib/getEventCharCode.js +2 -2
  143. package/lib/getEventKey.js +2 -2
  144. package/lib/getEventModifierState.js +2 -2
  145. package/lib/getEventTarget.js +2 -2
  146. package/lib/getIteratorFn.js +42 -0
  147. package/lib/getMarkupWrap.js +1 -1
  148. package/lib/getNodeForCharacterOffset.js +3 -3
  149. package/lib/getReactRootElementInContainer.js +2 -2
  150. package/lib/getTextContentAccessor.js +2 -2
  151. package/lib/getUnboundedScrollPosition.js +1 -1
  152. package/lib/hyphenate.js +1 -1
  153. package/lib/hyphenateStyleName.js +1 -1
  154. package/lib/instantiateReactComponent.js +90 -68
  155. package/lib/invariant.js +1 -1
  156. package/lib/isEventSupported.js +2 -2
  157. package/lib/isNode.js +4 -5
  158. package/lib/isTextInputElement.js +3 -4
  159. package/lib/isTextNode.js +1 -1
  160. package/lib/joinClasses.js +2 -2
  161. package/lib/keyMirror.js +2 -2
  162. package/lib/keyOf.js +1 -1
  163. package/lib/mapObject.js +1 -1
  164. package/lib/memoizeStringOnly.js +5 -6
  165. package/lib/onlyChild.js +2 -2
  166. package/lib/performance.js +1 -1
  167. package/lib/performanceNow.js +1 -1
  168. package/lib/quoteAttributeValueForBrowser.js +26 -0
  169. package/lib/setInnerHTML.js +13 -2
  170. package/lib/setTextContent.js +40 -0
  171. package/lib/shallowEqual.js +2 -2
  172. package/lib/shouldUpdateReactComponent.js +71 -7
  173. package/lib/toArray.js +2 -2
  174. package/lib/traverseAllChildren.js +114 -56
  175. package/lib/update.js +2 -2
  176. package/lib/warning.js +20 -2
  177. package/package.json +1 -1
  178. package/lib/CompositionEventPlugin.js +0 -257
  179. package/lib/ReactLegacyElement.js +0 -243
  180. package/lib/copyProperties.js +0 -54
  181. package/lib/deprecated.js +0 -47
  182. package/lib/merge.js +0 -34
  183. package/lib/mergeInto.js +0 -24
  184. package/lib/monitorCodeUse.js +0 -30
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013-2014, Facebook, Inc.
2
+ * Copyright 2013-2015, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under the BSD-style license found in the
@@ -9,9 +9,10 @@
9
9
  * @providesModule ReactChildren
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var PooledClass = require("./PooledClass");
15
+ var ReactFragment = require("./ReactFragment");
15
16
 
16
17
  var traverseAllChildren = require("./traverseAllChildren");
17
18
  var warning = require("./warning");
@@ -81,13 +82,15 @@ function mapSingleChildIntoContext(traverseContext, child, name, i) {
81
82
  var mapResult = mapBookKeeping.mapResult;
82
83
 
83
84
  var keyUnique = !mapResult.hasOwnProperty(name);
84
- ("production" !== process.env.NODE_ENV ? warning(
85
- keyUnique,
86
- 'ReactChildren.map(...): Encountered two children with the same key, ' +
87
- '`%s`. Child keys must be unique; when two children share a key, only ' +
88
- 'the first child will be used.',
89
- name
90
- ) : null);
85
+ if ("production" !== process.env.NODE_ENV) {
86
+ ("production" !== process.env.NODE_ENV ? warning(
87
+ keyUnique,
88
+ 'ReactChildren.map(...): Encountered two children with the same key, ' +
89
+ '`%s`. Child keys must be unique; when two children share a key, only ' +
90
+ 'the first child will be used.',
91
+ name
92
+ ) : null);
93
+ }
91
94
 
92
95
  if (keyUnique) {
93
96
  var mappedChild =
@@ -119,7 +122,7 @@ function mapChildren(children, func, context) {
119
122
  var traverseContext = MapBookKeeping.getPooled(mapResult, func, context);
120
123
  traverseAllChildren(children, mapSingleChildIntoContext, traverseContext);
121
124
  MapBookKeeping.release(traverseContext);
122
- return mapResult;
125
+ return ReactFragment.create(mapResult);
123
126
  }
124
127
 
125
128
  function forEachSingleChildDummy(traverseContext, child, name, i) {
@@ -0,0 +1,918 @@
1
+ /**
2
+ * Copyright 2013-2015, 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
+ * @providesModule ReactClass
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ var ReactComponent = require("./ReactComponent");
15
+ var ReactElement = require("./ReactElement");
16
+ var ReactErrorUtils = require("./ReactErrorUtils");
17
+ var ReactInstanceMap = require("./ReactInstanceMap");
18
+ var ReactLifeCycle = require("./ReactLifeCycle");
19
+ var ReactPropTypeLocations = require("./ReactPropTypeLocations");
20
+ var ReactPropTypeLocationNames = require("./ReactPropTypeLocationNames");
21
+ var ReactUpdateQueue = require("./ReactUpdateQueue");
22
+
23
+ var assign = require("./Object.assign");
24
+ var invariant = require("./invariant");
25
+ var keyMirror = require("./keyMirror");
26
+ var keyOf = require("./keyOf");
27
+ var warning = require("./warning");
28
+
29
+ var MIXINS_KEY = keyOf({mixins: null});
30
+
31
+ /**
32
+ * Policies that describe methods in `ReactClassInterface`.
33
+ */
34
+ var SpecPolicy = keyMirror({
35
+ /**
36
+ * These methods may be defined only once by the class specification or mixin.
37
+ */
38
+ DEFINE_ONCE: null,
39
+ /**
40
+ * These methods may be defined by both the class specification and mixins.
41
+ * Subsequent definitions will be chained. These methods must return void.
42
+ */
43
+ DEFINE_MANY: null,
44
+ /**
45
+ * These methods are overriding the base class.
46
+ */
47
+ OVERRIDE_BASE: null,
48
+ /**
49
+ * These methods are similar to DEFINE_MANY, except we assume they return
50
+ * objects. We try to merge the keys of the return values of all the mixed in
51
+ * functions. If there is a key conflict we throw.
52
+ */
53
+ DEFINE_MANY_MERGED: null
54
+ });
55
+
56
+
57
+ var injectedMixins = [];
58
+
59
+ /**
60
+ * Composite components are higher-level components that compose other composite
61
+ * or native components.
62
+ *
63
+ * To create a new type of `ReactClass`, pass a specification of
64
+ * your new class to `React.createClass`. The only requirement of your class
65
+ * specification is that you implement a `render` method.
66
+ *
67
+ * var MyComponent = React.createClass({
68
+ * render: function() {
69
+ * return <div>Hello World</div>;
70
+ * }
71
+ * });
72
+ *
73
+ * The class specification supports a specific protocol of methods that have
74
+ * special meaning (e.g. `render`). See `ReactClassInterface` for
75
+ * more the comprehensive protocol. Any other properties and methods in the
76
+ * class specification will available on the prototype.
77
+ *
78
+ * @interface ReactClassInterface
79
+ * @internal
80
+ */
81
+ var ReactClassInterface = {
82
+
83
+ /**
84
+ * An array of Mixin objects to include when defining your component.
85
+ *
86
+ * @type {array}
87
+ * @optional
88
+ */
89
+ mixins: SpecPolicy.DEFINE_MANY,
90
+
91
+ /**
92
+ * An object containing properties and methods that should be defined on
93
+ * the component's constructor instead of its prototype (static methods).
94
+ *
95
+ * @type {object}
96
+ * @optional
97
+ */
98
+ statics: SpecPolicy.DEFINE_MANY,
99
+
100
+ /**
101
+ * Definition of prop types for this component.
102
+ *
103
+ * @type {object}
104
+ * @optional
105
+ */
106
+ propTypes: SpecPolicy.DEFINE_MANY,
107
+
108
+ /**
109
+ * Definition of context types for this component.
110
+ *
111
+ * @type {object}
112
+ * @optional
113
+ */
114
+ contextTypes: SpecPolicy.DEFINE_MANY,
115
+
116
+ /**
117
+ * Definition of context types this component sets for its children.
118
+ *
119
+ * @type {object}
120
+ * @optional
121
+ */
122
+ childContextTypes: SpecPolicy.DEFINE_MANY,
123
+
124
+ // ==== Definition methods ====
125
+
126
+ /**
127
+ * Invoked when the component is mounted. Values in the mapping will be set on
128
+ * `this.props` if that prop is not specified (i.e. using an `in` check).
129
+ *
130
+ * This method is invoked before `getInitialState` and therefore cannot rely
131
+ * on `this.state` or use `this.setState`.
132
+ *
133
+ * @return {object}
134
+ * @optional
135
+ */
136
+ getDefaultProps: SpecPolicy.DEFINE_MANY_MERGED,
137
+
138
+ /**
139
+ * Invoked once before the component is mounted. The return value will be used
140
+ * as the initial value of `this.state`.
141
+ *
142
+ * getInitialState: function() {
143
+ * return {
144
+ * isOn: false,
145
+ * fooBaz: new BazFoo()
146
+ * }
147
+ * }
148
+ *
149
+ * @return {object}
150
+ * @optional
151
+ */
152
+ getInitialState: SpecPolicy.DEFINE_MANY_MERGED,
153
+
154
+ /**
155
+ * @return {object}
156
+ * @optional
157
+ */
158
+ getChildContext: SpecPolicy.DEFINE_MANY_MERGED,
159
+
160
+ /**
161
+ * Uses props from `this.props` and state from `this.state` to render the
162
+ * structure of the component.
163
+ *
164
+ * No guarantees are made about when or how often this method is invoked, so
165
+ * it must not have side effects.
166
+ *
167
+ * render: function() {
168
+ * var name = this.props.name;
169
+ * return <div>Hello, {name}!</div>;
170
+ * }
171
+ *
172
+ * @return {ReactComponent}
173
+ * @nosideeffects
174
+ * @required
175
+ */
176
+ render: SpecPolicy.DEFINE_ONCE,
177
+
178
+
179
+
180
+ // ==== Delegate methods ====
181
+
182
+ /**
183
+ * Invoked when the component is initially created and about to be mounted.
184
+ * This may have side effects, but any external subscriptions or data created
185
+ * by this method must be cleaned up in `componentWillUnmount`.
186
+ *
187
+ * @optional
188
+ */
189
+ componentWillMount: SpecPolicy.DEFINE_MANY,
190
+
191
+ /**
192
+ * Invoked when the component has been mounted and has a DOM representation.
193
+ * However, there is no guarantee that the DOM node is in the document.
194
+ *
195
+ * Use this as an opportunity to operate on the DOM when the component has
196
+ * been mounted (initialized and rendered) for the first time.
197
+ *
198
+ * @param {DOMElement} rootNode DOM element representing the component.
199
+ * @optional
200
+ */
201
+ componentDidMount: SpecPolicy.DEFINE_MANY,
202
+
203
+ /**
204
+ * Invoked before the component receives new props.
205
+ *
206
+ * Use this as an opportunity to react to a prop transition by updating the
207
+ * state using `this.setState`. Current props are accessed via `this.props`.
208
+ *
209
+ * componentWillReceiveProps: function(nextProps, nextContext) {
210
+ * this.setState({
211
+ * likesIncreasing: nextProps.likeCount > this.props.likeCount
212
+ * });
213
+ * }
214
+ *
215
+ * NOTE: There is no equivalent `componentWillReceiveState`. An incoming prop
216
+ * transition may cause a state change, but the opposite is not true. If you
217
+ * need it, you are probably looking for `componentWillUpdate`.
218
+ *
219
+ * @param {object} nextProps
220
+ * @optional
221
+ */
222
+ componentWillReceiveProps: SpecPolicy.DEFINE_MANY,
223
+
224
+ /**
225
+ * Invoked while deciding if the component should be updated as a result of
226
+ * receiving new props, state and/or context.
227
+ *
228
+ * Use this as an opportunity to `return false` when you're certain that the
229
+ * transition to the new props/state/context will not require a component
230
+ * update.
231
+ *
232
+ * shouldComponentUpdate: function(nextProps, nextState, nextContext) {
233
+ * return !equal(nextProps, this.props) ||
234
+ * !equal(nextState, this.state) ||
235
+ * !equal(nextContext, this.context);
236
+ * }
237
+ *
238
+ * @param {object} nextProps
239
+ * @param {?object} nextState
240
+ * @param {?object} nextContext
241
+ * @return {boolean} True if the component should update.
242
+ * @optional
243
+ */
244
+ shouldComponentUpdate: SpecPolicy.DEFINE_ONCE,
245
+
246
+ /**
247
+ * Invoked when the component is about to update due to a transition from
248
+ * `this.props`, `this.state` and `this.context` to `nextProps`, `nextState`
249
+ * and `nextContext`.
250
+ *
251
+ * Use this as an opportunity to perform preparation before an update occurs.
252
+ *
253
+ * NOTE: You **cannot** use `this.setState()` in this method.
254
+ *
255
+ * @param {object} nextProps
256
+ * @param {?object} nextState
257
+ * @param {?object} nextContext
258
+ * @param {ReactReconcileTransaction} transaction
259
+ * @optional
260
+ */
261
+ componentWillUpdate: SpecPolicy.DEFINE_MANY,
262
+
263
+ /**
264
+ * Invoked when the component's DOM representation has been updated.
265
+ *
266
+ * Use this as an opportunity to operate on the DOM when the component has
267
+ * been updated.
268
+ *
269
+ * @param {object} prevProps
270
+ * @param {?object} prevState
271
+ * @param {?object} prevContext
272
+ * @param {DOMElement} rootNode DOM element representing the component.
273
+ * @optional
274
+ */
275
+ componentDidUpdate: SpecPolicy.DEFINE_MANY,
276
+
277
+ /**
278
+ * Invoked when the component is about to be removed from its parent and have
279
+ * its DOM representation destroyed.
280
+ *
281
+ * Use this as an opportunity to deallocate any external resources.
282
+ *
283
+ * NOTE: There is no `componentDidUnmount` since your component will have been
284
+ * destroyed by that point.
285
+ *
286
+ * @optional
287
+ */
288
+ componentWillUnmount: SpecPolicy.DEFINE_MANY,
289
+
290
+
291
+
292
+ // ==== Advanced methods ====
293
+
294
+ /**
295
+ * Updates the component's currently mounted DOM representation.
296
+ *
297
+ * By default, this implements React's rendering and reconciliation algorithm.
298
+ * Sophisticated clients may wish to override this.
299
+ *
300
+ * @param {ReactReconcileTransaction} transaction
301
+ * @internal
302
+ * @overridable
303
+ */
304
+ updateComponent: SpecPolicy.OVERRIDE_BASE
305
+
306
+ };
307
+
308
+ /**
309
+ * Mapping from class specification keys to special processing functions.
310
+ *
311
+ * Although these are declared like instance properties in the specification
312
+ * when defining classes using `React.createClass`, they are actually static
313
+ * and are accessible on the constructor instead of the prototype. Despite
314
+ * being static, they must be defined outside of the "statics" key under
315
+ * which all other static methods are defined.
316
+ */
317
+ var RESERVED_SPEC_KEYS = {
318
+ displayName: function(Constructor, displayName) {
319
+ Constructor.displayName = displayName;
320
+ },
321
+ mixins: function(Constructor, mixins) {
322
+ if (mixins) {
323
+ for (var i = 0; i < mixins.length; i++) {
324
+ mixSpecIntoComponent(Constructor, mixins[i]);
325
+ }
326
+ }
327
+ },
328
+ childContextTypes: function(Constructor, childContextTypes) {
329
+ if ("production" !== process.env.NODE_ENV) {
330
+ validateTypeDef(
331
+ Constructor,
332
+ childContextTypes,
333
+ ReactPropTypeLocations.childContext
334
+ );
335
+ }
336
+ Constructor.childContextTypes = assign(
337
+ {},
338
+ Constructor.childContextTypes,
339
+ childContextTypes
340
+ );
341
+ },
342
+ contextTypes: function(Constructor, contextTypes) {
343
+ if ("production" !== process.env.NODE_ENV) {
344
+ validateTypeDef(
345
+ Constructor,
346
+ contextTypes,
347
+ ReactPropTypeLocations.context
348
+ );
349
+ }
350
+ Constructor.contextTypes = assign(
351
+ {},
352
+ Constructor.contextTypes,
353
+ contextTypes
354
+ );
355
+ },
356
+ /**
357
+ * Special case getDefaultProps which should move into statics but requires
358
+ * automatic merging.
359
+ */
360
+ getDefaultProps: function(Constructor, getDefaultProps) {
361
+ if (Constructor.getDefaultProps) {
362
+ Constructor.getDefaultProps = createMergedResultFunction(
363
+ Constructor.getDefaultProps,
364
+ getDefaultProps
365
+ );
366
+ } else {
367
+ Constructor.getDefaultProps = getDefaultProps;
368
+ }
369
+ },
370
+ propTypes: function(Constructor, propTypes) {
371
+ if ("production" !== process.env.NODE_ENV) {
372
+ validateTypeDef(
373
+ Constructor,
374
+ propTypes,
375
+ ReactPropTypeLocations.prop
376
+ );
377
+ }
378
+ Constructor.propTypes = assign(
379
+ {},
380
+ Constructor.propTypes,
381
+ propTypes
382
+ );
383
+ },
384
+ statics: function(Constructor, statics) {
385
+ mixStaticSpecIntoComponent(Constructor, statics);
386
+ }
387
+ };
388
+
389
+ function validateTypeDef(Constructor, typeDef, location) {
390
+ for (var propName in typeDef) {
391
+ if (typeDef.hasOwnProperty(propName)) {
392
+ // use a warning instead of an invariant so components
393
+ // don't show up in prod but not in __DEV__
394
+ ("production" !== process.env.NODE_ENV ? warning(
395
+ typeof typeDef[propName] === 'function',
396
+ '%s: %s type `%s` is invalid; it must be a function, usually from ' +
397
+ 'React.PropTypes.',
398
+ Constructor.displayName || 'ReactClass',
399
+ ReactPropTypeLocationNames[location],
400
+ propName
401
+ ) : null);
402
+ }
403
+ }
404
+ }
405
+
406
+ function validateMethodOverride(proto, name) {
407
+ var specPolicy = ReactClassInterface.hasOwnProperty(name) ?
408
+ ReactClassInterface[name] :
409
+ null;
410
+
411
+ // Disallow overriding of base class methods unless explicitly allowed.
412
+ if (ReactClassMixin.hasOwnProperty(name)) {
413
+ ("production" !== process.env.NODE_ENV ? invariant(
414
+ specPolicy === SpecPolicy.OVERRIDE_BASE,
415
+ 'ReactClassInterface: You are attempting to override ' +
416
+ '`%s` from your class specification. Ensure that your method names ' +
417
+ 'do not overlap with React methods.',
418
+ name
419
+ ) : invariant(specPolicy === SpecPolicy.OVERRIDE_BASE));
420
+ }
421
+
422
+ // Disallow defining methods more than once unless explicitly allowed.
423
+ if (proto.hasOwnProperty(name)) {
424
+ ("production" !== process.env.NODE_ENV ? invariant(
425
+ specPolicy === SpecPolicy.DEFINE_MANY ||
426
+ specPolicy === SpecPolicy.DEFINE_MANY_MERGED,
427
+ 'ReactClassInterface: You are attempting to define ' +
428
+ '`%s` on your component more than once. This conflict may be due ' +
429
+ 'to a mixin.',
430
+ name
431
+ ) : invariant(specPolicy === SpecPolicy.DEFINE_MANY ||
432
+ specPolicy === SpecPolicy.DEFINE_MANY_MERGED));
433
+ }
434
+ }
435
+
436
+ /**
437
+ * Mixin helper which handles policy validation and reserved
438
+ * specification keys when building React classses.
439
+ */
440
+ function mixSpecIntoComponent(Constructor, spec) {
441
+ if (!spec) {
442
+ return;
443
+ }
444
+
445
+ ("production" !== process.env.NODE_ENV ? invariant(
446
+ typeof spec !== 'function',
447
+ 'ReactClass: You\'re attempting to ' +
448
+ 'use a component class as a mixin. Instead, just use a regular object.'
449
+ ) : invariant(typeof spec !== 'function'));
450
+ ("production" !== process.env.NODE_ENV ? invariant(
451
+ !ReactElement.isValidElement(spec),
452
+ 'ReactClass: You\'re attempting to ' +
453
+ 'use a component as a mixin. Instead, just use a regular object.'
454
+ ) : invariant(!ReactElement.isValidElement(spec)));
455
+
456
+ var proto = Constructor.prototype;
457
+
458
+ // By handling mixins before any other properties, we ensure the same
459
+ // chaining order is applied to methods with DEFINE_MANY policy, whether
460
+ // mixins are listed before or after these methods in the spec.
461
+ if (spec.hasOwnProperty(MIXINS_KEY)) {
462
+ RESERVED_SPEC_KEYS.mixins(Constructor, spec.mixins);
463
+ }
464
+
465
+ for (var name in spec) {
466
+ if (!spec.hasOwnProperty(name)) {
467
+ continue;
468
+ }
469
+
470
+ if (name === MIXINS_KEY) {
471
+ // We have already handled mixins in a special case above
472
+ continue;
473
+ }
474
+
475
+ var property = spec[name];
476
+ validateMethodOverride(proto, name);
477
+
478
+ if (RESERVED_SPEC_KEYS.hasOwnProperty(name)) {
479
+ RESERVED_SPEC_KEYS[name](Constructor, property);
480
+ } else {
481
+ // Setup methods on prototype:
482
+ // The following member methods should not be automatically bound:
483
+ // 1. Expected ReactClass methods (in the "interface").
484
+ // 2. Overridden methods (that were mixed in).
485
+ var isReactClassMethod =
486
+ ReactClassInterface.hasOwnProperty(name);
487
+ var isAlreadyDefined = proto.hasOwnProperty(name);
488
+ var markedDontBind = property && property.__reactDontBind;
489
+ var isFunction = typeof property === 'function';
490
+ var shouldAutoBind =
491
+ isFunction &&
492
+ !isReactClassMethod &&
493
+ !isAlreadyDefined &&
494
+ !markedDontBind;
495
+
496
+ if (shouldAutoBind) {
497
+ if (!proto.__reactAutoBindMap) {
498
+ proto.__reactAutoBindMap = {};
499
+ }
500
+ proto.__reactAutoBindMap[name] = property;
501
+ proto[name] = property;
502
+ } else {
503
+ if (isAlreadyDefined) {
504
+ var specPolicy = ReactClassInterface[name];
505
+
506
+ // These cases should already be caught by validateMethodOverride
507
+ ("production" !== process.env.NODE_ENV ? invariant(
508
+ isReactClassMethod && (
509
+ (specPolicy === SpecPolicy.DEFINE_MANY_MERGED || specPolicy === SpecPolicy.DEFINE_MANY)
510
+ ),
511
+ 'ReactClass: Unexpected spec policy %s for key %s ' +
512
+ 'when mixing in component specs.',
513
+ specPolicy,
514
+ name
515
+ ) : invariant(isReactClassMethod && (
516
+ (specPolicy === SpecPolicy.DEFINE_MANY_MERGED || specPolicy === SpecPolicy.DEFINE_MANY)
517
+ )));
518
+
519
+ // For methods which are defined more than once, call the existing
520
+ // methods before calling the new property, merging if appropriate.
521
+ if (specPolicy === SpecPolicy.DEFINE_MANY_MERGED) {
522
+ proto[name] = createMergedResultFunction(proto[name], property);
523
+ } else if (specPolicy === SpecPolicy.DEFINE_MANY) {
524
+ proto[name] = createChainedFunction(proto[name], property);
525
+ }
526
+ } else {
527
+ proto[name] = property;
528
+ if ("production" !== process.env.NODE_ENV) {
529
+ // Add verbose displayName to the function, which helps when looking
530
+ // at profiling tools.
531
+ if (typeof property === 'function' && spec.displayName) {
532
+ proto[name].displayName = spec.displayName + '_' + name;
533
+ }
534
+ }
535
+ }
536
+ }
537
+ }
538
+ }
539
+ }
540
+
541
+ function mixStaticSpecIntoComponent(Constructor, statics) {
542
+ if (!statics) {
543
+ return;
544
+ }
545
+ for (var name in statics) {
546
+ var property = statics[name];
547
+ if (!statics.hasOwnProperty(name)) {
548
+ continue;
549
+ }
550
+
551
+ var isReserved = name in RESERVED_SPEC_KEYS;
552
+ ("production" !== process.env.NODE_ENV ? invariant(
553
+ !isReserved,
554
+ 'ReactClass: You are attempting to define a reserved ' +
555
+ 'property, `%s`, that shouldn\'t be on the "statics" key. Define it ' +
556
+ 'as an instance property instead; it will still be accessible on the ' +
557
+ 'constructor.',
558
+ name
559
+ ) : invariant(!isReserved));
560
+
561
+ var isInherited = name in Constructor;
562
+ ("production" !== process.env.NODE_ENV ? invariant(
563
+ !isInherited,
564
+ 'ReactClass: You are attempting to define ' +
565
+ '`%s` on your component more than once. This conflict may be ' +
566
+ 'due to a mixin.',
567
+ name
568
+ ) : invariant(!isInherited));
569
+ Constructor[name] = property;
570
+ }
571
+ }
572
+
573
+ /**
574
+ * Merge two objects, but throw if both contain the same key.
575
+ *
576
+ * @param {object} one The first object, which is mutated.
577
+ * @param {object} two The second object
578
+ * @return {object} one after it has been mutated to contain everything in two.
579
+ */
580
+ function mergeIntoWithNoDuplicateKeys(one, two) {
581
+ ("production" !== process.env.NODE_ENV ? invariant(
582
+ one && two && typeof one === 'object' && typeof two === 'object',
583
+ 'mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.'
584
+ ) : invariant(one && two && typeof one === 'object' && typeof two === 'object'));
585
+
586
+ for (var key in two) {
587
+ if (two.hasOwnProperty(key)) {
588
+ ("production" !== process.env.NODE_ENV ? invariant(
589
+ one[key] === undefined,
590
+ 'mergeIntoWithNoDuplicateKeys(): ' +
591
+ 'Tried to merge two objects with the same key: `%s`. This conflict ' +
592
+ 'may be due to a mixin; in particular, this may be caused by two ' +
593
+ 'getInitialState() or getDefaultProps() methods returning objects ' +
594
+ 'with clashing keys.',
595
+ key
596
+ ) : invariant(one[key] === undefined));
597
+ one[key] = two[key];
598
+ }
599
+ }
600
+ return one;
601
+ }
602
+
603
+ /**
604
+ * Creates a function that invokes two functions and merges their return values.
605
+ *
606
+ * @param {function} one Function to invoke first.
607
+ * @param {function} two Function to invoke second.
608
+ * @return {function} Function that invokes the two argument functions.
609
+ * @private
610
+ */
611
+ function createMergedResultFunction(one, two) {
612
+ return function mergedResult() {
613
+ var a = one.apply(this, arguments);
614
+ var b = two.apply(this, arguments);
615
+ if (a == null) {
616
+ return b;
617
+ } else if (b == null) {
618
+ return a;
619
+ }
620
+ var c = {};
621
+ mergeIntoWithNoDuplicateKeys(c, a);
622
+ mergeIntoWithNoDuplicateKeys(c, b);
623
+ return c;
624
+ };
625
+ }
626
+
627
+ /**
628
+ * Creates a function that invokes two functions and ignores their return vales.
629
+ *
630
+ * @param {function} one Function to invoke first.
631
+ * @param {function} two Function to invoke second.
632
+ * @return {function} Function that invokes the two argument functions.
633
+ * @private
634
+ */
635
+ function createChainedFunction(one, two) {
636
+ return function chainedFunction() {
637
+ one.apply(this, arguments);
638
+ two.apply(this, arguments);
639
+ };
640
+ }
641
+
642
+ /**
643
+ * Binds a method to the component.
644
+ *
645
+ * @param {object} component Component whose method is going to be bound.
646
+ * @param {function} method Method to be bound.
647
+ * @return {function} The bound method.
648
+ */
649
+ function bindAutoBindMethod(component, method) {
650
+ var boundMethod = method.bind(component);
651
+ if ("production" !== process.env.NODE_ENV) {
652
+ boundMethod.__reactBoundContext = component;
653
+ boundMethod.__reactBoundMethod = method;
654
+ boundMethod.__reactBoundArguments = null;
655
+ var componentName = component.constructor.displayName;
656
+ var _bind = boundMethod.bind;
657
+ /* eslint-disable block-scoped-var, no-undef */
658
+ boundMethod.bind = function(newThis ) {for (var args=[],$__0=1,$__1=arguments.length;$__0<$__1;$__0++) args.push(arguments[$__0]);
659
+ // User is trying to bind() an autobound method; we effectively will
660
+ // ignore the value of "this" that the user is trying to use, so
661
+ // let's warn.
662
+ if (newThis !== component && newThis !== null) {
663
+ ("production" !== process.env.NODE_ENV ? warning(
664
+ false,
665
+ 'bind(): React component methods may only be bound to the ' +
666
+ 'component instance. See %s',
667
+ componentName
668
+ ) : null);
669
+ } else if (!args.length) {
670
+ ("production" !== process.env.NODE_ENV ? warning(
671
+ false,
672
+ 'bind(): You are binding a component method to the component. ' +
673
+ 'React does this for you automatically in a high-performance ' +
674
+ 'way, so you can safely remove this call. See ',
675
+ componentName
676
+ ) : null);
677
+ return boundMethod;
678
+ }
679
+ var reboundMethod = _bind.apply(boundMethod, arguments);
680
+ reboundMethod.__reactBoundContext = component;
681
+ reboundMethod.__reactBoundMethod = method;
682
+ reboundMethod.__reactBoundArguments = args;
683
+ return reboundMethod;
684
+ /* eslint-enable */
685
+ };
686
+ }
687
+ return boundMethod;
688
+ }
689
+
690
+ /**
691
+ * Binds all auto-bound methods in a component.
692
+ *
693
+ * @param {object} component Component whose method is going to be bound.
694
+ */
695
+ function bindAutoBindMethods(component) {
696
+ for (var autoBindKey in component.__reactAutoBindMap) {
697
+ if (component.__reactAutoBindMap.hasOwnProperty(autoBindKey)) {
698
+ var method = component.__reactAutoBindMap[autoBindKey];
699
+ component[autoBindKey] = bindAutoBindMethod(
700
+ component,
701
+ ReactErrorUtils.guard(
702
+ method,
703
+ component.constructor.displayName + '.' + autoBindKey
704
+ )
705
+ );
706
+ }
707
+ }
708
+ }
709
+
710
+ var typeDeprecationDescriptor = {
711
+ enumerable: false,
712
+ get: function() {
713
+ var displayName = this.displayName || this.name || 'Component';
714
+ ("production" !== process.env.NODE_ENV ? warning(
715
+ false,
716
+ '%s.type is deprecated. Use %s directly to access the class.',
717
+ displayName,
718
+ displayName
719
+ ) : null);
720
+ Object.defineProperty(this, 'type', {
721
+ value: this
722
+ });
723
+ return this;
724
+ }
725
+ };
726
+
727
+ /**
728
+ * Add more to the ReactClass base class. These are all legacy features and
729
+ * therefore not already part of the modern ReactComponent.
730
+ */
731
+ var ReactClassMixin = {
732
+
733
+ /**
734
+ * TODO: This will be deprecated because state should always keep a consistent
735
+ * type signature and the only use case for this, is to avoid that.
736
+ */
737
+ replaceState: function(newState, callback) {
738
+ ReactUpdateQueue.enqueueReplaceState(this, newState);
739
+ if (callback) {
740
+ ReactUpdateQueue.enqueueCallback(this, callback);
741
+ }
742
+ },
743
+
744
+ /**
745
+ * Checks whether or not this composite component is mounted.
746
+ * @return {boolean} True if mounted, false otherwise.
747
+ * @protected
748
+ * @final
749
+ */
750
+ isMounted: function() {
751
+ var internalInstance = ReactInstanceMap.get(this);
752
+ return (
753
+ internalInstance &&
754
+ internalInstance !== ReactLifeCycle.currentlyMountingInstance
755
+ );
756
+ },
757
+
758
+ /**
759
+ * Sets a subset of the props.
760
+ *
761
+ * @param {object} partialProps Subset of the next props.
762
+ * @param {?function} callback Called after props are updated.
763
+ * @final
764
+ * @public
765
+ * @deprecated
766
+ */
767
+ setProps: function(partialProps, callback) {
768
+ ReactUpdateQueue.enqueueSetProps(this, partialProps);
769
+ if (callback) {
770
+ ReactUpdateQueue.enqueueCallback(this, callback);
771
+ }
772
+ },
773
+
774
+ /**
775
+ * Replace all the props.
776
+ *
777
+ * @param {object} newProps Subset of the next props.
778
+ * @param {?function} callback Called after props are updated.
779
+ * @final
780
+ * @public
781
+ * @deprecated
782
+ */
783
+ replaceProps: function(newProps, callback) {
784
+ ReactUpdateQueue.enqueueReplaceProps(this, newProps);
785
+ if (callback) {
786
+ ReactUpdateQueue.enqueueCallback(this, callback);
787
+ }
788
+ }
789
+ };
790
+
791
+ var ReactClassComponent = function() {};
792
+ assign(
793
+ ReactClassComponent.prototype,
794
+ ReactComponent.prototype,
795
+ ReactClassMixin
796
+ );
797
+
798
+ /**
799
+ * Module for creating composite components.
800
+ *
801
+ * @class ReactClass
802
+ */
803
+ var ReactClass = {
804
+
805
+ /**
806
+ * Creates a composite component class given a class specification.
807
+ *
808
+ * @param {object} spec Class specification (which must define `render`).
809
+ * @return {function} Component constructor function.
810
+ * @public
811
+ */
812
+ createClass: function(spec) {
813
+ var Constructor = function(props, context) {
814
+ // This constructor is overridden by mocks. The argument is used
815
+ // by mocks to assert on what gets mounted.
816
+
817
+ // Wire up auto-binding
818
+ if (this.__reactAutoBindMap) {
819
+ bindAutoBindMethods(this);
820
+ }
821
+
822
+ this.props = props;
823
+ this.context = context;
824
+ this.state = null;
825
+
826
+ // ReactClasses doesn't have constructors. Instead, they use the
827
+ // getInitialState and componentWillMount methods for initialization.
828
+
829
+ var initialState = this.getInitialState ? this.getInitialState() : null;
830
+ if ("production" !== process.env.NODE_ENV) {
831
+ // We allow auto-mocks to proceed as if they're returning null.
832
+ if (typeof initialState === 'undefined' &&
833
+ this.getInitialState._isMockFunction) {
834
+ // This is probably bad practice. Consider warning here and
835
+ // deprecating this convenience.
836
+ initialState = null;
837
+ }
838
+ }
839
+ ("production" !== process.env.NODE_ENV ? invariant(
840
+ typeof initialState === 'object' && !Array.isArray(initialState),
841
+ '%s.getInitialState(): must return an object or null',
842
+ Constructor.displayName || 'ReactCompositeComponent'
843
+ ) : invariant(typeof initialState === 'object' && !Array.isArray(initialState)));
844
+
845
+ this.state = initialState;
846
+ };
847
+ Constructor.prototype = new ReactClassComponent();
848
+ Constructor.prototype.constructor = Constructor;
849
+
850
+ injectedMixins.forEach(
851
+ mixSpecIntoComponent.bind(null, Constructor)
852
+ );
853
+
854
+ mixSpecIntoComponent(Constructor, spec);
855
+
856
+ // Initialize the defaultProps property after all mixins have been merged
857
+ if (Constructor.getDefaultProps) {
858
+ Constructor.defaultProps = Constructor.getDefaultProps();
859
+ }
860
+
861
+ if ("production" !== process.env.NODE_ENV) {
862
+ // This is a tag to indicate that the use of these method names is ok,
863
+ // since it's used with createClass. If it's not, then it's likely a
864
+ // mistake so we'll warn you to use the static property, property
865
+ // initializer or constructor respectively.
866
+ if (Constructor.getDefaultProps) {
867
+ Constructor.getDefaultProps.isReactClassApproved = {};
868
+ }
869
+ if (Constructor.prototype.getInitialState) {
870
+ Constructor.prototype.getInitialState.isReactClassApproved = {};
871
+ }
872
+ }
873
+
874
+ ("production" !== process.env.NODE_ENV ? invariant(
875
+ Constructor.prototype.render,
876
+ 'createClass(...): Class specification must implement a `render` method.'
877
+ ) : invariant(Constructor.prototype.render));
878
+
879
+ if ("production" !== process.env.NODE_ENV) {
880
+ ("production" !== process.env.NODE_ENV ? warning(
881
+ !Constructor.prototype.componentShouldUpdate,
882
+ '%s has a method called ' +
883
+ 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' +
884
+ 'The name is phrased as a question because the function is ' +
885
+ 'expected to return a value.',
886
+ spec.displayName || 'A component'
887
+ ) : null);
888
+ }
889
+
890
+ // Reduce time spent doing lookups by setting these on the prototype.
891
+ for (var methodName in ReactClassInterface) {
892
+ if (!Constructor.prototype[methodName]) {
893
+ Constructor.prototype[methodName] = null;
894
+ }
895
+ }
896
+
897
+ // Legacy hook
898
+ Constructor.type = Constructor;
899
+ if ("production" !== process.env.NODE_ENV) {
900
+ try {
901
+ Object.defineProperty(Constructor, 'type', typeDeprecationDescriptor);
902
+ } catch (x) {
903
+ // IE will fail on defineProperty (es5-shim/sham too)
904
+ }
905
+ }
906
+
907
+ return Constructor;
908
+ },
909
+
910
+ injection: {
911
+ injectMixin: function(mixin) {
912
+ injectedMixins.push(mixin);
913
+ }
914
+ }
915
+
916
+ };
917
+
918
+ module.exports = ReactClass;