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
@@ -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 DOMPropertyOperations = require("./DOMPropertyOperations");
16
16
  var ReactComponentBrowserEnvironment =
@@ -18,8 +18,7 @@ var ReactComponentBrowserEnvironment =
18
18
  var ReactDOMComponent = require("./ReactDOMComponent");
19
19
 
20
20
  var assign = require("./Object.assign");
21
- var escapeTextForBrowser = require("./escapeTextForBrowser");
22
- var invariant = require("./invariant");
21
+ var escapeTextContentForBrowser = require("./escapeTextContentForBrowser");
23
22
 
24
23
  /**
25
24
  * Text nodes violate a couple assumptions that React makes about components:
@@ -67,7 +66,7 @@ assign(ReactDOMTextComponent.prototype, {
67
66
  */
68
67
  mountComponent: function(rootID, transaction, context) {
69
68
  this._rootNodeID = rootID;
70
- var escapedText = escapeTextForBrowser(this._stringText);
69
+ var escapedText = escapeTextContentForBrowser(this._stringText);
71
70
 
72
71
  if (transaction.renderToStaticMarkup) {
73
72
  // Normally we'd wrap this in a `span` for the reasons stated above, but
@@ -107,15 +106,7 @@ assign(ReactDOMTextComponent.prototype, {
107
106
  }
108
107
  },
109
108
 
110
- updateComponent: function() {
111
- ("production" !== process.env.NODE_ENV ? invariant(
112
- false,
113
- 'ReactDOMTextComponent: updateComponent() should never be called'
114
- ) : invariant(false));
115
- },
116
-
117
109
  unmountComponent: function() {
118
- // TODO: Is this necessary?
119
110
  ReactComponentBrowserEnvironment.unmountIDFromEnvironment(this._rootNodeID);
120
111
  }
121
112
 
@@ -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 ReactDOMTextarea
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var AutoFocusMixin = require("./AutoFocusMixin");
15
15
  var DOMPropertyOperations = require("./DOMPropertyOperations");
@@ -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 ReactDefaultBatchingStrategy
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var ReactUpdates = require("./ReactUpdates");
15
15
  var Transaction = require("./Transaction");
@@ -54,16 +54,16 @@ var ReactDefaultBatchingStrategy = {
54
54
  * Call the provided function in a context within which calls to `setState`
55
55
  * and friends are batched such that components aren't updated unnecessarily.
56
56
  */
57
- batchedUpdates: function(callback, a, b) {
57
+ batchedUpdates: function(callback, a, b, c, d) {
58
58
  var alreadyBatchingUpdates = ReactDefaultBatchingStrategy.isBatchingUpdates;
59
59
 
60
60
  ReactDefaultBatchingStrategy.isBatchingUpdates = true;
61
61
 
62
62
  // The code is written this way to avoid extra allocations
63
63
  if (alreadyBatchingUpdates) {
64
- callback(a, b);
64
+ callback(a, b, c, d);
65
65
  } else {
66
- transaction.perform(callback, null, a, b);
66
+ transaction.perform(callback, null, a, b, c, d);
67
67
  }
68
68
  }
69
69
  };
@@ -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 ReactDefaultInjection
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var BeforeInputEventPlugin = require("./BeforeInputEventPlugin");
15
15
  var ChangeEventPlugin = require("./ChangeEventPlugin");
@@ -20,6 +20,7 @@ var ExecutionEnvironment = require("./ExecutionEnvironment");
20
20
  var HTMLDOMPropertyConfig = require("./HTMLDOMPropertyConfig");
21
21
  var MobileSafariClickEventPlugin = require("./MobileSafariClickEventPlugin");
22
22
  var ReactBrowserComponentMixin = require("./ReactBrowserComponentMixin");
23
+ var ReactClass = require("./ReactClass");
23
24
  var ReactComponentBrowserEnvironment =
24
25
  require("./ReactComponentBrowserEnvironment");
25
26
  var ReactDefaultBatchingStrategy = require("./ReactDefaultBatchingStrategy");
@@ -28,11 +29,13 @@ var ReactDOMButton = require("./ReactDOMButton");
28
29
  var ReactDOMForm = require("./ReactDOMForm");
29
30
  var ReactDOMImg = require("./ReactDOMImg");
30
31
  var ReactDOMIDOperations = require("./ReactDOMIDOperations");
32
+ var ReactDOMIframe = require("./ReactDOMIframe");
31
33
  var ReactDOMInput = require("./ReactDOMInput");
32
34
  var ReactDOMOption = require("./ReactDOMOption");
33
35
  var ReactDOMSelect = require("./ReactDOMSelect");
34
36
  var ReactDOMTextarea = require("./ReactDOMTextarea");
35
37
  var ReactDOMTextComponent = require("./ReactDOMTextComponent");
38
+ var ReactElement = require("./ReactElement");
36
39
  var ReactEventListener = require("./ReactEventListener");
37
40
  var ReactInjection = require("./ReactInjection");
38
41
  var ReactInstanceHandles = require("./ReactInstanceHandles");
@@ -45,6 +48,22 @@ var SVGDOMPropertyConfig = require("./SVGDOMPropertyConfig");
45
48
 
46
49
  var createFullPageComponent = require("./createFullPageComponent");
47
50
 
51
+ function autoGenerateWrapperClass(type) {
52
+ return ReactClass.createClass({
53
+ tagName: type.toUpperCase(),
54
+ render: function() {
55
+ return new ReactElement(
56
+ type,
57
+ null,
58
+ null,
59
+ null,
60
+ null,
61
+ this.props
62
+ );
63
+ }
64
+ });
65
+ }
66
+
48
67
  function inject() {
49
68
  ReactInjection.EventEmitter.injectReactEventListener(
50
69
  ReactEventListener
@@ -78,6 +97,10 @@ function inject() {
78
97
  ReactDOMTextComponent
79
98
  );
80
99
 
100
+ ReactInjection.NativeComponent.injectAutoWrapper(
101
+ autoGenerateWrapperClass
102
+ );
103
+
81
104
  // This needs to happen before createFullPageComponent() otherwise the mixin
82
105
  // won't be included.
83
106
  ReactInjection.Class.injectMixin(ReactBrowserComponentMixin);
@@ -85,6 +108,7 @@ function inject() {
85
108
  ReactInjection.NativeComponent.injectComponentClasses({
86
109
  'button': ReactDOMButton,
87
110
  'form': ReactDOMForm,
111
+ 'iframe': ReactDOMIframe,
88
112
  'img': ReactDOMImg,
89
113
  'input': ReactDOMInput,
90
114
  'option': ReactDOMOption,
@@ -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 DOMProperty = require("./DOMProperty");
16
16
  var ReactDefaultPerfAnalysis = require("./ReactDefaultPerfAnalysis");
@@ -242,10 +242,18 @@ var ReactDefaultPerf = {
242
242
  addValue(entry.inclusive, rootNodeID, totalTime);
243
243
  }
244
244
 
245
+ var displayName = null;
246
+ if (this._instance.constructor.displayName) {
247
+ displayName = this._instance.constructor.displayName;
248
+ } else if (this._currentElement.type) {
249
+ displayName = this._currentElement.type;
250
+ }
251
+
245
252
  entry.displayNames[rootNodeID] = {
246
- current: this.constructor.displayName,
253
+ current: displayName,
247
254
  owner: this._currentElement._owner ?
248
- this._currentElement._owner.constructor.displayName : '<root>'
255
+ this._currentElement._owner._instance.constructor.displayName :
256
+ '<root>'
249
257
  };
250
258
 
251
259
  return rv;
@@ -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
@@ -9,11 +9,12 @@
9
9
  * @providesModule ReactElement
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var ReactContext = require("./ReactContext");
15
15
  var ReactCurrentOwner = require("./ReactCurrentOwner");
16
16
 
17
+ var assign = require("./Object.assign");
17
18
  var warning = require("./warning");
18
19
 
19
20
  var RESERVED_PROPS = {
@@ -44,8 +45,9 @@ function defineWarningProperty(object, key) {
44
45
  set: function(value) {
45
46
  ("production" !== process.env.NODE_ENV ? warning(
46
47
  false,
47
- 'Don\'t set the ' + key + ' property of the component. ' +
48
- 'Mutate the existing props object instead.'
48
+ 'Don\'t set the %s property of the React element. Instead, ' +
49
+ 'specify the correct value when initially creating the element.',
50
+ key
49
51
  ) : null);
50
52
  this._store[key] = value;
51
53
  }
@@ -106,7 +108,7 @@ var ReactElement = function(type, key, ref, owner, context, props) {
106
108
  // an external backing store so that we can freeze the whole object.
107
109
  // This can be replaced with a WeakMap once they are implemented in
108
110
  // commonly used development environments.
109
- this._store = { props: props };
111
+ this._store = {props: props, originalProps: assign({}, props)};
110
112
 
111
113
  // To make comparing ReactElements easier for testing purposes, we make
112
114
  // the validation flag non-enumerable (where possible, which should
@@ -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
@@ -16,26 +16,35 @@
16
16
  * that support it.
17
17
  */
18
18
 
19
- "use strict";
19
+ 'use strict';
20
20
 
21
21
  var ReactElement = require("./ReactElement");
22
+ var ReactFragment = require("./ReactFragment");
22
23
  var ReactPropTypeLocations = require("./ReactPropTypeLocations");
24
+ var ReactPropTypeLocationNames = require("./ReactPropTypeLocationNames");
23
25
  var ReactCurrentOwner = require("./ReactCurrentOwner");
26
+ var ReactNativeComponent = require("./ReactNativeComponent");
24
27
 
25
28
  var getIteratorFn = require("./getIteratorFn");
26
- var monitorCodeUse = require("./monitorCodeUse");
29
+ var invariant = require("./invariant");
27
30
  var warning = require("./warning");
28
31
 
32
+ function getDeclarationErrorAddendum() {
33
+ if (ReactCurrentOwner.current) {
34
+ var name = ReactCurrentOwner.current.getName();
35
+ if (name) {
36
+ return ' Check the render method of `' + name + '`.';
37
+ }
38
+ }
39
+ return '';
40
+ }
41
+
29
42
  /**
30
43
  * Warn if there's no key explicitly set on dynamic arrays of children or
31
44
  * object keys are not valid. This allows us to keep track of children between
32
45
  * updates.
33
46
  */
34
- var ownerHasKeyUseWarning = {
35
- 'react_key_warning': {},
36
- 'react_numeric_key_warning': {}
37
- };
38
- var ownerHasMonitoredObjectMap = {};
47
+ var ownerHasKeyUseWarning = {};
39
48
 
40
49
  var loggedTypeFailures = {};
41
50
 
@@ -89,7 +98,6 @@ function validateExplicitKey(element, parentType) {
89
98
  element._store.validated = true;
90
99
 
91
100
  warnAndMonitorForKeyUse(
92
- 'react_key_warning',
93
101
  'Each child in an array or iterator should have a unique "key" prop.',
94
102
  element,
95
103
  parentType
@@ -110,7 +118,6 @@ function validatePropertyKey(name, element, parentType) {
110
118
  return;
111
119
  }
112
120
  warnAndMonitorForKeyUse(
113
- 'react_numeric_key_warning',
114
121
  'Child objects should have non-numeric keys so ordering is preserved.',
115
122
  element,
116
123
  parentType
@@ -121,17 +128,18 @@ function validatePropertyKey(name, element, parentType) {
121
128
  * Shared warning and monitoring code for the key warnings.
122
129
  *
123
130
  * @internal
124
- * @param {string} warningID The id used when logging.
125
131
  * @param {string} message The base warning that gets output.
126
132
  * @param {ReactElement} element Component that requires a key.
127
133
  * @param {*} parentType element's parent's type.
128
134
  */
129
- function warnAndMonitorForKeyUse(warningID, message, element, parentType) {
135
+ function warnAndMonitorForKeyUse(message, element, parentType) {
130
136
  var ownerName = getCurrentOwnerDisplayName();
131
137
  var parentName = parentType.displayName || parentType.name;
132
138
 
133
139
  var useName = ownerName || parentName;
134
- var memoizer = ownerHasKeyUseWarning[warningID];
140
+ var memoizer = ownerHasKeyUseWarning[message] || (
141
+ (ownerHasKeyUseWarning[message] = {})
142
+ );
135
143
  if (memoizer.hasOwnProperty(useName)) {
136
144
  return;
137
145
  }
@@ -144,37 +152,17 @@ function warnAndMonitorForKeyUse(warningID, message, element, parentType) {
144
152
  // Usually the current owner is the offender, but if it accepts children as a
145
153
  // property, it may be the creator of the child that's responsible for
146
154
  // assigning it a key.
147
- var childOwnerName = null;
148
155
  if (element &&
149
156
  element._owner &&
150
157
  element._owner !== ReactCurrentOwner.current) {
151
158
  // Name of the component that originally created this child.
152
- childOwnerName = getName(element._owner);
159
+ var childOwnerName = getName(element._owner);
153
160
 
154
161
  message += (" It was passed a child from " + childOwnerName + ".");
155
162
  }
156
163
 
157
164
  message += ' See http://fb.me/react-warning-keys for more information.';
158
- monitorCodeUse(warningID, {
159
- component: useName,
160
- componentOwner: childOwnerName
161
- });
162
- console.warn(message);
163
- }
164
-
165
- /**
166
- * Log that we're using an object map. We're considering deprecating this
167
- * feature and replace it with proper Map and ImmutableMap data structures.
168
- *
169
- * @internal
170
- */
171
- function monitorUseOfObjectMap() {
172
- var currentName = getCurrentOwnerDisplayName() || '';
173
- if (ownerHasMonitoredObjectMap.hasOwnProperty(currentName)) {
174
- return;
175
- }
176
- ownerHasMonitoredObjectMap[currentName] = true;
177
- monitorCodeUse('react_object_map_children');
165
+ ("production" !== process.env.NODE_ENV ? warning(false, message) : null);
178
166
  }
179
167
 
180
168
  /**
@@ -200,19 +188,21 @@ function validateChildKeys(node, parentType) {
200
188
  } else if (node) {
201
189
  var iteratorFn = getIteratorFn(node);
202
190
  // Entry iterators provide implicit keys.
203
- if (iteratorFn && iteratorFn !== node.entries) {
204
- var iterator = iteratorFn.call(node);
205
- var step;
206
- while (!(step = iterator.next()).done) {
207
- if (ReactElement.isValidElement(step.value)) {
208
- validateExplicitKey(step.value, parentType);
191
+ if (iteratorFn) {
192
+ if (iteratorFn !== node.entries) {
193
+ var iterator = iteratorFn.call(node);
194
+ var step;
195
+ while (!(step = iterator.next()).done) {
196
+ if (ReactElement.isValidElement(step.value)) {
197
+ validateExplicitKey(step.value, parentType);
198
+ }
209
199
  }
210
200
  }
211
201
  } else if (typeof node === 'object') {
212
- monitorUseOfObjectMap();
213
- for (var key in node) {
214
- if (node.hasOwnProperty(key)) {
215
- validatePropertyKey(key, node[key], parentType);
202
+ var fragment = ReactFragment.extractIfFragment(node);
203
+ for (var key in fragment) {
204
+ if (fragment.hasOwnProperty(key)) {
205
+ validatePropertyKey(key, fragment[key], parentType);
216
206
  }
217
207
  }
218
208
  }
@@ -236,6 +226,16 @@ function checkPropTypes(componentName, propTypes, props, location) {
236
226
  // fail the render phase where it didn't fail before. So we log it.
237
227
  // After these have been cleaned up, we'll let them throw.
238
228
  try {
229
+ // This is intentionally an invariant that gets caught. It's the same
230
+ // behavior as without this statement except with a better message.
231
+ ("production" !== process.env.NODE_ENV ? invariant(
232
+ typeof propTypes[propName] === 'function',
233
+ '%s: %s type `%s` is invalid; it must be a function, usually from ' +
234
+ 'React.PropTypes.',
235
+ componentName || 'React class',
236
+ ReactPropTypeLocationNames[location],
237
+ propName
238
+ ) : invariant(typeof propTypes[propName] === 'function'));
239
239
  error = propTypes[propName](props, propName, componentName, location);
240
240
  } catch (ex) {
241
241
  error = ex;
@@ -244,11 +244,93 @@ function checkPropTypes(componentName, propTypes, props, location) {
244
244
  // Only monitor this failure once because there tends to be a lot of the
245
245
  // same error.
246
246
  loggedTypeFailures[error.message] = true;
247
- // This will soon use the warning module
248
- monitorCodeUse(
249
- 'react_failed_descriptor_type_check',
250
- { message: error.message }
251
- );
247
+
248
+ var addendum = getDeclarationErrorAddendum(this);
249
+ ("production" !== process.env.NODE_ENV ? warning(false, 'Failed propType: ' + error.message + addendum) : null);
250
+ }
251
+ }
252
+ }
253
+ }
254
+
255
+ var warnedPropsMutations = {};
256
+
257
+ /**
258
+ * Warn about mutating props when setting `propName` on `element`.
259
+ *
260
+ * @param {string} propName The string key within props that was set
261
+ * @param {ReactElement} element
262
+ */
263
+ function warnForPropsMutation(propName, element) {
264
+ var type = element.type;
265
+ var elementName = typeof type === 'string' ? type : type.displayName;
266
+ var ownerName = element._owner ?
267
+ element._owner.getPublicInstance().constructor.displayName : null;
268
+
269
+ var warningKey = propName + '|' + elementName + '|' + ownerName;
270
+ if (warnedPropsMutations.hasOwnProperty(warningKey)) {
271
+ return;
272
+ }
273
+ warnedPropsMutations[warningKey] = true;
274
+
275
+ var elementInfo = '';
276
+ if (elementName) {
277
+ elementInfo = ' <' + elementName + ' />';
278
+ }
279
+ var ownerInfo = '';
280
+ if (ownerName) {
281
+ ownerInfo = ' The element was created by ' + ownerName + '.';
282
+ }
283
+
284
+ ("production" !== process.env.NODE_ENV ? warning(
285
+ false,
286
+ 'Don\'t set .props.%s of the React component%s. ' +
287
+ 'Instead, specify the correct value when ' +
288
+ 'initially creating the element.%s',
289
+ propName,
290
+ elementInfo,
291
+ ownerInfo
292
+ ) : null);
293
+ }
294
+
295
+ // Inline Object.is polyfill
296
+ function is(a, b) {
297
+ if (a !== a) {
298
+ // NaN
299
+ return b !== b;
300
+ }
301
+ if (a === 0 && b === 0) {
302
+ // +-0
303
+ return 1 / a === 1 / b;
304
+ }
305
+ return a === b;
306
+ }
307
+
308
+ /**
309
+ * Given an element, check if its props have been mutated since element
310
+ * creation (or the last call to this function). In particular, check if any
311
+ * new props have been added, which we can't directly catch by defining warning
312
+ * properties on the props object.
313
+ *
314
+ * @param {ReactElement} element
315
+ */
316
+ function checkAndWarnForMutatedProps(element) {
317
+ if (!element._store) {
318
+ // Element was created using `new ReactElement` directly or with
319
+ // `ReactElement.createElement`; skip mutation checking
320
+ return;
321
+ }
322
+
323
+ var originalProps = element._store.originalProps;
324
+ var props = element.props;
325
+
326
+ for (var propName in props) {
327
+ if (props.hasOwnProperty(propName)) {
328
+ if (!originalProps.hasOwnProperty(propName) ||
329
+ !is(originalProps[propName], props[propName])) {
330
+ warnForPropsMutation(propName, element);
331
+
332
+ // Copy over the new value so that the two props objects match again
333
+ originalProps[propName] = props[propName];
252
334
  }
253
335
  }
254
336
  }
@@ -256,6 +338,8 @@ function checkPropTypes(componentName, propTypes, props, location) {
256
338
 
257
339
  var ReactElementValidator = {
258
340
 
341
+ checkAndWarnForMutatedProps: checkAndWarnForMutatedProps,
342
+
259
343
  createElement: function(type, props, children) {
260
344
  // We warn in this case but don't throw. We expect the element creation to
261
345
  // succeed and there will likely be errors in render.
@@ -279,24 +363,33 @@ var ReactElementValidator = {
279
363
  }
280
364
 
281
365
  if (type) {
282
- var name = type.displayName || type.name;
283
- if (type.propTypes) {
284
- checkPropTypes(
285
- name,
286
- type.propTypes,
287
- element.props,
288
- ReactPropTypeLocations.prop
289
- );
366
+ // Extract the component class from the element. Converts string types
367
+ // to a composite class which may have propTypes.
368
+ // TODO: Validating a string's propTypes is not decoupled from the
369
+ // rendering target which is problematic.
370
+ var componentClass = ReactNativeComponent.getComponentClassForElement(
371
+ element
372
+ );
373
+ var name = componentClass.displayName || componentClass.name;
374
+ if ("production" !== process.env.NODE_ENV) {
375
+ if (componentClass.propTypes) {
376
+ checkPropTypes(
377
+ name,
378
+ componentClass.propTypes,
379
+ element.props,
380
+ ReactPropTypeLocations.prop
381
+ );
382
+ }
290
383
  }
291
- if (type.contextTypes) {
292
- checkPropTypes(
293
- name,
294
- type.contextTypes,
295
- element._context,
296
- ReactPropTypeLocations.context
297
- );
384
+ if (typeof componentClass.getDefaultProps === 'function') {
385
+ ("production" !== process.env.NODE_ENV ? warning(
386
+ componentClass.getDefaultProps.isReactClassApproved,
387
+ 'getDefaultProps is only used on classic React.createClass ' +
388
+ 'definitions. Use a static property named `defaultProps` instead.'
389
+ ) : null);
298
390
  }
299
391
  }
392
+
300
393
  return element;
301
394
  },
302
395
 
@@ -307,6 +400,33 @@ var ReactElementValidator = {
307
400
  );
308
401
  // Legacy hook TODO: Warn if this is accessed
309
402
  validatedFactory.type = type;
403
+
404
+ if ("production" !== process.env.NODE_ENV) {
405
+ try {
406
+ Object.defineProperty(
407
+ validatedFactory,
408
+ 'type',
409
+ {
410
+ enumerable: false,
411
+ get: function() {
412
+ ("production" !== process.env.NODE_ENV ? warning(
413
+ false,
414
+ 'Factory.type is deprecated. Access the class directly ' +
415
+ 'before passing it to createFactory.'
416
+ ) : null);
417
+ Object.defineProperty(this, 'type', {
418
+ value: type
419
+ });
420
+ return type;
421
+ }
422
+ }
423
+ );
424
+ } catch (x) {
425
+ // IE will fail on defineProperty (es5-shim/sham too)
426
+ }
427
+ }
428
+
429
+
310
430
  return validatedFactory;
311
431
  }
312
432