react 0.13.0-beta.1 → 0.13.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 (181) hide show
  1. package/dist/JSXTransformer.js +1919 -1295
  2. package/dist/react-with-addons.js +1690 -1090
  3. package/dist/react-with-addons.min.js +7 -6
  4. package/dist/react.js +1574 -1010
  5. package/dist/react.min.js +6 -6
  6. package/lib/AutoFocusMixin.js +1 -1
  7. package/lib/BeforeInputEventPlugin.js +1 -5
  8. package/lib/CSSCore.js +1 -1
  9. package/lib/CSSProperty.js +3 -1
  10. package/lib/CSSPropertyOperations.js +1 -1
  11. package/lib/CallbackQueue.js +1 -1
  12. package/lib/ChangeEventPlugin.js +1 -1
  13. package/lib/ClientReactRootIndex.js +1 -1
  14. package/lib/DOMChildrenOperations.js +4 -43
  15. package/lib/DOMProperty.js +1 -1
  16. package/lib/DOMPropertyOperations.js +7 -14
  17. package/lib/Danger.js +1 -1
  18. package/lib/DefaultEventPluginOrder.js +2 -2
  19. package/lib/EnterLeaveEventPlugin.js +1 -1
  20. package/lib/EventConstants.js +1 -1
  21. package/lib/EventListener.js +1 -1
  22. package/lib/EventPluginHub.js +1 -1
  23. package/lib/EventPluginRegistry.js +1 -1
  24. package/lib/EventPluginUtils.js +3 -3
  25. package/lib/EventPropagators.js +1 -1
  26. package/lib/ExecutionEnvironment.js +1 -1
  27. package/lib/FallbackCompositionState.js +1 -1
  28. package/lib/HTMLDOMPropertyConfig.js +12 -5
  29. package/lib/LinkedStateMixin.js +1 -1
  30. package/lib/LinkedValueUtils.js +1 -1
  31. package/lib/LocalEventTrapMixin.js +1 -1
  32. package/lib/MobileSafariClickEventPlugin.js +1 -1
  33. package/lib/Object.assign.js +1 -1
  34. package/lib/PooledClass.js +1 -1
  35. package/lib/React.js +7 -9
  36. package/lib/ReactBrowserComponentMixin.js +1 -1
  37. package/lib/ReactBrowserEventEmitter.js +2 -2
  38. package/lib/ReactCSSTransitionGroup.js +1 -1
  39. package/lib/ReactCSSTransitionGroupChild.js +8 -5
  40. package/lib/ReactChildReconciler.js +1 -1
  41. package/lib/ReactChildren.js +3 -2
  42. package/lib/ReactClass.js +49 -23
  43. package/lib/ReactComponent.js +35 -19
  44. package/lib/ReactComponentBrowserEnvironment.js +1 -1
  45. package/lib/ReactComponentEnvironment.js +1 -1
  46. package/lib/ReactComponentWithPureRenderMixin.js +1 -1
  47. package/lib/ReactCompositeComponent.js +89 -40
  48. package/lib/ReactContext.js +13 -3
  49. package/lib/ReactCurrentOwner.js +1 -1
  50. package/lib/ReactDOM.js +1 -1
  51. package/lib/ReactDOMButton.js +1 -1
  52. package/lib/ReactDOMComponent.js +19 -19
  53. package/lib/ReactDOMForm.js +1 -1
  54. package/lib/ReactDOMIDOperations.js +3 -3
  55. package/lib/ReactDOMIframe.js +43 -0
  56. package/lib/ReactDOMImg.js +1 -1
  57. package/lib/ReactDOMInput.js +1 -1
  58. package/lib/ReactDOMOption.js +1 -1
  59. package/lib/ReactDOMSelect.js +1 -1
  60. package/lib/ReactDOMSelection.js +1 -1
  61. package/lib/ReactDOMTextComponent.js +3 -5
  62. package/lib/ReactDOMTextarea.js +1 -1
  63. package/lib/ReactDefaultBatchingStrategy.js +1 -1
  64. package/lib/ReactDefaultInjection.js +25 -1
  65. package/lib/ReactDefaultPerf.js +5 -10
  66. package/lib/ReactDefaultPerfAnalysis.js +1 -1
  67. package/lib/ReactElement.js +56 -2
  68. package/lib/ReactElementValidator.js +122 -79
  69. package/lib/ReactEmptyComponent.js +5 -5
  70. package/lib/ReactErrorUtils.js +1 -1
  71. package/lib/ReactEventEmitterMixin.js +1 -1
  72. package/lib/ReactEventListener.js +1 -1
  73. package/lib/ReactFragment.js +181 -0
  74. package/lib/ReactInjection.js +1 -1
  75. package/lib/ReactInputSelection.js +1 -1
  76. package/lib/ReactInstanceHandles.js +1 -1
  77. package/lib/ReactInstanceMap.js +1 -1
  78. package/lib/ReactLifeCycle.js +1 -1
  79. package/lib/ReactLink.js +1 -1
  80. package/lib/ReactMarkupChecksum.js +1 -1
  81. package/lib/ReactMount.js +32 -10
  82. package/lib/ReactMultiChild.js +1 -1
  83. package/lib/ReactMultiChildUpdateTypes.js +1 -1
  84. package/lib/ReactNativeComponent.js +7 -20
  85. package/lib/ReactOwner.js +1 -1
  86. package/lib/ReactPerf.js +1 -1
  87. package/lib/ReactPropTransferer.js +1 -1
  88. package/lib/ReactPropTypeLocationNames.js +1 -1
  89. package/lib/ReactPropTypeLocations.js +1 -1
  90. package/lib/ReactPropTypes.js +7 -4
  91. package/lib/ReactPutListenerQueue.js +1 -1
  92. package/lib/ReactReconcileTransaction.js +1 -1
  93. package/lib/ReactReconciler.js +15 -2
  94. package/lib/ReactRef.js +2 -3
  95. package/lib/ReactRootIndex.js +1 -1
  96. package/lib/ReactServerRendering.js +1 -1
  97. package/lib/ReactServerRenderingTransaction.js +1 -1
  98. package/lib/ReactStateSetters.js +1 -1
  99. package/lib/ReactTestUtils.js +19 -7
  100. package/lib/ReactTransitionChildMapping.js +7 -3
  101. package/lib/ReactTransitionEvents.js +1 -1
  102. package/lib/ReactTransitionGroup.js +5 -5
  103. package/lib/ReactUpdateQueue.js +63 -32
  104. package/lib/ReactUpdates.js +7 -2
  105. package/lib/ReactWithAddons.js +3 -1
  106. package/lib/SVGDOMPropertyConfig.js +1 -1
  107. package/lib/SelectEventPlugin.js +1 -1
  108. package/lib/ServerReactRootIndex.js +1 -1
  109. package/lib/SimpleEventPlugin.js +3 -3
  110. package/lib/SyntheticClipboardEvent.js +1 -1
  111. package/lib/SyntheticCompositionEvent.js +1 -1
  112. package/lib/SyntheticDragEvent.js +1 -1
  113. package/lib/SyntheticEvent.js +1 -1
  114. package/lib/SyntheticFocusEvent.js +1 -1
  115. package/lib/SyntheticInputEvent.js +1 -1
  116. package/lib/SyntheticKeyboardEvent.js +1 -1
  117. package/lib/SyntheticMouseEvent.js +1 -1
  118. package/lib/SyntheticTouchEvent.js +1 -1
  119. package/lib/SyntheticUIEvent.js +1 -1
  120. package/lib/SyntheticWheelEvent.js +1 -1
  121. package/lib/Transaction.js +2 -2
  122. package/lib/ViewportMetrics.js +1 -1
  123. package/lib/accumulateInto.js +1 -1
  124. package/lib/adler32.js +1 -1
  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 +1 -1
  131. package/lib/createNodesFromMarkup.js +4 -4
  132. package/lib/cx.js +16 -1
  133. package/lib/dangerousStyleValue.js +1 -1
  134. package/lib/emptyFunction.js +1 -1
  135. package/lib/emptyObject.js +1 -1
  136. package/lib/{escapeTextForBrowser.js → escapeTextContentForBrowser.js} +4 -5
  137. package/lib/findDOMNode.js +19 -1
  138. package/lib/flattenChildren.js +1 -1
  139. package/lib/focusNode.js +1 -1
  140. package/lib/forEachAccumulated.js +1 -1
  141. package/lib/getActiveElement.js +1 -1
  142. package/lib/getEventCharCode.js +1 -1
  143. package/lib/getEventKey.js +1 -1
  144. package/lib/getEventModifierState.js +1 -1
  145. package/lib/getEventTarget.js +1 -1
  146. package/lib/getIteratorFn.js +1 -1
  147. package/lib/getMarkupWrap.js +1 -1
  148. package/lib/getNodeForCharacterOffset.js +1 -1
  149. package/lib/getReactRootElementInContainer.js +1 -1
  150. package/lib/getTextContentAccessor.js +1 -1
  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 +6 -1
  155. package/lib/invariant.js +1 -1
  156. package/lib/isEventSupported.js +1 -1
  157. package/lib/isNode.js +1 -1
  158. package/lib/isTextInputElement.js +1 -1
  159. package/lib/isTextNode.js +1 -1
  160. package/lib/joinClasses.js +1 -1
  161. package/lib/keyMirror.js +1 -1
  162. package/lib/keyOf.js +1 -1
  163. package/lib/mapObject.js +1 -1
  164. package/lib/memoizeStringOnly.js +1 -1
  165. package/lib/onlyChild.js +1 -1
  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 +1 -1
  170. package/lib/setTextContent.js +40 -0
  171. package/lib/shallowEqual.js +1 -1
  172. package/lib/shouldUpdateReactComponent.js +32 -10
  173. package/lib/toArray.js +2 -2
  174. package/lib/traverseAllChildren.js +18 -4
  175. package/lib/update.js +1 -1
  176. package/lib/warning.js +9 -2
  177. package/package.json +1 -1
  178. package/lib/copyProperties.js +0 -56
  179. package/lib/merge.js +0 -34
  180. package/lib/mergeInto.js +0 -24
  181. package/lib/monitorCodeUse.js +0 -30
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2014, Facebook, Inc.
2
+ * Copyright 2014-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
@@ -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
package/lib/React.js CHANGED
@@ -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
@@ -13,7 +13,6 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- var DOMPropertyOperations = require("./DOMPropertyOperations");
17
16
  var EventPluginUtils = require("./EventPluginUtils");
