react 0.13.0-alpha.1 → 0.13.0-rc1

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 (182) hide show
  1. package/dist/JSXTransformer.js +1376 -596
  2. package/dist/react-with-addons.js +3256 -2363
  3. package/dist/react-with-addons.min.js +7 -7
  4. package/dist/react.js +3092 -2266
  5. package/dist/react.min.js +6 -7
  6. package/lib/AutoFocusMixin.js +2 -2
  7. package/lib/BeforeInputEventPlugin.js +5 -9
  8. package/lib/CSSCore.js +1 -1
  9. package/lib/CSSProperty.js +4 -2
  10. package/lib/CSSPropertyOperations.js +44 -17
  11. package/lib/CallbackQueue.js +3 -3
  12. package/lib/ChangeEventPlugin.js +2 -2
  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 +7 -6
  18. package/lib/DefaultEventPluginOrder.js +3 -3
  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 +1 -1
  27. package/lib/FallbackCompositionState.js +7 -5
  28. package/lib/HTMLDOMPropertyConfig.js +22 -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 +2 -2
  34. package/lib/PooledClass.js +2 -2
  35. package/lib/React.js +9 -13
  36. package/lib/ReactBrowserComponentMixin.js +2 -2
  37. package/lib/ReactBrowserEventEmitter.js +4 -4
  38. package/lib/ReactCSSTransitionGroup.js +2 -2
  39. package/lib/ReactCSSTransitionGroupChild.js +12 -7
  40. package/lib/ReactChildReconciler.js +11 -7
  41. package/lib/ReactChildren.js +13 -10
  42. package/lib/ReactClass.js +161 -135
  43. package/lib/ReactComponent.js +100 -158
  44. package/lib/ReactComponentBrowserEnvironment.js +2 -2
  45. package/lib/ReactComponentEnvironment.js +3 -3
  46. package/lib/ReactComponentWithPureRenderMixin.js +2 -2
  47. package/lib/ReactCompositeComponent.js +336 -484
  48. package/lib/ReactContext.js +14 -4
  49. package/lib/ReactCurrentOwner.js +2 -2
  50. package/lib/ReactDOM.js +2 -2
  51. package/lib/ReactDOMButton.js +2 -2
  52. package/lib/ReactDOMComponent.js +42 -52
  53. package/lib/ReactDOMForm.js +2 -2
  54. package/lib/ReactDOMIDOperations.js +4 -4
  55. package/lib/ReactDOMIframe.js +43 -0
  56. package/lib/ReactDOMImg.js +2 -2
  57. package/lib/ReactDOMInput.js +2 -2
  58. package/lib/ReactDOMOption.js +2 -2
  59. package/lib/ReactDOMSelect.js +3 -3
  60. package/lib/ReactDOMSelection.js +2 -2
  61. package/lib/ReactDOMTextComponent.js +4 -13
  62. package/lib/ReactDOMTextarea.js +2 -2
  63. package/lib/ReactDefaultBatchingStrategy.js +5 -5
  64. package/lib/ReactDefaultInjection.js +26 -2
  65. package/lib/ReactDefaultPerf.js +12 -4
  66. package/lib/ReactDefaultPerfAnalysis.js +1 -1
  67. package/lib/ReactElement.js +7 -5
  68. package/lib/ReactElementValidator.js +185 -65
  69. package/lib/ReactEmptyComponent.js +17 -6
  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 +180 -0
  74. package/lib/ReactInjection.js +2 -2
  75. package/lib/ReactInputSelection.js +2 -2
  76. package/lib/ReactInstanceHandles.js +4 -3
  77. package/lib/ReactInstanceMap.js +2 -2
  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 +87 -23
  82. package/lib/ReactMultiChild.js +19 -7
  83. package/lib/ReactMultiChildUpdateTypes.js +2 -2
  84. package/lib/ReactNativeComponent.js +34 -37
  85. package/lib/ReactOwner.js +2 -2
  86. package/lib/ReactPerf.js +2 -2
  87. package/lib/ReactPropTransferer.js +3 -3
  88. package/lib/ReactPropTypeLocationNames.js +2 -2
  89. package/lib/ReactPropTypeLocations.js +2 -2
  90. package/lib/ReactPropTypes.js +16 -8
  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 +41 -68
  95. package/lib/ReactRootIndex.js +2 -2
  96. package/lib/ReactServerRendering.js +4 -3
  97. package/lib/ReactServerRenderingTransaction.js +2 -2
  98. package/lib/ReactStateSetters.js +2 -2
  99. package/lib/ReactTestUtils.js +49 -8
  100. package/lib/ReactTransitionChildMapping.js +8 -4
  101. package/lib/ReactTransitionEvents.js +2 -2
  102. package/lib/ReactTransitionGroup.js +6 -6
  103. package/lib/ReactUpdateQueue.js +295 -0
  104. package/lib/ReactUpdates.js +13 -22
  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 +2 -2
  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 +5 -5
  122. package/lib/ViewportMetrics.js +2 -2
  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 +2 -2
  131. package/lib/createNodesFromMarkup.js +4 -4
  132. package/lib/cx.js +16 -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 +26 -9
  138. package/lib/flattenChildren.js +11 -9
  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 +2 -2
  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 +21 -21
  155. package/lib/invariant.js +1 -1
  156. package/lib/isEventSupported.js +2 -2
  157. package/lib/isNode.js +1 -1
  158. package/lib/isTextInputElement.js +2 -2
  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 +64 -8
  173. package/lib/toArray.js +2 -2
  174. package/lib/traverseAllChildren.js +19 -5
  175. package/lib/update.js +2 -2
  176. package/lib/warning.js +20 -2
  177. package/package.json +1 -1
  178. package/lib/accumulate.js +0 -47
  179. package/lib/copyProperties.js +0 -56
  180. package/lib/merge.js +0 -34
  181. package/lib/mergeInto.js +0 -24
  182. package/lib/monitorCodeUse.js +0 -30
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
@@ -11,9 +11,8 @@
11
11
 