18
17
  var ReactChildren = require("./ReactChildren");
19
18
  var ReactComponent = require("./ReactComponent");
@@ -23,14 +22,13 @@ var ReactCurrentOwner = require("./ReactCurrentOwner");
23
22
  var ReactElement = require("./ReactElement");
24
23
  var ReactElementValidator = require("./ReactElementValidator");
25
24
  var ReactDOM = require("./ReactDOM");
26
- var ReactDOMComponent = require("./ReactDOMComponent");
27
25
  var ReactDOMTextComponent = require("./ReactDOMTextComponent");
28
26
  var ReactDefaultInjection = require("./ReactDefaultInjection");
29
27
  var ReactInstanceHandles = require("./ReactInstanceHandles");
30
28
  var ReactMount = require("./ReactMount");
31
- var ReactMultiChild = require("./ReactMultiChild");
32
29
  var ReactPerf = require("./ReactPerf");
33
30
  var ReactPropTypes = require("./ReactPropTypes");
31
+ var ReactReconciler = require("./ReactReconciler");
34
32
  var ReactServerRendering = require("./ReactServerRendering");
35
33
 
36
34
  var assign = require("./Object.assign");
@@ -41,10 +39,12 @@ ReactDefaultInjection.inject();
41
39
 
42
40
  var createElement = ReactElement.createElement;
43
41
  var createFactory = ReactElement.createFactory;
42
+ var cloneElement = ReactElement.cloneElement;
44
43
 
45
44
  if ("production" !== process.env.NODE_ENV) {
46
45
  createElement = ReactElementValidator.createElement;
47
46
  createFactory = ReactElementValidator.createFactory;
47
+ cloneElement = ReactElementValidator.cloneElement;
48
48
  }
49
49
 
50
50
  var render = ReactPerf.measure('React', 'render', ReactMount.render);
@@ -64,6 +64,7 @@ var React = {
64
64
  },
65
65
  createClass: ReactClass.createClass,
66
66
  createElement: createElement,
67
+ cloneElement: cloneElement,
67
68
  createFactory: createFactory,
68
69
  createMixin: function(mixin) {
69
70
  // Currently a noop. Will be used to validate and trace mixins.
@@ -89,13 +90,10 @@ if (
89
90
  typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
90
91
  typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.inject === 'function') {
91
92
  __REACT_DEVTOOLS_GLOBAL_HOOK__.inject({
92
- // TODO: Inject a hook for notifying devtools of updates
93
93
  CurrentOwner: ReactCurrentOwner,
94
- DOMComponent: ReactDOMComponent,
95
- DOMPropertyOperations: DOMPropertyOperations,
96
94
  InstanceHandles: ReactInstanceHandles,
97
95
  Mount: ReactMount,
98
- MultiChild: ReactMultiChild,
96
+ Reconciler: ReactReconciler,
99
97
  TextComponent: ReactDOMTextComponent
100
98
  });
101
99
  }
@@ -145,6 +143,6 @@ if ("production" !== process.env.NODE_ENV) {
145
143
  }
146
144
  }