12
12
  /* globals __REACT_DEVTOOLS_GLOBAL_HOOK__*/
13
13
 
14
- "use strict";
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,15 +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");
34
- var ReactRef = require("./ReactRef");
31
+ var ReactReconciler = require("./ReactReconciler");
35
32
  var ReactServerRendering = require("./ReactServerRendering");
36
33
 
37
34
  var assign = require("./Object.assign");
@@ -57,6 +54,7 @@ var React = {
57
54
  count: ReactChildren.count,
58
55
  only: onlyChild
59
56
  },
57
+ Component: ReactComponent,
60
58
  DOM: ReactDOM,
61
59
  PropTypes: ReactPropTypes,
62
60
  initializeTouchEvents: function(shouldUseTouch) {
@@ -65,8 +63,9 @@ var React = {
65
63
  createClass: ReactClass.createClass,
66
64
  createElement: createElement,
67
65
  createFactory: createFactory,
68
- createRef: function() {
69
- return new ReactRef();
66
+ createMixin: function(mixin) {
67
+ // Currently a noop. Will be used to validate and trace mixins.
68
+ return mixin;
70
69
  },
71
70
  constructAndRenderComponent: ReactMount.constructAndRenderComponent,
72
71
  constructAndRenderComponentByID: ReactMount.constructAndRenderComponentByID,
@@ -88,13 +87,10 @@ if (
88
87
  typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
89
88
  typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.inject === 'function') {
90
89
  __REACT_DEVTOOLS_GLOBAL_HOOK__.inject({
91
- Component: ReactComponent,
92
90
  CurrentOwner: ReactCurrentOwner,
93
- DOMComponent: ReactDOMComponent,
94
- DOMPropertyOperations: DOMPropertyOperations,
95
91
  InstanceHandles: ReactInstanceHandles,
96
92
  Mount: ReactMount,
97
- MultiChild: ReactMultiChild,
93
+ Reconciler: ReactReconciler,
98
94
  TextComponent: ReactDOMTextComponent
99
95
  });
100
96
  }
@@ -144,6 +140,6 @@ if ("production" !== process.env.NODE_ENV) {
144
140
  }
145
141
  }
146
142
 
147
- React.version = '0.13.0-alpha.1';
143
+ React.version = '0.13.0-rc1';
148
144
 
149
145
  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
@@ -9,7 +9,7 @@
9
9
  * @providesModule ReactBrowserComponentMixin
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var findDOMNode = require("./findDOMNode");
15
15
 
@@ -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
@@ -10,7 +10,7 @@
10
10
  * @typechecks static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var EventConstants = require("./EventConstants");
16
16
  var EventPluginHub = require("./EventPluginHub");
@@ -126,7 +126,7 @@ var topEventMapping = {
126
126
  /**
127
127
  * To ensure no conflicts with other potential React instances on the page
128
128
  */
129
- var topListenersIDKey = "_reactListenersID" + String(Math.random()).slice(2);
129
+ var topListenersIDKey = '_reactListenersID' + String(Math.random()).slice(2);
130
130
 
131
131
  function getListeningForDocument(mountAt) {
132
132
  // In IE8, `mountAt` is a host object and doesn't have `hasOwnProperty`
@@ -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
@@ -10,7 +10,7 @@
10
10
  * @providesModule ReactCSSTransitionGroup
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var React = require("./React");
16
16
 
@@ -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
@@ -10,7 +10,7 @@
10
10
  * @providesModule ReactCSSTransitionGroupChild
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var React = require("./React");
16
16
 
@@ -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
 
@@ -64,7 +67,9 @@ var ReactCSSTransitionGroupChild = React.createClass({
64
67
 
65
68
  // Usually this optional callback is used for informing an owner of
66
69
  // a leave animation and telling it to remove the child.
67
- finishCallback && finishCallback();
70
+ if (finishCallback) {
71
+ finishCallback();
72
+ }
68
73
  };
69
74
 
70
75
  ReactTransitionEvents.addEndEventListener(node, endListener);
@@ -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
@@ -10,7 +10,9 @@
10
10
  * @typechecks static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
+
15
+ var ReactReconciler = require("./ReactReconciler");
14
16
 
15
17
  var flattenChildren = require("./flattenChildren");
16
18
  var instantiateReactComponent = require("./instantiateReactComponent");
@@ -67,7 +69,7 @@ var ReactChildReconciler = {
67
69
  // can quickly bailout if nothing has changed.
68
70
  var nextChildren = flattenChildren(nextNestedChildNodes);
69
71
  if (!nextChildren && !prevChildren) {
70
- return;
72
+ return null;
71
73
  }
72
74
  var name;
73
75
  for (name in nextChildren) {
@@ -78,11 +80,13 @@ var ReactChildReconciler = {
78
80
  var prevElement = prevChild && prevChild._currentElement;
79
81
  var nextElement = nextChildren[name];
80
82
  if (shouldUpdateReactComponent(prevElement, nextElement)) {
81
- prevChild.receiveComponent(nextElement, transaction, context);
83
+ ReactReconciler.receiveComponent(
84
+ prevChild, nextElement, transaction, context
85
+ );
82
86
  nextChildren[name] = prevChild;
83
87
  } else {
84
88
  if (prevChild) {
85
- prevChild.unmountComponent();
89
+ ReactReconciler.unmountComponent(prevChild, name);
86
90
  }
87
91
  // The child must be instantiated before it's mounted.
88
92
  var nextChildInstance = instantiateReactComponent(
@@ -96,7 +100,7 @@ var ReactChildReconciler = {
96
100
  for (name in prevChildren) {
97
101
  if (prevChildren.hasOwnProperty(name) &&
98
102
  !(nextChildren && nextChildren.hasOwnProperty(name))) {
99
- prevChildren[name].unmountComponent();
103
+ ReactReconciler.unmountComponent(prevChildren[name]);
100
104
  }
101
105
  }
102
106
  return nextChildren;
@@ -112,7 +116,7 @@ var ReactChildReconciler = {
112
116
  unmountChildren: function(renderedChildren) {
113
117
  for (var name in renderedChildren) {
114
118
  var renderedChild = renderedChildren[name];
115
- renderedChild.unmountComponent();
119
+ ReactReconciler.unmountComponent(renderedChild);
116
120
  }
117
121
  }
118
122
 
@@ -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) {
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
@@ -9,19 +9,22 @@
9
9
  * @providesModule ReactClass
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
+ var ReactComponent = require("./ReactComponent");
15
+ var ReactCurrentOwner = require("./ReactCurrentOwner");
14
16
  var ReactElement = require("./ReactElement");
15
17
  var ReactErrorUtils = require("./ReactErrorUtils");
16
18
  var ReactInstanceMap = require("./ReactInstanceMap");
19
+ var ReactLifeCycle = require("./ReactLifeCycle");
17
20
  var ReactPropTypeLocations = require("./ReactPropTypeLocations");
18
21
  var ReactPropTypeLocationNames = require("./ReactPropTypeLocationNames");
22
+ var ReactUpdateQueue = require("./ReactUpdateQueue");
19
23
 
20
24
  var assign = require("./Object.assign");
21
25
  var invariant = require("./invariant");
22
26
  var keyMirror = require("./keyMirror");
23
27
  var keyOf = require("./keyOf");
24
- var monitorCodeUse = require("./monitorCodeUse");
25
28
  var warning = require("./warning");
26
29
 
27
30
  var MIXINS_KEY = keyOf({mixins: null});
@@ -324,11 +327,13 @@ var RESERVED_SPEC_KEYS = {
324
327
  }
325
328
  },
326
329
  childContextTypes: function(Constructor, childContextTypes) {
327
- validateTypeDef(
328
- Constructor,
329
- childContextTypes,
330
- ReactPropTypeLocations.childContext
331
- );
330
+ if ("production" !== process.env.NODE_ENV) {
331
+ validateTypeDef(
332
+ Constructor,
333
+ childContextTypes,
334
+ ReactPropTypeLocations.childContext
335
+ );
336
+ }
332
337
  Constructor.childContextTypes = assign(
333
338
  {},
334
339
  Constructor.childContextTypes,
@@ -336,11 +341,13 @@ var RESERVED_SPEC_KEYS = {
336
341
  );
337
342
  },
338
343
  contextTypes: function(Constructor, contextTypes) {
339
- validateTypeDef(
340
- Constructor,
341
- contextTypes,
342
- ReactPropTypeLocations.context
343
- );
344
+ if ("production" !== process.env.NODE_ENV) {
345
+ validateTypeDef(
346
+ Constructor,
347
+ contextTypes,
348
+ ReactPropTypeLocations.context
349
+ );
350
+ }
344
351
  Constructor.contextTypes = assign(
345
352
  {},
346
353
  Constructor.contextTypes,
@@ -362,11 +369,13 @@ var RESERVED_SPEC_KEYS = {
362
369
  }
363
370
  },
364
371
  propTypes: function(Constructor, propTypes) {
365
- validateTypeDef(
366
- Constructor,
367
- propTypes,
368
- ReactPropTypeLocations.prop
369
- );
372
+ if ("production" !== process.env.NODE_ENV) {
373
+ validateTypeDef(
374
+ Constructor,
375
+ propTypes,
376
+ ReactPropTypeLocations.prop
377
+ );
378
+ }
370
379
  Constructor.propTypes = assign(
371
380
  {},
372
381
  Constructor.propTypes,
@@ -381,14 +390,16 @@ var RESERVED_SPEC_KEYS = {
381
390
  function validateTypeDef(Constructor, typeDef, location) {
382
391
  for (var propName in typeDef) {
383
392
  if (typeDef.hasOwnProperty(propName)) {
384
- ("production" !== process.env.NODE_ENV ? invariant(
385
- typeof typeDef[propName] == 'function',
393
+ // use a warning instead of an invariant so components
394
+ // don't show up in prod but not in __DEV__
395
+ ("production" !== process.env.NODE_ENV ? warning(
396
+ typeof typeDef[propName] === 'function',
386
397
  '%s: %s type `%s` is invalid; it must be a function, usually from ' +
387
398
  'React.PropTypes.',
388
399
  Constructor.displayName || 'ReactClass',
389
400
  ReactPropTypeLocationNames[location],
390
401
  propName
391
- ) : invariant(typeof typeDef[propName] == 'function'));
402
+ ) : null);
392
403
  }
393
404
  }
394
405
  }
@@ -644,23 +655,26 @@ function bindAutoBindMethod(component, method) {
644
655
  boundMethod.__reactBoundArguments = null;
645
656
  var componentName = component.constructor.displayName;
646
657
  var _bind = boundMethod.bind;
658
+ /* eslint-disable block-scoped-var, no-undef */
647
659
  boundMethod.bind = function(newThis ) {for (var args=[],$__0=1,$__1=arguments.length;$__0<$__1;$__0++) args.push(arguments[$__0]);
648
660
  // User is trying to bind() an autobound method; we effectively will
649
661
  // ignore the value of "this" that the user is trying to use, so
650
662
  // let's warn.
651
663
  if (newThis !== component && newThis !== null) {
652
- monitorCodeUse('react_bind_warning', { component: componentName });
653
- console.warn(
664
+ ("production" !== process.env.NODE_ENV ? warning(
665
+ false,
654
666
  'bind(): React component methods may only be bound to the ' +
655
- 'component instance. See ' + componentName
656
- );
667
+ 'component instance. See %s',
668
+ componentName
669
+ ) : null);
657
670
  } else if (!args.length) {
658
- monitorCodeUse('react_bind_warning', { component: componentName });
659
- console.warn(
671
+ ("production" !== process.env.NODE_ENV ? warning(
672
+ false,
660
673
  'bind(): You are binding a component method to the component. ' +
661
674
  'React does this for you automatically in a high-performance ' +
662
- 'way, so you can safely remove this call. See ' + componentName
663
- );
675
+ 'way, so you can safely remove this call. See %s',
676
+ componentName
677
+ ) : null);
664
678
  return boundMethod;
665
679
  }
666
680
  var reboundMethod = _bind.apply(boundMethod, arguments);
@@ -668,6 +682,7 @@ function bindAutoBindMethod(component, method) {
668
682
  reboundMethod.__reactBoundMethod = method;
669
683
  reboundMethod.__reactBoundArguments = args;
670
684
  return reboundMethod;
685
+ /* eslint-enable */
671
686
  };
672
687
  }
673
688
  return boundMethod;
@@ -693,88 +708,38 @@ function bindAutoBindMethods(component) {
693
708
  }
694
709
  }
695
710
 
711
+ var typeDeprecationDescriptor = {
712
+ enumerable: false,
713
+ get: function() {
714
+ var displayName = this.displayName || this.name || 'Component';
715
+ ("production" !== process.env.NODE_ENV ? warning(
716
+ false,
717
+ '%s.type is deprecated. Use %s directly to access the class.',
718
+ displayName,
719
+ displayName
720
+ ) : null);
721
+ Object.defineProperty(this, 'type', {
722
+ value: this
723
+ });
724
+ return this;
725
+ }
726
+ };
727
+
696
728
  /**
697
- * @lends {ReactClass.prototype}
729
+ * Add more to the ReactClass base class. These are all legacy features and
730
+ * therefore not already part of the modern ReactComponent.
698
731
  */
699
732
  var ReactClassMixin = {
700
733
 
701
- /**
702
- * Sets a subset of the state. Always use this or `replaceState` to mutate
703
- * state. You should treat `this.state` as immutable.
704
- *
705
- * There is no guarantee that `this.state` will be immediately updated, so
706
- * accessing `this.state` after calling this method may return the old value.
707
- *
708
- * There is no guarantee that calls to `setState` will run synchronously,
709
- * as they may eventually be batched together. You can provide an optional
710
- * callback that will be executed when the call to setState is actually
711
- * completed.
712
- *
713
- * @param {object} partialState Next partial state to be merged with state.
714
- * @param {?function} callback Called after state is updated.
715
- * @final
716
- * @protected
717
- */
718
- setState: function(partialState, callback) {
719
- ("production" !== process.env.NODE_ENV ? invariant(
720
- typeof partialState === 'object' || partialState == null,
721
- 'setState(...): takes an object of state variables to update.'
722
- ) : invariant(typeof partialState === 'object' || partialState == null));
723
- if ("production" !== process.env.NODE_ENV) {
724
- ("production" !== process.env.NODE_ENV ? warning(
725
- partialState != null,
726
- 'setState(...): You passed an undefined or null state object; ' +
727
- 'instead, use forceUpdate().'
728
- ) : null);
729
- }
730
- var internalInstance = ReactInstanceMap.get(this);
731
- ("production" !== process.env.NODE_ENV ? invariant(
732
- internalInstance,
733
- 'setState(...): Can only update a mounted or mounting component.'
734
- ) : invariant(internalInstance));
735
- internalInstance.setState(
736
- partialState, callback && callback.bind(this)
737
- );
738
- },
739
-
740
734
  /**
741
735
  * TODO: This will be deprecated because state should always keep a consistent
742
736
  * type signature and the only use case for this, is to avoid that.
743
737
  */
744
738
  replaceState: function(newState, callback) {
745
- var internalInstance = ReactInstanceMap.get(this);
746
- ("production" !== process.env.NODE_ENV ? invariant(
747
- internalInstance,
748
- 'replaceState(...): Can only update a mounted or mounting component.'
749
- ) : invariant(internalInstance));
750
- internalInstance.replaceState(
751
- newState,
752
- callback && callback.bind(this)
753
- );
754
- },
755
-
756
- /**
757
- * Forces an update. This should only be invoked when it is known with
758
- * certainty that we are **not** in a DOM transaction.
759
- *
760
- * You may want to call this when you know that some deeper aspect of the
761
- * component's state has changed but `setState` was not called.
762
- *
763
- * This will not invoke `shouldUpdateComponent`, but it will invoke
764
- * `componentWillUpdate` and `componentDidUpdate`.
765
- *
766
- * @param {?function} callback Called after update is complete.
767
- * @final
768
- * @protected
769
- */
770
- forceUpdate: function(callback) {
771
- var internalInstance = ReactInstanceMap.get(this);
772
- ("production" !== process.env.NODE_ENV ? invariant(
773
- internalInstance,
774
- 'forceUpdate(...): Can only force an update on mounted or mounting ' +
775
- 'components.'
776
- ) : invariant(internalInstance));
777
- internalInstance.forceUpdate(callback && callback.bind(this));
739
+ ReactUpdateQueue.enqueueReplaceState(this, newState);
740
+ if (callback) {
741
+ ReactUpdateQueue.enqueueCallback(this, callback);
742
+ }
778
743
  },
779
744
 
780
745
  /**
@@ -784,10 +749,26 @@ var ReactClassMixin = {
784
749
  * @final
785
750
  */
786
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
+ }
787
767
  var internalInstance = ReactInstanceMap.get(this);
788
- // In theory, isMounted is always true if it exists in the map.
789
- // TODO: Remove the internal isMounted method.
790
- return internalInstance && internalInstance.isMounted();
768
+ return (
769
+ internalInstance &&
770
+ internalInstance !== ReactLifeCycle.currentlyMountingInstance
771
+ );
791
772
  },
792
773
 
793
774
  /**
@@ -800,15 +781,10 @@ var ReactClassMixin = {
800
781
  * @deprecated
801
782
  */
802
783
  setProps: function(partialProps, callback) {
803
- var internalInstance = ReactInstanceMap.get(this);
804
- ("production" !== process.env.NODE_ENV ? invariant(
805
- internalInstance,
806
- 'setProps(...): Can only update a mounted component.'
807
- ) : invariant(internalInstance));
808
- internalInstance.setProps(
809
- partialProps,
810
- callback && callback.bind(this)
811
- );
784
+ ReactUpdateQueue.enqueueSetProps(this, partialProps);
785
+ if (callback) {
786
+ ReactUpdateQueue.enqueueCallback(this, callback);
787
+ }
812
788
  },
813
789
 
814
790
  /**
@@ -821,16 +797,17 @@ var ReactClassMixin = {
821
797
  * @deprecated
822
798
  */
823
799
  replaceProps: function(newProps, callback) {
824
- ReactInstanceMap.get(this).replaceProps(
825
- newProps,
826
- callback && callback.bind(this)
827
- );
800
+ ReactUpdateQueue.enqueueReplaceProps(this, newProps);
801
+ if (callback) {
802
+ ReactUpdateQueue.enqueueCallback(this, callback);
803
+ }
828
804
  }
829
805
  };
830
806
 
831
- var ReactClassBase = function() {};
807
+ var ReactClassComponent = function() {};
832
808
  assign(
833
- ReactClassBase.prototype,
809
+ ReactClassComponent.prototype,
810
+ ReactComponent.prototype,
834
811
  ReactClassMixin
835
812
  );
836
813
 
@@ -849,16 +826,49 @@ var ReactClass = {
849
826
  * @public
850
827
  */
851
828
  createClass: function(spec) {
852
- var Constructor = function(props) {
829
+ var Constructor = function(props, context) {
853
830
  // This constructor is overridden by mocks. The argument is used
854
831
  // by mocks to assert on what gets mounted.
855
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
+
856
841
  // Wire up auto-binding
857
842
  if (this.__reactAutoBindMap) {
858
843
  bindAutoBindMethods(this);
859
844
  }
845
+
846
+ this.props = props;
847
+ this.context = context;
848
+ this.state = null;
849
+
850
+ // ReactClasses doesn't have constructors. Instead, they use the
851
+ // getInitialState and componentWillMount methods for initialization.
852
+
853
+ var initialState = this.getInitialState ? this.getInitialState() : null;
854
+ if ("production" !== process.env.NODE_ENV) {
855
+ // We allow auto-mocks to proceed as if they're returning null.
856
+ if (typeof initialState === 'undefined' &&
857
+ this.getInitialState._isMockFunction) {
858
+ // This is probably bad practice. Consider warning here and
859
+ // deprecating this convenience.
860
+ initialState = null;
861
+ }
862
+ }
863
+ ("production" !== process.env.NODE_ENV ? invariant(
864
+ typeof initialState === 'object' && !Array.isArray(initialState),
865
+ '%s.getInitialState(): must return an object or null',
866
+ Constructor.displayName || 'ReactCompositeComponent'
867
+ ) : invariant(typeof initialState === 'object' && !Array.isArray(initialState)));
868
+
869
+ this.state = initialState;
860
870
  };
861
- Constructor.prototype = new ReactClassBase();
871
+ Constructor.prototype = new ReactClassComponent();
862
872
  Constructor.prototype.constructor = Constructor;
863
873
 
864
874
  injectedMixins.forEach(
@@ -872,24 +882,33 @@ var ReactClass = {
872
882
  Constructor.defaultProps = Constructor.getDefaultProps();
873
883
  }
874
884
 
885
+ if ("production" !== process.env.NODE_ENV) {
886
+ // This is a tag to indicate that the use of these method names is ok,
887
+ // since it's used with createClass. If it's not, then it's likely a
888
+ // mistake so we'll warn you to use the static property, property
889
+ // initializer or constructor respectively.
890
+ if (Constructor.getDefaultProps) {
891
+ Constructor.getDefaultProps.isReactClassApproved = {};
892
+ }
893
+ if (Constructor.prototype.getInitialState) {
894
+ Constructor.prototype.getInitialState.isReactClassApproved = {};
895
+ }
896
+ }
897
+
875
898
  ("production" !== process.env.NODE_ENV ? invariant(
876
899
  Constructor.prototype.render,
877
900
  'createClass(...): Class specification must implement a `render` method.'
878
901
  ) : invariant(Constructor.prototype.render));
879
902
 
880
903
  if ("production" !== process.env.NODE_ENV) {
881
- if (Constructor.prototype.componentShouldUpdate) {
882
- monitorCodeUse(
883
- 'react_component_should_update_warning',
884
- { component: spec.displayName }
885
- );
886
- console.warn(
887
- (spec.displayName || 'A component') + ' has a method called ' +
888
- 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' +
889
- 'The name is phrased as a question because the function is ' +
890
- 'expected to return a value.'
891
- );
892
- }
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);
893
912
  }
894
913
 
895
914
  // Reduce time spent doing lookups by setting these on the prototype.
@@ -899,8 +918,15 @@ var ReactClass = {
899
918
  }
900
919
  }
901
920
 
902
- // Legacy hook TODO: Warn if this is accessed
921
+ // Legacy hook
903
922
  Constructor.type = Constructor;
923
+ if ("production" !== process.env.NODE_ENV) {
924
+ try {
925
+ Object.defineProperty(Constructor, 'type', typeDeprecationDescriptor);
926
+ } catch (x) {
927
+ // IE will fail on defineProperty (es5-shim/sham too)
928
+ }
929
+ }
904
930
 
905
931
  return Constructor;
906
932
  },