147
145
 
148
- React.version = '0.13.0-beta.1';
146
+ React.version = '0.13.0';
149
147
 
150
148
  module.exports = React;
@@ -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
@@ -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
@@ -326,7 +326,7 @@ var ReactBrowserEventEmitter = assign({}, ReactEventEmitterMixin, {
326
326
  *
327
327
  * @see http://www.quirksmode.org/dom/events/scroll.html
328
328
  */
329
- ensureScrollValueMonitoring: function(){
329
+ ensureScrollValueMonitoring: function() {
330
330
  if (!isMonitoringScrollValue) {
331
331
  var refresh = ViewportMetrics.refreshScrollValues;
332
332
  ReactBrowserEventEmitter.ReactEventListener.monitorScrollValue(refresh);
@@ -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
@@ -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
@@ -18,6 +18,7 @@ var CSSCore = require("./CSSCore");
18
18
  var ReactTransitionEvents = require("./ReactTransitionEvents");
19
19
 
20
20
  var onlyChild = require("./onlyChild");
21
+ var warning = require("./warning");
21
22
 
22
23
  // We don't remove the element from the DOM until we receive an animationend or
23
24
  // transitionend event. If the user screws up and forgets to add an animation
@@ -31,12 +32,14 @@ var noEventListener = null;
31
32
 
32
33
  if ("production" !== process.env.NODE_ENV) {
33
34
  noEventListener = function() {
34
- console.warn(
35
+ ("production" !== process.env.NODE_ENV ? warning(
36
+ false,
35
37
  'transition(): tried to perform an animation without ' +
36
38
  'an animationend or transitionend event after timeout (' +
37
- NO_EVENT_TIMEOUT + 'ms). You should either disable this ' +
38
- 'transition in JS or add a CSS animation/transition.'
39
- );
39
+ '%sms). You should either disable this ' +
40
+ 'transition in JS or add a CSS animation/transition.',
41
+ NO_EVENT_TIMEOUT
42
+ ) : null);
40
43
  };
41
44
  }
42
45
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2014, Facebook, Inc.
2
+ * Copyright 2014-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
@@ -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
@@ -12,6 +12,7 @@
12
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");
@@ -121,7 +122,7 @@ function mapChildren(children, func, context) {
121
122
  var traverseContext = MapBookKeeping.getPooled(mapResult, func, context);
122
123
  traverseAllChildren(children, mapSingleChildIntoContext, traverseContext);
123
124
  MapBookKeeping.release(traverseContext);
124
- return mapResult;
125
+ return ReactFragment.create(mapResult);
125
126
  }
126
127
 
127
128
  function forEachSingleChildDummy(traverseContext, child, name, i) {
package/lib/ReactClass.js CHANGED
@@ -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
@@ -12,6 +12,7 @@
12
12
  'use strict';
13
13
 
14
14
  var ReactComponent = require("./ReactComponent");
15
+ var ReactCurrentOwner = require("./ReactCurrentOwner");
15
16
  var ReactElement = require("./ReactElement");
16
17
  var ReactErrorUtils = require("./ReactErrorUtils");
17
18
  var ReactInstanceMap = require("./ReactInstanceMap");
@@ -24,7 +25,6 @@ var assign = require("./Object.assign");
24
25
  var invariant = require("./invariant");
25
26
  var keyMirror = require("./keyMirror");
26
27
  var keyOf = require("./keyOf");
27
- var monitorCodeUse = require("./monitorCodeUse");
28
28
  var warning = require("./warning");
29
29
 
30
30
  var MIXINS_KEY = keyOf({mixins: null});
@@ -661,18 +661,20 @@ function bindAutoBindMethod(component, method) {
661
661
  // ignore the value of "this" that the user is trying to use, so
662
662
  // let's warn.
663
663
  if (newThis !== component && newThis !== null) {
664
- monitorCodeUse('react_bind_warning', { component: componentName });
665
- console.warn(
664
+ ("production" !== process.env.NODE_ENV ? warning(
665
+ false,
666
666
  'bind(): React component methods may only be bound to the ' +
667
- 'component instance. See ' + componentName
668
- );
667
+ 'component instance. See %s',
668
+ componentName
669
+ ) : null);
669
670
  } else if (!args.length) {
670
- monitorCodeUse('react_bind_warning', { component: componentName });
671
- console.warn(
671
+ ("production" !== process.env.NODE_ENV ? warning(
672
+ false,
672
673
  'bind(): You are binding a component method to the component. ' +
673
674
  'React does this for you automatically in a high-performance ' +
674
- 'way, so you can safely remove this call. See ' + componentName
675
- );
675
+ 'way, so you can safely remove this call. See %s',
676
+ componentName
677
+ ) : null);
676
678
  return boundMethod;
677
679
  }
678
680
  var reboundMethod = _bind.apply(boundMethod, arguments);
@@ -716,6 +718,9 @@ var typeDeprecationDescriptor = {
716
718
  displayName,
717
719
  displayName
718
720
  ) : null);
721
+ Object.defineProperty(this, 'type', {
722
+ value: this
723
+ });
719
724
  return this;
720
725
  }
721
726
  };
@@ -744,6 +749,21 @@ var ReactClassMixin = {
744
749
  * @final
745
750
  */
746
751
  isMounted: function() {
752
+ if ("production" !== process.env.NODE_ENV) {
753
+ var owner = ReactCurrentOwner.current;
754
+ if (owner !== null) {
755
+ ("production" !== process.env.NODE_ENV ? warning(
756
+ owner._warnedAboutRefsInRender,
757
+ '%s is accessing isMounted inside its render() function. ' +
758
+ 'render() should be a pure function of props and state. It should ' +
759
+ 'never access something that requires stale data from the previous ' +
760
+ 'render, such as refs. Move this logic to componentDidMount and ' +
761
+ 'componentDidUpdate instead.',
762
+ owner.getName() || 'A component'
763
+ ) : null);
764
+ owner._warnedAboutRefsInRender = true;
765
+ }
766
+ }
747
767
  var internalInstance = ReactInstanceMap.get(this);
748
768
  return (
749
769
  internalInstance &&
@@ -810,6 +830,14 @@ var ReactClass = {
810
830
  // This constructor is overridden by mocks. The argument is used
811
831
  // by mocks to assert on what gets mounted.
812
832
 
833
+ if ("production" !== process.env.NODE_ENV) {
834
+ ("production" !== process.env.NODE_ENV ? warning(
835
+ this instanceof Constructor,
836
+ 'Something is calling a React component directly. Use a factory or ' +
837
+ 'JSX instead. See: http://fb.me/react-legacyfactory'
838
+ ) : null);
839
+ }
840
+
813
841
  // Wire up auto-binding
814
842
  if (this.__reactAutoBindMap) {
815
843
  bindAutoBindMethods(this);
@@ -873,18 +901,14 @@ var ReactClass = {
873
901
  ) : invariant(Constructor.prototype.render));
874
902
 
875
903
  if ("production" !== process.env.NODE_ENV) {
876
- if (Constructor.prototype.componentShouldUpdate) {
877
- monitorCodeUse(
878
- 'react_component_should_update_warning',
879
- { component: spec.displayName }
880
- );
881
- console.warn(
882
- (spec.displayName || 'A component') + ' 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
- );
887
- }
904
+ ("production" !== process.env.NODE_ENV ? warning(
905
+ !Constructor.prototype.componentShouldUpdate,
906
+ '%s has a method called ' +
907
+ 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' +
908
+ 'The name is phrased as a question because the function is ' +
909
+ 'expected to return a value.',
910
+ spec.displayName || 'A component'
911
+ ) : null);
888
912
  }
889
913
 
890
914
  // Reduce time spent doing lookups by setting these on the prototype.
@@ -897,8 +921,10 @@ var ReactClass = {
897
921
  // Legacy hook
898
922
  Constructor.type = Constructor;
899
923
  if ("production" !== process.env.NODE_ENV) {
900
- if (Object.defineProperty) {
924
+ try {
901
925
  Object.defineProperty(Constructor, 'type', typeDeprecationDescriptor);
926
+ } catch (x) {
927
+ // IE will fail on defineProperty (es5-shim/sham too)
902
928
  }
903
929
  }
904
930
 
@@ -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
@@ -36,16 +36,29 @@ function ReactComponent(props, context) {
36
36
  * callback that will be executed when the call to setState is actually
37
37
  * completed.
38
38
  *
39
- * @param {object} partialState Next partial state to be merged with state.
39
+ * When a function is provided to setState, it will be called at some point in
40
+ * the future (not synchronously). It will be called with the up to date
41
+ * component arguments (state, props, context). These values can be different
42
+ * from this.* because your function may be called after receiveProps but before
43
+ * shouldComponentUpdate, and this new state, props, and context will not yet be
44
+ * assigned to this.
45
+ *
46
+ * @param {object|function} partialState Next partial state or function to
47
+ * produce next partial state to be merged with current state.
40
48
  * @param {?function} callback Called after state is updated.
41
49
  * @final
42
50
  * @protected
43
51
  */
44
52
  ReactComponent.prototype.setState = function(partialState, callback) {
45
53
  ("production" !== process.env.NODE_ENV ? invariant(
46
- typeof partialState === 'object' || partialState == null,
47
- 'setState(...): takes an object of state variables to update.'
48
- ) : invariant(typeof partialState === 'object' || partialState == null));
54
+ typeof partialState === 'object' ||
55
+ typeof partialState === 'function' ||
56
+ partialState == null,
57
+ 'setState(...): takes an object of state variables to update or a ' +
58
+ 'function which returns an object of state variables.'
59
+ ) : invariant(typeof partialState === 'object' ||
60
+ typeof partialState === 'function' ||
61
+ partialState == null));
49
62
  if ("production" !== process.env.NODE_ENV) {
50
63
  ("production" !== process.env.NODE_ENV ? warning(
51
64
  partialState != null,
@@ -66,7 +79,7 @@ ReactComponent.prototype.setState = function(partialState, callback) {
66
79
  * You may want to call this when you know that some deeper aspect of the
67
80
  * component's state has changed but `setState` was not called.
68
81
  *
69
- * This will not invoke `shouldUpdateComponent`, but it will invoke
82
+ * This will not invoke `shouldComponentUpdate`, but it will invoke
70
83
  * `componentWillUpdate` and `componentDidUpdate`.
71
84
  *
72
85
  * @param {?function} callback Called after update is complete.
@@ -86,14 +99,15 @@ ReactComponent.prototype.forceUpdate = function(callback) {
86
99
  * modern base class. Instead, we define a getter that warns if it's accessed.
87
100
  */
88
101
  if ("production" !== process.env.NODE_ENV) {
89
- if (Object.defineProperty) {
90
- var deprecatedAPIs = {
91
- getDOMNode: 'getDOMNode',
92
- isMounted: 'isMounted',
93
- replaceState: 'replaceState',
94
- setProps: 'setProps'
95
- };
96
- var defineDeprecationWarning = function(methodName, displayName) {
102
+ var deprecatedAPIs = {
103
+ getDOMNode: 'getDOMNode',
104
+ isMounted: 'isMounted',
105
+ replaceProps: 'replaceProps',
106
+ replaceState: 'replaceState',
107
+ setProps: 'setProps'
108
+ };
109
+ var defineDeprecationWarning = function(methodName, displayName) {
110
+ try {
97
111
  Object.defineProperty(ReactComponent.prototype, methodName, {
98
112
  get: function() {
99
113
  ("production" !== process.env.NODE_ENV ? warning(
@@ -104,11 +118,13 @@ if ("production" !== process.env.NODE_ENV) {
104
118
  return undefined;
105
119
  }
106
120
  });
107
- };
108
- for (var methodName in deprecatedAPIs) {
109
- if (deprecatedAPIs.hasOwnProperty(methodName)) {
110
- defineDeprecationWarning(methodName, deprecatedAPIs[methodName]);
111
- }
121
+ } catch (x) {
122
+ // IE will fail on defineProperty (es5-shim/sham too)
123
+ }
124
+ };
125
+ for (var fnName in deprecatedAPIs) {
126
+ if (deprecatedAPIs.hasOwnProperty(fnName)) {
127
+ defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
112
128
  }
113
129
  }
114
130
  }
@@ -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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2014, Facebook, Inc.
2
+ * Copyright 2014-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
@@ -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
@@ -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
@@ -96,7 +96,8 @@ var ReactCompositeComponentMixin = {
96
96
 
97
97
  // See ReactUpdateQueue
98
98
  this._pendingElement = null;
99
- this._pendingState = null;
99
+ this._pendingStateQueue = null;
100
+ this._pendingReplaceState = false;
100
101
  this._pendingForceUpdate = false;
101
102
 
102
103
  this._renderedComponent = null;
@@ -132,6 +133,20 @@ var ReactCompositeComponentMixin = {
132
133
 
133
134
  // Initialize the public class
134
135
  var inst = new Component(publicProps, publicContext);
136
+
137
+ if ("production" !== process.env.NODE_ENV) {
138
+ // This will throw later in _renderValidatedComponent, but add an early
139
+ // warning now to help debugging
140
+ ("production" !== process.env.NODE_ENV ? warning(
141
+ inst.render != null,
142
+ '%s(...): No `render` method found on the returned component ' +
143
+ 'instance: you may have forgotten to define `render` in your ' +
144
+ 'component or you may have accidentally tried to render an element ' +
145
+ 'whose type is a function that isn\'t a React component.',
146
+ Component.displayName || Component.name || 'Component'
147
+ ) : null);
148
+ }
149
+
135
150
  // These should be set up in the constructor, but as a convenience for
136
151
  // simpler class abstractions, we set them up after the fact.
137
152
  inst.props = publicProps;
@@ -191,26 +206,29 @@ var ReactCompositeComponentMixin = {
191
206
  this.getName() || 'ReactCompositeComponent'
192
207
  ) : invariant(typeof initialState === 'object' && !Array.isArray(initialState)));
193
208
 
194
- this._pendingState = null;
209
+ this._pendingStateQueue = null;
210
+ this._pendingReplaceState = false;
195
211
  this._pendingForceUpdate = false;
196
212
 
197
- if (inst.componentWillMount) {
198
- var previouslyMounting = ReactLifeCycle.currentlyMountingInstance;
199
- ReactLifeCycle.currentlyMountingInstance = this;
200
- try {
213
+ var renderedElement;
214
+
215
+ var previouslyMounting = ReactLifeCycle.currentlyMountingInstance;
216
+ ReactLifeCycle.currentlyMountingInstance = this;
217
+ try {
218
+ if (inst.componentWillMount) {
201
219
  inst.componentWillMount();
202
- } finally {
203
- ReactLifeCycle.currentlyMountingInstance = previouslyMounting;
204
- }
205
- // When mounting, calls to `setState` by `componentWillMount` will set
206
- // `this._pendingState` without triggering a re-render.
207
- if (this._pendingState) {
208
- inst.state = this._pendingState;
209
- this._pendingState = null;
220
+ // When mounting, calls to `setState` by `componentWillMount` will set
221
+ // `this._pendingStateQueue` without triggering a re-render.
222
+ if (this._pendingStateQueue) {
223
+ inst.state = this._processPendingState(inst.props, inst.context);
224
+ }
210
225
  }
226
+
227
+ renderedElement = this._renderValidatedComponent();
228
+ } finally {
229
+ ReactLifeCycle.currentlyMountingInstance = previouslyMounting;
211
230
  }
212
231
 
213
- var renderedElement = this._renderValidatedComponent();
214
232
  this._renderedComponent = this._instantiateReactComponent(
215
233
  renderedElement,
216
234
  this._currentElement.type // The wrapping type
@@ -252,13 +270,12 @@ var ReactCompositeComponentMixin = {
252
270
  this._renderedComponent = null;
253
271
 
254
272
  // Reset pending fields
255
- this._pendingState = null;
273
+ this._pendingStateQueue = null;
274
+ this._pendingReplaceState = false;
256
275
  this._pendingForceUpdate = false;
257
276
  this._pendingCallbacks = null;
258
277
  this._pendingElement = null;
259
278
 
260
- ReactComponentEnvironment.unmountIDFromEnvironment(this._rootNodeID);
261
-
262
279
  // These fields do not really need to be reset since this object is no
263
280
  // longer accessible.
264
281
  this._context = null;
@@ -444,10 +461,19 @@ var ReactCompositeComponentMixin = {
444
461
 
445
462
  if (location === ReactPropTypeLocations.prop) {
446
463
  // Preface gives us something to blacklist in warning module
447
- var preface = 'Failed CompositeComponent proptype check. ';
448
- ("production" !== process.env.NODE_ENV ? warning(false, preface + error.message + addendum) : null);
464
+ ("production" !== process.env.NODE_ENV ? warning(
465
+ false,
466
+ 'Failed Composite propType: %s%s',
467
+ error.message,
468
+ addendum
469
+ ) : null);
449
470
  } else {
450
- ("production" !== process.env.NODE_ENV ? warning(false, error.message + addendum) : null);
471
+ ("production" !== process.env.NODE_ENV ? warning(
472
+ false,
473
+ 'Failed Context Types: %s%s',
474
+ error.message,
475
+ addendum
476
+ ) : null);
451
477
  }
452
478
  }
453
479
  }
@@ -470,7 +496,7 @@ var ReactCompositeComponentMixin = {
470
496
  },
471
497
 
472
498
  /**
473
- * If any of `_pendingElement`, `_pendingState`, or `_pendingForceUpdate`
499
+ * If any of `_pendingElement`, `_pendingStateQueue`, or `_pendingForceUpdate`
474
500
  * is set, update the component.
475
501
  *
476
502
  * @param {ReactReconcileTransaction} transaction
@@ -486,7 +512,7 @@ var ReactCompositeComponentMixin = {
486
512
  );
487
513
  }
488
514
 
489
- if (this._pendingState != null || this._pendingForceUpdate) {
515
+ if (this._pendingStateQueue !== null || this._pendingForceUpdate) {
490
516
  if ("production" !== process.env.NODE_ENV) {
491
517
  ReactElementValidator.checkAndWarnForMutatedProps(
492
518
  this._currentElement
@@ -551,10 +577,8 @@ var ReactCompositeComponentMixin = {
551
577
  ) {
552
578
  var inst = this._instance;
553
579
 
554
- var prevContext = inst.context;
555
- var prevProps = inst.props;
556
- var nextContext = prevContext;
557
- var nextProps = prevProps;
580
+ var nextContext = inst.context;
581
+ var nextProps = inst.props;
558
582
 
559
583
  // Distinguish between a props update versus a simple state update
560
584
  if (prevParentElement !== nextParentElement) {
@@ -563,12 +587,15 @@ var ReactCompositeComponentMixin = {
563
587
 
564
588
  if ("production" !== process.env.NODE_ENV) {
565
589
  if (nextUnmaskedContext != null) {
566
- this._warnIfContextsDiffer(nextParentElement._context, nextUnmaskedContext);
590
+ this._warnIfContextsDiffer(
591
+ nextParentElement._context,
592
+ nextUnmaskedContext
593
+ );
567
594
  }
568
595
  }
569
596
 
570
597
  // An update here will schedule an update but immediately set
571
- // _pendingState which will ensure that any state updates gets
598
+ // _pendingStateQueue which will ensure that any state updates gets
572
599
  // immediately reconciled instead of waiting for the next batch.
573
600
 
574
601
  if (inst.componentWillReceiveProps) {
@@ -576,8 +603,7 @@ var ReactCompositeComponentMixin = {
576
603
  }
577
604
  }
578
605
 
579
- var nextState = this._pendingState || inst.state;
580
- this._pendingState = null;
606
+ var nextState = this._processPendingState(nextProps, nextContext);
581
607
 
582
608
  var shouldUpdate =
583
609
  this._pendingForceUpdate ||
@@ -585,13 +611,12 @@ var ReactCompositeComponentMixin = {
585
611
  inst.shouldComponentUpdate(nextProps, nextState, nextContext);
586
612
 
587
613
  if ("production" !== process.env.NODE_ENV) {
588
- if (typeof shouldUpdate === 'undefined') {
589
- console.warn(
590
- (this.getName() || 'ReactCompositeComponent') +
591
- '.shouldComponentUpdate(): Returned undefined instead of a ' +
592
- 'boolean value. Make sure to return true or false.'
593
- );
594
- }
614
+ ("production" !== process.env.NODE_ENV ? warning(
615
+ typeof shouldUpdate !== 'undefined',
616
+ '%s.shouldComponentUpdate(): Returned undefined instead of a ' +
617
+ 'boolean value. Make sure to return true or false.',
618
+ this.getName() || 'ReactCompositeComponent'
619
+ ) : null);
595
620
  }
596
621
 
597
622
  if (shouldUpdate) {
@@ -616,6 +641,31 @@ var ReactCompositeComponentMixin = {
616
641
  }
617
642
  },
618
643
 
644
+ _processPendingState: function(props, context) {
645
+ var inst = this._instance;
646
+ var queue = this._pendingStateQueue;
647
+ var replace = this._pendingReplaceState;
648
+ this._pendingReplaceState = false;
649
+ this._pendingStateQueue = null;
650
+
651
+ if (!queue) {
652
+ return inst.state;
653
+ }
654
+
655
+ var nextState = assign({}, replace ? queue[0] : inst.state);
656
+ for (var i = replace ? 1 : 0; i < queue.length; i++) {
657
+ var partial = queue[i];
658
+ assign(
659
+ nextState,
660
+ typeof partial === 'function' ?
661
+ partial.call(inst, nextState, props, context) :
662
+ partial
663
+ );
664
+ }
665
+
666
+ return nextState;
667
+ },
668
+
619
669
  /**
620
670
  * Merges new props and state, notifies delegate methods of update and
621
671
  * performs update.
@@ -638,7 +688,6 @@ var ReactCompositeComponentMixin = {
638
688
  ) {
639
689
  var inst = this._instance;
640
690
 
641
- var prevElement = this._currentElement;
642
691
  var prevProps = inst.props;
643
692
  var prevState = inst.state;
644
693
  var prevContext = inst.context;