react 0.12.1 → 0.13.0-beta.1

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 (153) hide show
  1. package/dist/JSXTransformer.js +352 -251
  2. package/dist/react-with-addons.js +5409 -4242
  3. package/dist/react-with-addons.min.js +5 -6
  4. package/dist/react.js +5012 -4136
  5. package/dist/react.min.js +5 -6
  6. package/lib/AutoFocusMixin.js +1 -1
  7. package/lib/BeforeInputEventPlugin.js +389 -112
  8. package/lib/CSSProperty.js +6 -3
  9. package/lib/CSSPropertyOperations.js +57 -10
  10. package/lib/CallbackQueue.js +2 -2
  11. package/lib/ChangeEventPlugin.js +3 -3
  12. package/lib/ClientReactRootIndex.js +1 -1
  13. package/lib/DOMChildrenOperations.js +6 -4
  14. package/lib/DOMProperty.js +1 -1
  15. package/lib/DOMPropertyOperations.js +4 -2
  16. package/lib/Danger.js +7 -6
  17. package/lib/DefaultEventPluginOrder.js +1 -2
  18. package/lib/EnterLeaveEventPlugin.js +1 -1
  19. package/lib/EventConstants.js +1 -1
  20. package/lib/EventPluginHub.js +9 -7
  21. package/lib/EventPluginRegistry.js +1 -1
  22. package/lib/EventPluginUtils.js +1 -1
  23. package/lib/EventPropagators.js +1 -1
  24. package/lib/ExecutionEnvironment.js +2 -3
  25. package/lib/FallbackCompositionState.js +89 -0
  26. package/lib/HTMLDOMPropertyConfig.js +19 -7
  27. package/lib/LinkedStateMixin.js +1 -1
  28. package/lib/LinkedValueUtils.js +3 -3
  29. package/lib/LocalEventTrapMixin.js +9 -2
  30. package/lib/MobileSafariClickEventPlugin.js +1 -1
  31. package/lib/Object.assign.js +3 -1
  32. package/lib/PooledClass.js +1 -1
  33. package/lib/React.js +17 -51
  34. package/lib/ReactBrowserComponentMixin.js +3 -13
  35. package/lib/ReactBrowserEventEmitter.js +4 -6
  36. package/lib/ReactCSSTransitionGroup.js +4 -1
  37. package/lib/ReactCSSTransitionGroupChild.js +12 -2
  38. package/lib/ReactChildReconciler.js +125 -0
  39. package/lib/ReactChildren.js +10 -8
  40. package/lib/ReactClass.js +916 -0
  41. package/lib/ReactComponent.js +81 -404
  42. package/lib/ReactComponentBrowserEnvironment.js +10 -83
  43. package/lib/ReactComponentEnvironment.js +57 -0
  44. package/lib/ReactComponentWithPureRenderMixin.js +1 -1
  45. package/lib/ReactCompositeComponent.js +533 -1132
  46. package/lib/ReactContext.js +6 -2
  47. package/lib/ReactCurrentOwner.js +1 -1
  48. package/lib/ReactDOM.js +3 -8
  49. package/lib/ReactDOMButton.js +5 -6
  50. package/lib/ReactDOMComponent.js +110 -92
  51. package/lib/ReactDOMForm.js +5 -6
  52. package/lib/ReactDOMIDOperations.js +56 -74
  53. package/lib/ReactDOMImg.js +4 -6
  54. package/lib/ReactDOMInput.js +5 -6
  55. package/lib/ReactDOMOption.js +5 -6
  56. package/lib/ReactDOMSelect.js +57 -65
  57. package/lib/ReactDOMSelection.js +6 -2
  58. package/lib/{ReactTextComponent.js → ReactDOMTextComponent.js} +48 -35
  59. package/lib/ReactDOMTextarea.js +5 -6
  60. package/lib/ReactDefaultBatchingStrategy.js +4 -4
  61. package/lib/ReactDefaultInjection.js +14 -8
  62. package/lib/ReactDefaultPerf.js +16 -7
  63. package/lib/ReactDefaultPerfAnalysis.js +1 -1
  64. package/lib/ReactElement.js +23 -15
  65. package/lib/ReactElementValidator.js +209 -57
  66. package/lib/ReactEmptyComponent.js +29 -11
  67. package/lib/ReactEventEmitterMixin.js +1 -1
  68. package/lib/ReactEventListener.js +3 -4
  69. package/lib/ReactInjection.js +7 -5
  70. package/lib/ReactInputSelection.js +3 -4
  71. package/lib/ReactInstanceHandles.js +3 -2
  72. package/lib/ReactInstanceMap.js +47 -0
  73. package/lib/ReactLifeCycle.js +35 -0
  74. package/lib/ReactLink.js +1 -1
  75. package/lib/ReactMarkupChecksum.js +1 -1
  76. package/lib/ReactMount.js +239 -68
  77. package/lib/ReactMultiChild.js +49 -47
  78. package/lib/ReactMultiChildUpdateTypes.js +1 -1
  79. package/lib/ReactNativeComponent.js +72 -25
  80. package/lib/ReactOwner.js +4 -48
  81. package/lib/ReactPerf.js +21 -1
  82. package/lib/ReactPropTransferer.js +2 -57
  83. package/lib/ReactPropTypeLocationNames.js +1 -1
  84. package/lib/ReactPropTypeLocations.js +1 -1
  85. package/lib/ReactPropTypes.js +14 -22
  86. package/lib/ReactPutListenerQueue.js +1 -1
  87. package/lib/ReactReconcileTransaction.js +1 -1
  88. package/lib/ReactReconciler.js +107 -0
  89. package/lib/ReactRef.js +70 -0
  90. package/lib/ReactRootIndex.js +1 -1
  91. package/lib/ReactServerRendering.js +5 -3
  92. package/lib/ReactServerRenderingTransaction.js +1 -1
  93. package/lib/ReactStateSetters.js +1 -1
  94. package/lib/ReactTestUtils.js +112 -26
  95. package/lib/ReactTransitionChildMapping.js +1 -1
  96. package/lib/ReactTransitionEvents.js +1 -1
  97. package/lib/ReactTransitionGroup.js +48 -7
  98. package/lib/ReactUpdateQueue.js +264 -0
  99. package/lib/ReactUpdates.js +48 -61
  100. package/lib/ReactWithAddons.js +1 -1
  101. package/lib/SVGDOMPropertyConfig.js +1 -1
  102. package/lib/SelectEventPlugin.js +3 -3
  103. package/lib/ServerReactRootIndex.js +1 -1
  104. package/lib/SimpleEventPlugin.js +1 -1
  105. package/lib/SyntheticClipboardEvent.js +1 -2
  106. package/lib/SyntheticCompositionEvent.js +1 -2
  107. package/lib/SyntheticDragEvent.js +1 -1
  108. package/lib/SyntheticEvent.js +11 -3
  109. package/lib/SyntheticFocusEvent.js +1 -1
  110. package/lib/SyntheticInputEvent.js +1 -2
  111. package/lib/SyntheticKeyboardEvent.js +1 -1
  112. package/lib/SyntheticMouseEvent.js +2 -4
  113. package/lib/SyntheticTouchEvent.js +1 -1
  114. package/lib/SyntheticUIEvent.js +1 -1
  115. package/lib/SyntheticWheelEvent.js +1 -1
  116. package/lib/Transaction.js +3 -3
  117. package/lib/ViewportMetrics.js +2 -5
  118. package/lib/accumulateInto.js +1 -1
  119. package/lib/adler32.js +1 -1
  120. package/lib/cloneWithProps.js +3 -3
  121. package/lib/copyProperties.js +2 -0
  122. package/lib/createFullPageComponent.js +3 -3
  123. package/lib/dangerousStyleValue.js +1 -1
  124. package/lib/escapeTextForBrowser.js +6 -6
  125. package/lib/findDOMNode.js +51 -0
  126. package/lib/flattenChildren.js +11 -22
  127. package/lib/forEachAccumulated.js +1 -1
  128. package/lib/getEventCharCode.js +1 -1
  129. package/lib/getEventKey.js +1 -1
  130. package/lib/getEventModifierState.js +1 -1
  131. package/lib/getEventTarget.js +1 -1
  132. package/lib/getIteratorFn.js +42 -0
  133. package/lib/getNodeForCharacterOffset.js +2 -2
  134. package/lib/getReactRootElementInContainer.js +1 -1
  135. package/lib/getTextContentAccessor.js +1 -1
  136. package/lib/instantiateReactComponent.js +85 -67
  137. package/lib/isEventSupported.js +1 -1
  138. package/lib/isNode.js +3 -4
  139. package/lib/isTextInputElement.js +2 -3
  140. package/lib/joinClasses.js +1 -1
  141. package/lib/keyMirror.js +1 -1
  142. package/lib/memoizeStringOnly.js +4 -5
  143. package/lib/onlyChild.js +1 -1
  144. package/lib/setInnerHTML.js +12 -1
  145. package/lib/shallowEqual.js +1 -1
  146. package/lib/shouldUpdateReactComponent.js +48 -6
  147. package/lib/traverseAllChildren.js +111 -55
  148. package/lib/update.js +1 -1
  149. package/lib/warning.js +12 -1
  150. package/package.json +1 -1
  151. package/lib/CompositionEventPlugin.js +0 -257
  152. package/lib/ReactLegacyElement.js +0 -243
  153. package/lib/deprecated.js +0 -47
@@ -9,7 +9,7 @@
9
9
  * @providesModule ReactDOMSelection
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var ExecutionEnvironment = require("./ExecutionEnvironment");
15
15
 
@@ -189,7 +189,11 @@ function setModernOffsets(node, offsets) {
189
189
  }
190
190
  }
191
191
 
192
- var useIEOffsets = ExecutionEnvironment.canUseDOM && document.selection;
192
+ var useIEOffsets = (
193
+ ExecutionEnvironment.canUseDOM &&
194
+ 'selection' in document &&
195
+ !('getSelection' in window)
196
+ );
193
197
 
194
198
  var ReactDOMSelection = {
195
199
  /**
@@ -6,18 +6,20 @@
6
6
  * LICENSE file in the root directory of this source tree. An additional grant
7
7
  * of patent rights can be found in the PATENTS file in the same directory.
8
8
  *
9
- * @providesModule ReactTextComponent
9
+ * @providesModule ReactDOMTextComponent
10
10
  * @typechecks static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var DOMPropertyOperations = require("./DOMPropertyOperations");
16
- var ReactComponent = require("./ReactComponent");
17
- var ReactElement = require("./ReactElement");
16
+ var ReactComponentBrowserEnvironment =
17
+ require("./ReactComponentBrowserEnvironment");
18
+ var ReactDOMComponent = require("./ReactDOMComponent");
18
19
 
19
20
  var assign = require("./Object.assign");
20
21
  var escapeTextForBrowser = require("./escapeTextForBrowser");
22
+ var invariant = require("./invariant");
21
23
 
22
24
  /**
23
25
  * Text nodes violate a couple assumptions that React makes about components:
@@ -30,15 +32,29 @@ var escapeTextForBrowser = require("./escapeTextForBrowser");
30
32
  *
31
33
  * TODO: Investigate representing React components in the DOM with text nodes.
32
34
  *
33
- * @class ReactTextComponent
35
+ * @class ReactDOMTextComponent
34
36
  * @extends ReactComponent
35
37
  * @internal
36
38
  */
37
- var ReactTextComponent = function(props) {
38
- // This constructor and it's argument is currently used by mocks.
39
+ var ReactDOMTextComponent = function(props) {
40
+ // This constructor and its argument is currently used by mocks.
39
41
  };
40
42
 
41
- assign(ReactTextComponent.prototype, ReactComponent.Mixin, {
43
+ assign(ReactDOMTextComponent.prototype, {
44
+
45
+ /**
46
+ * @param {ReactText} text
47
+ * @internal
48
+ */
49
+ construct: function(text) {
50
+ // TODO: This is really a ReactText (ReactNode), not a ReactElement
51
+ this._currentElement = text;
52
+ this._stringText = '' + text;
53
+
54
+ // Properties
55
+ this._rootNodeID = null;
56
+ this._mountIndex = 0;
57
+ },
42
58
 
43
59
  /**
44
60
  * Creates the markup for this text node. This node is not intended to have
@@ -46,19 +62,12 @@ assign(ReactTextComponent.prototype, ReactComponent.Mixin, {
46
62
  *
47
63
  * @param {string} rootID DOM ID of the root node.
48
64
  * @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
49
- * @param {number} mountDepth number of components in the owner hierarchy
50
65
  * @return {string} Markup for this text node.
51
66
  * @internal
52
67
  */
53
- mountComponent: function(rootID, transaction, mountDepth) {
54
- ReactComponent.Mixin.mountComponent.call(
55
- this,
56
- rootID,
57
- transaction,
58
- mountDepth
59
- );
60
-
61
- var escapedText = escapeTextForBrowser(this.props);
68
+ mountComponent: function(rootID, transaction, context) {
69
+ this._rootNodeID = rootID;
70
+ var escapedText = escapeTextForBrowser(this._stringText);
62
71
 
63
72
  if (transaction.renderToStaticMarkup) {
64
73
  // Normally we'd wrap this in a `span` for the reasons stated above, but
@@ -77,28 +86,32 @@ assign(ReactTextComponent.prototype, ReactComponent.Mixin, {
77
86
  /**
78
87
  * Updates this component by updating the text content.
79
88
  *
80
- * @param {object} nextComponent Contains the next text content.
89
+ * @param {ReactText} nextText The next text content
81
90
  * @param {ReactReconcileTransaction} transaction
82
91
  * @internal
83
92
  */
84
- receiveComponent: function(nextComponent, transaction) {
85
- var nextProps = nextComponent.props;
86
- if (nextProps !== this.props) {
87
- this.props = nextProps;
88
- ReactComponent.BackendIDOperations.updateTextContentByID(
89
- this._rootNodeID,
90
- nextProps
91
- );
93
+ receiveComponent: function(nextText, transaction) {
94
+ if (nextText !== this._currentElement) {
95
+ this._currentElement = nextText;
96
+ var nextStringText = '' + nextText;
97
+ if (nextStringText !== this._stringText) {
98
+ // TODO: Save this as pending props and use performUpdateIfNecessary
99
+ // and/or updateComponent to do the actual update for consistency with
100
+ // other component types?
101
+ this._stringText = nextStringText;
102
+ ReactDOMComponent.BackendIDOperations.updateTextContentByID(
103
+ this._rootNodeID,
104
+ nextStringText
105
+ );
106
+ }
92
107
  }
108
+ },
109
+
110
+ unmountComponent: function() {
111
+ // TODO: Is this necessary?
112
+ ReactComponentBrowserEnvironment.unmountIDFromEnvironment(this._rootNodeID);
93
113
  }
94
114
 
95
115
  });
96
116
 
97
- var ReactTextComponentFactory = function(text) {
98
- // Bypass validation and configuration
99
- return new ReactElement(ReactTextComponent, null, null, null, null, text);
100
- };
101
-
102
- ReactTextComponentFactory.type = ReactTextComponent;
103
-
104
- module.exports = ReactTextComponentFactory;
117
+ module.exports = ReactDOMTextComponent;
@@ -9,15 +9,14 @@
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");
16
16
  var LinkedValueUtils = require("./LinkedValueUtils");
17
17
  var ReactBrowserComponentMixin = require("./ReactBrowserComponentMixin");
18
- var ReactCompositeComponent = require("./ReactCompositeComponent");
18
+ var ReactClass = require("./ReactClass");
19
19
  var ReactElement = require("./ReactElement");
20
- var ReactDOM = require("./ReactDOM");
21
20
  var ReactUpdates = require("./ReactUpdates");
22
21
 
23
22
  var assign = require("./Object.assign");
@@ -25,8 +24,7 @@ var invariant = require("./invariant");
25
24
 
26
25
  var warning = require("./warning");
27
26
 
28
- // Store a reference to the <textarea> `ReactDOMComponent`. TODO: use string
29
- var textarea = ReactElement.createFactory(ReactDOM.textarea.type);
27
+ var textarea = ReactElement.createFactory('textarea');
30
28
 
31
29
  function forceUpdateIfMounted() {
32
30
  /*jshint validthis:true */
@@ -50,8 +48,9 @@ function forceUpdateIfMounted() {
50
48
  * The rendered element will be initialized with an empty value, the prop
51
49
  * `defaultValue` if specified, or the children content (deprecated).
52
50
  */
53
- var ReactDOMTextarea = ReactCompositeComponent.createClass({
51
+ var ReactDOMTextarea = ReactClass.createClass({
54
52
  displayName: 'ReactDOMTextarea',
53
+ tagName: 'TEXTAREA',
55
54
 
56
55
  mixins: [AutoFocusMixin, LinkedValueUtils.Mixin, ReactBrowserComponentMixin],
57
56
 
@@ -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
  };
@@ -9,12 +9,11 @@
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");
16
16
  var ClientReactRootIndex = require("./ClientReactRootIndex");
17
- var CompositionEventPlugin = require("./CompositionEventPlugin");
18
17
  var DefaultEventPluginOrder = require("./DefaultEventPluginOrder");
19
18
  var EnterLeaveEventPlugin = require("./EnterLeaveEventPlugin");
20
19
  var ExecutionEnvironment = require("./ExecutionEnvironment");
@@ -28,14 +27,17 @@ var ReactDOMComponent = require("./ReactDOMComponent");
28
27
  var ReactDOMButton = require("./ReactDOMButton");
29
28
  var ReactDOMForm = require("./ReactDOMForm");
30
29
  var ReactDOMImg = require("./ReactDOMImg");
30
+ var ReactDOMIDOperations = require("./ReactDOMIDOperations");
31
31
  var ReactDOMInput = require("./ReactDOMInput");
32
32
  var ReactDOMOption = require("./ReactDOMOption");
33
33
  var ReactDOMSelect = require("./ReactDOMSelect");
34
34
  var ReactDOMTextarea = require("./ReactDOMTextarea");
35
+ var ReactDOMTextComponent = require("./ReactDOMTextComponent");
35
36
  var ReactEventListener = require("./ReactEventListener");
36
37
  var ReactInjection = require("./ReactInjection");
37
38
  var ReactInstanceHandles = require("./ReactInstanceHandles");
38
39
  var ReactMount = require("./ReactMount");
40
+ var ReactReconcileTransaction = require("./ReactReconcileTransaction");
39
41
  var SelectEventPlugin = require("./SelectEventPlugin");
40
42
  var ServerReactRootIndex = require("./ServerReactRootIndex");
41
43
  var SimpleEventPlugin = require("./SimpleEventPlugin");
@@ -63,7 +65,6 @@ function inject() {
63
65
  SimpleEventPlugin: SimpleEventPlugin,
64
66
  EnterLeaveEventPlugin: EnterLeaveEventPlugin,
65
67
  ChangeEventPlugin: ChangeEventPlugin,
66
- CompositionEventPlugin: CompositionEventPlugin,
67
68
  MobileSafariClickEventPlugin: MobileSafariClickEventPlugin,
68
69
  SelectEventPlugin: SelectEventPlugin,
69
70
  BeforeInputEventPlugin: BeforeInputEventPlugin
@@ -73,6 +74,14 @@ function inject() {
73
74
  ReactDOMComponent
74
75
  );
75
76
 
77
+ ReactInjection.NativeComponent.injectTextComponentClass(
78
+ ReactDOMTextComponent
79
+ );
80
+
81
+ // This needs to happen before createFullPageComponent() otherwise the mixin
82
+ // won't be included.
83
+ ReactInjection.Class.injectMixin(ReactBrowserComponentMixin);
84
+
76
85
  ReactInjection.NativeComponent.injectComponentClasses({
77
86
  'button': ReactDOMButton,
78
87
  'form': ReactDOMForm,
@@ -87,17 +96,13 @@ function inject() {
87
96
  'body': createFullPageComponent('body')
88
97
  });
89
98
 
90
- // This needs to happen after createFullPageComponent() otherwise the mixin
91
- // gets double injected.
92
- ReactInjection.CompositeComponent.injectMixin(ReactBrowserComponentMixin);
93
-
94
99
  ReactInjection.DOMProperty.injectDOMPropertyConfig(HTMLDOMPropertyConfig);
95
100
  ReactInjection.DOMProperty.injectDOMPropertyConfig(SVGDOMPropertyConfig);
96
101
 
97
102
  ReactInjection.EmptyComponent.injectEmptyComponent('noscript');
98
103
 
99
104
  ReactInjection.Updates.injectReconcileTransaction(
100
- ReactComponentBrowserEnvironment.ReactReconcileTransaction
105
+ ReactReconcileTransaction
101
106
  );
102
107
  ReactInjection.Updates.injectBatchingStrategy(
103
108
  ReactDefaultBatchingStrategy
@@ -110,6 +115,7 @@ function inject() {
110
115
  );
111
116
 
112
117
  ReactInjection.Component.injectEnvironment(ReactComponentBrowserEnvironment);
118
+ ReactInjection.DOMComponent.injectIDOperations(ReactDOMIDOperations);
113
119
 
114
120
  if ("production" !== process.env.NODE_ENV) {
115
121
  var url = (ExecutionEnvironment.canUseDOM && window.location.href) || '';
@@ -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");
@@ -169,7 +169,7 @@ var ReactDefaultPerf = {
169
169
  rv = func.apply(this, args);
170
170
  totalTime = performanceNow() - start;
171
171
 
172
- if (fnName === 'mountImageIntoNode') {
172
+ if (fnName === '_mountImageIntoNode') {
173
173
  var mountID = ReactMount.getID(args[1]);
174
174
  ReactDefaultPerf._recordWrite(mountID, fnName, totalTime, args[0]);
175
175
  } else if (fnName === 'dangerouslyProcessChildrenUpdates') {
@@ -206,9 +206,9 @@ var ReactDefaultPerf = {
206
206
  }
207
207
  return rv;
208
208
  } else if (moduleName === 'ReactCompositeComponent' && (
209
- fnName === 'mountComponent' ||
210
- fnName === 'updateComponent' || // TODO: receiveComponent()?
211
- fnName === '_renderValidatedComponent')) {
209
+ (// TODO: receiveComponent()?
210
+ (fnName === 'mountComponent' ||
211
+ fnName === 'updateComponent' || fnName === '_renderValidatedComponent')))) {
212
212
 
213
213
  var rootNodeID = fnName === 'mountComponent' ?
214
214
  args[0] :
@@ -242,9 +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,
247
- owner: this._owner ? this._owner.constructor.displayName : '<root>'
253
+ current: displayName,
254
+ owner: this._currentElement._owner ?
255
+ this._currentElement._owner._instance.constructor.displayName :
256
+ '<root>'
248
257
  };
249
258
 
250
259
  return rv;
@@ -14,7 +14,7 @@ var assign = require("./Object.assign");
14
14
  // Don't try to save users less than 1.2ms (a number I made up)
15
15
  var DONT_CARE_THRESHOLD = 1.2;
16
16
  var DOM_OPERATION_TYPES = {
17
- 'mountImageIntoNode': 'set innerHTML',
17
+ '_mountImageIntoNode': 'set innerHTML',
18
18
  INSERT_MARKUP: 'set innerHTML',
19
19
  MOVE_EXISTING: 'move',
20
20
  REMOVE_NODE: 'remove',
@@ -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,21 @@ 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 = { validated: false, props: props };
111
+ this._store = { props: props, originalProps: assign({}, props) };
112
+
113
+ // To make comparing ReactElements easier for testing purposes, we make
114
+ // the validation flag non-enumerable (where possible, which should
115
+ // include every environment we run tests in), so the test framework
116
+ // ignores it.
117
+ try {
118
+ Object.defineProperty(this._store, 'validated', {
119
+ configurable: false,
120
+ enumerable: false,
121
+ writable: true
122
+ });
123
+ } catch (x) {
124
+ }
125
+ this._store.validated = false;
110
126
 
111
127
  // We're not allowed to set props directly on the object so we early
112
128
  // return and rely on the prototype membrane to forward to the backing
@@ -141,16 +157,7 @@ ReactElement.createElement = function(type, config, children) {
141
157
 
142
158
  if (config != null) {
143
159
  ref = config.ref === undefined ? null : config.ref;
144
- if ("production" !== process.env.NODE_ENV) {
145
- ("production" !== process.env.NODE_ENV ? warning(
146
- config.key !== null,
147
- 'createElement(...): Encountered component with a `key` of null. In ' +
148
- 'a future version, this will be treated as equivalent to the string ' +
149
- '\'null\'; instead, provide an explicit key or use undefined.'
150
- ) : null);
151
- }
152
- // TODO: Change this back to `config.key === undefined`
153
- key = config.key == null ? null : '' + config.key;
160
+ key = config.key === undefined ? null : '' + config.key;
154
161
  // Remaining properties are added to a new props object
155
162
  for (propName in config) {
156
163
  if (config.hasOwnProperty(propName) &&
@@ -174,7 +181,7 @@ ReactElement.createElement = function(type, config, children) {
174
181
  }
175
182
 
176
183
  // Resolve default props
177
- if (type.defaultProps) {
184
+ if (type && type.defaultProps) {
178
185
  var defaultProps = type.defaultProps;
179
186
  for (propName in defaultProps) {
180
187
  if (typeof props[propName] === 'undefined') {
@@ -199,6 +206,7 @@ ReactElement.createFactory = function(type) {
199
206
  // easily accessed on elements. E.g. <Foo />.type === Foo.type.
200
207
  // This should not be named `constructor` since this may not be the function
201
208
  // that created the element, and it may not even be a constructor.
209
+ // Legacy hook TODO: Warn if this is accessed
202
210
  factory.type = type;
203
211
  return factory;
204
212
  };
@@ -16,13 +16,28 @@
16
16
  * that support it.
17
17
  */
18
18
 
19
- "use strict";
19
+ 'use strict';
20
20
 
21
21
  var ReactElement = require("./ReactElement");
22
22
  var ReactPropTypeLocations = require("./ReactPropTypeLocations");
23
+ var ReactPropTypeLocationNames = require("./ReactPropTypeLocationNames");
23
24
  var ReactCurrentOwner = require("./ReactCurrentOwner");
25
+ var ReactNativeComponent = require("./ReactNativeComponent");
24
26
 
27
+ var getIteratorFn = require("./getIteratorFn");
25
28
  var monitorCodeUse = require("./monitorCodeUse");
29
+ var invariant = require("./invariant");
30
+ var warning = require("./warning");
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
+ }
26
41
 
27
42
  /**
28
43
  * Warn if there's no key explicitly set on dynamic arrays of children or
@@ -39,6 +54,24 @@ var loggedTypeFailures = {};
39
54
 
40
55
  var NUMERIC_PROPERTY_REGEX = /^\d+$/;
41
56
 
57
+ /**
58
+ * Gets the instance's name for use in warnings.
59
+ *
60
+ * @internal
61
+ * @return {?string} Display name or undefined
62
+ */
63
+ function getName(instance) {
64
+ var publicInstance = instance && instance.getPublicInstance();
65
+ if (!publicInstance) {
66
+ return undefined;
67
+ }
68
+ var constructor = publicInstance.constructor;
69
+ if (!constructor) {
70
+ return undefined;
71
+ }
72
+ return constructor.displayName || constructor.name || undefined;
73
+ }
74
+
42
75
  /**
43
76
  * Gets the current owner's displayName for use in warnings.
44
77
  *
@@ -47,29 +80,31 @@ var NUMERIC_PROPERTY_REGEX = /^\d+$/;
47
80
  */
48
81
  function getCurrentOwnerDisplayName() {
49
82
  var current = ReactCurrentOwner.current;
50
- return current && current.constructor.displayName || undefined;
83
+ return (
84
+ current && getName(current) || undefined
85
+ );
51
86
  }
52
87
 
53
88
  /**
54
- * Warn if the component doesn't have an explicit key assigned to it.
55
- * This component is in an array. The array could grow and shrink or be
89
+ * Warn if the element doesn't have an explicit key assigned to it.
90
+ * This element is in an array. The array could grow and shrink or be
56
91
  * reordered. All children that haven't already been validated are required to
57
92
  * have a "key" property assigned to it.
58
93
  *
59
94
  * @internal
60
- * @param {ReactComponent} component Component that requires a key.
61
- * @param {*} parentType component's parent's type.
95
+ * @param {ReactElement} element Element that requires a key.
96
+ * @param {*} parentType element's parent's type.
62
97
  */
63
- function validateExplicitKey(component, parentType) {
64
- if (component._store.validated || component.key != null) {
98
+ function validateExplicitKey(element, parentType) {
99
+ if (element._store.validated || element.key != null) {
65
100
  return;
66
101
  }
67
- component._store.validated = true;
102
+ element._store.validated = true;
68
103
 
69
104
  warnAndMonitorForKeyUse(
70
105
  'react_key_warning',
71
- 'Each child in an array should have a unique "key" prop.',
72
- component,
106
+ 'Each child in an array or iterator should have a unique "key" prop.',
107
+ element,
73
108
  parentType
74
109
  );
75
110
  }
@@ -80,17 +115,17 @@ function validateExplicitKey(component, parentType) {
80
115
  *
81
116
  * @internal
82
117
  * @param {string} name Property name of the key.
83
- * @param {ReactComponent} component Component that requires a key.
84
- * @param {*} parentType component's parent's type.
118
+ * @param {ReactElement} element Component that requires a key.
119
+ * @param {*} parentType element's parent's type.
85
120
  */
86
- function validatePropertyKey(name, component, parentType) {
121
+ function validatePropertyKey(name, element, parentType) {
87
122
  if (!NUMERIC_PROPERTY_REGEX.test(name)) {
88
123
  return;
89
124
  }
90
125
  warnAndMonitorForKeyUse(
91
126
  'react_numeric_key_warning',
92
127
  'Child objects should have non-numeric keys so ordering is preserved.',
93
- component,
128
+ element,
94
129
  parentType
95
130
  );
96
131
  }
@@ -101,12 +136,12 @@ function validatePropertyKey(name, component, parentType) {
101
136
  * @internal
102
137
  * @param {string} warningID The id used when logging.
103
138
  * @param {string} message The base warning that gets output.
104
- * @param {ReactComponent} component Component that requires a key.
105
- * @param {*} parentType component's parent's type.
139
+ * @param {ReactElement} element Component that requires a key.
140
+ * @param {*} parentType element's parent's type.
106
141
  */
107
- function warnAndMonitorForKeyUse(warningID, message, component, parentType) {
142
+ function warnAndMonitorForKeyUse(warningID, message, element, parentType) {
108
143
  var ownerName = getCurrentOwnerDisplayName();
109
- var parentName = parentType.displayName;
144
+ var parentName = parentType.displayName || parentType.name;
110
145
 
111
146
  var useName = ownerName || parentName;
112
147
  var memoizer = ownerHasKeyUseWarning[warningID];
@@ -117,15 +152,17 @@ function warnAndMonitorForKeyUse(warningID, message, component, parentType) {
117
152
 
118
153
  message += ownerName ?
119
154
  (" Check the render method of " + ownerName + ".") :
120
- (" Check the renderComponent call using <" + parentName + ">.");
155
+ (" Check the React.render call using <" + parentName + ">.");
121
156
 
122
157
  // Usually the current owner is the offender, but if it accepts children as a
123
158
  // property, it may be the creator of the child that's responsible for
124
159
  // assigning it a key.
125
160
  var childOwnerName = null;
126
- if (component._owner && component._owner !== ReactCurrentOwner.current) {
161
+ if (element &&
162
+ element._owner &&
163
+ element._owner !== ReactCurrentOwner.current) {
127
164
  // Name of the component that originally created this child.
128
- childOwnerName = component._owner.constructor.displayName;
165
+ childOwnerName = getName(element._owner);
129
166
 
130
167
  message += (" It was passed a child from " + childOwnerName + ".");
131
168
  }
@@ -154,30 +191,43 @@ function monitorUseOfObjectMap() {
154
191
  }
155
192
 
156
193
  /**
157
- * Ensure that every component either is passed in a static location, in an
194
+ * Ensure that every element either is passed in a static location, in an
158
195
  * array with an explicit keys property defined, or in an object literal
159
196
  * with valid key property.
160
197
  *
161
198
  * @internal
162
- * @param {*} component Statically passed child of any type.
163
- * @param {*} parentType component's parent's type.
164
- * @return {boolean}
199
+ * @param {ReactNode} node Statically passed child of any type.
200
+ * @param {*} parentType node's parent's type.
165
201
  */
166
- function validateChildKeys(component, parentType) {
167
- if (Array.isArray(component)) {
168
- for (var i = 0; i < component.length; i++) {
169
- var child = component[i];
202
+ function validateChildKeys(node, parentType) {
203
+ if (Array.isArray(node)) {
204
+ for (var i = 0; i < node.length; i++) {
205
+ var child = node[i];
170
206
  if (ReactElement.isValidElement(child)) {
171
207
  validateExplicitKey(child, parentType);
172
208
  }
173
209
  }
174
- } else if (ReactElement.isValidElement(component)) {
175
- // This component was passed in a valid location.
176
- component._store.validated = true;
177
- } else if (component && typeof component === 'object') {
178
- monitorUseOfObjectMap();
179
- for (var name in component) {
180
- validatePropertyKey(name, component[name], parentType);
210
+ } else if (ReactElement.isValidElement(node)) {
211
+ // This element was passed in a valid location.
212
+ node._store.validated = true;
213
+ } else if (node) {
214
+ var iteratorFn = getIteratorFn(node);
215
+ // Entry iterators provide implicit keys.
216
+ if (iteratorFn && iteratorFn !== node.entries) {
217
+ var iterator = iteratorFn.call(node);
218
+ var step;
219
+ while (!(step = iterator.next()).done) {
220
+ if (ReactElement.isValidElement(step.value)) {
221
+ validateExplicitKey(step.value, parentType);
222
+ }
223
+ }
224
+ } else if (typeof node === 'object') {
225
+ monitorUseOfObjectMap();
226
+ for (var key in node) {
227
+ if (node.hasOwnProperty(key)) {
228
+ validatePropertyKey(key, node[key], parentType);
229
+ }
230
+ }
181
231
  }
182
232
  }
183
233
  }
@@ -199,6 +249,16 @@ function checkPropTypes(componentName, propTypes, props, location) {
199
249
  // fail the render phase where it didn't fail before. So we log it.
200
250
  // After these have been cleaned up, we'll let them throw.
201
251
  try {
252
+ // This is intentionally an invariant that gets caught. It's the same
253
+ // behavior as without this statement except with a better message.
254
+ ("production" !== process.env.NODE_ENV ? invariant(
255
+ typeof propTypes[propName] === 'function',
256
+ '%s: %s type `%s` is invalid; it must be a function, usually from ' +
257
+ 'React.PropTypes.',
258
+ componentName || 'React class',
259
+ ReactPropTypeLocationNames[location],
260
+ propName
261
+ ) : invariant(typeof propTypes[propName] === 'function'));
202
262
  error = propTypes[propName](props, propName, componentName, location);
203
263
  } catch (ex) {
204
264
  error = ex;
@@ -207,11 +267,80 @@ function checkPropTypes(componentName, propTypes, props, location) {
207
267
  // Only monitor this failure once because there tends to be a lot of the
208
268
  // same error.
209
269
  loggedTypeFailures[error.message] = true;
210
- // This will soon use the warning module
211
- monitorCodeUse(
212
- 'react_failed_descriptor_type_check',
213
- { message: error.message }
214
- );
270
+
271
+ var addendum = getDeclarationErrorAddendum(this);
272
+ ("production" !== process.env.NODE_ENV ? warning(false, error.message + addendum) : null);
273
+ }
274
+ }
275
+ }
276
+ }
277
+
278
+ var warnedPropsMutations = {};
279
+
280
+ /**
281
+ * Warn about mutating props when setting `propName` on `element`.
282
+ *
283
+ * @param {string} propName The string key within props that was set
284
+ * @param {ReactElement} element
285
+ */
286
+ function warnForPropsMutation(propName, element) {
287
+ var type = element.type;
288
+ var elementName = typeof type === 'string' ? type : type.displayName;
289
+ var ownerName = element._owner ?
290
+ element._owner.getPublicInstance().constructor.displayName : null;
291
+
292
+ var warningKey = propName + '|' + elementName + '|' + ownerName;
293
+ if (warnedPropsMutations.hasOwnProperty(warningKey)) {
294
+ return;
295
+ }
296
+ warnedPropsMutations[warningKey] = true;
297
+
298
+ var elementInfo = '';
299
+ if (elementName) {
300
+ elementInfo = ' <' + elementName + ' />';
301
+ }
302
+ var ownerInfo = '';
303
+ if (ownerName) {
304
+ ownerInfo = ' The element was created by ' + ownerName + '.';
305
+ }
306
+
307
+ ("production" !== process.env.NODE_ENV ? warning(
308
+ false,
309
+ 'Don\'t set .props.%s of the React component%s. ' +
310
+ 'Instead, specify the correct value when ' +
311
+ 'initially creating the element.%s',
312
+ propName,
313
+ elementInfo,
314
+ ownerInfo
315
+ ) : null);
316
+ }
317
+
318
+ /**
319
+ * Given an element, check if its props have been mutated since element
320
+ * creation (or the last call to this function). In particular, check if any
321
+ * new props have been added, which we can't directly catch by defining warning
322
+ * properties on the props object.
323
+ *
324
+ * @param {ReactElement} element
325
+ */
326
+ function checkAndWarnForMutatedProps(element) {
327
+ if (!element._store) {
328
+ // Element was created using `new ReactElement` directly or with
329
+ // `ReactElement.createElement`; skip mutation checking
330
+ return;
331
+ }
332
+
333
+ var originalProps = element._store.originalProps;
334
+ var props = element.props;
335
+
336
+ for (var propName in props) {
337
+ if (props.hasOwnProperty(propName)) {
338
+ if (!originalProps.hasOwnProperty(propName) ||
339
+ originalProps[propName] !== props[propName]) {
340
+ warnForPropsMutation(propName, element);
341
+
342
+ // Copy over the new value so that the two props objects match again
343
+ originalProps[propName] = props[propName];
215
344
  }
216
345
  }
217
346
  }
@@ -219,7 +348,18 @@ function checkPropTypes(componentName, propTypes, props, location) {
219
348
 
220
349
  var ReactElementValidator = {
221
350
 
351
+ checkAndWarnForMutatedProps: checkAndWarnForMutatedProps,
352
+
222
353
  createElement: function(type, props, children) {
354
+ // We warn in this case but don't throw. We expect the element creation to
355
+ // succeed and there will likely be errors in render.
356
+ ("production" !== process.env.NODE_ENV ? warning(
357
+ type != null,
358
+ 'React.createElement: type should not be null or undefined. It should ' +
359
+ 'be a string (for DOM elements) or a ReactClass (for composite ' +
360
+ 'components).'
361
+ ) : null);
362
+
223
363
  var element = ReactElement.createElement.apply(this, arguments);
224
364
 
225
365
  // The result can be nullish if a mock or a custom function is used.
@@ -232,23 +372,34 @@ var ReactElementValidator = {
232
372
  validateChildKeys(arguments[i], type);
233
373
  }
234
374
 
235
- var name = type.displayName;
236
- if (type.propTypes) {
237
- checkPropTypes(
238
- name,
239
- type.propTypes,
240
- element.props,
241
- ReactPropTypeLocations.prop
242
- );
243
- }
244
- if (type.contextTypes) {
245
- checkPropTypes(
246
- name,
247
- type.contextTypes,
248
- element._context,
249
- ReactPropTypeLocations.context
375
+ if (type) {
376
+ // Extract the component class from the element. Converts string types
377
+ // to a composite class which may have propTypes.
378
+ // TODO: Validating a string's propTypes is not decoupled from the
379
+ // rendering target which is problematic.
380
+ var componentClass = ReactNativeComponent.getComponentClassForElement(
381
+ element
250
382
  );
383
+ var name = componentClass.displayName || componentClass.name;
384
+ if ("production" !== process.env.NODE_ENV) {
385
+ if (componentClass.propTypes) {
386
+ checkPropTypes(
387
+ name,
388
+ componentClass.propTypes,
389
+ element.props,
390
+ ReactPropTypeLocations.prop
391
+ );
392
+ }
393
+ }
394
+ if (typeof componentClass.getDefaultProps === 'function') {
395
+ ("production" !== process.env.NODE_ENV ? warning(
396
+ componentClass.getDefaultProps.isReactClassApproved,
397
+ 'getDefaultProps is only used on classic React.createClass ' +
398
+ 'definitions. Use a static property named `defaultProps` instead.'
399
+ ) : null);
400
+ }
251
401
  }
402
+
252
403
  return element;
253
404
  },
254
405
 
@@ -257,6 +408,7 @@ var ReactElementValidator = {
257
408
  null,
258
409
  type
259
410
  );
411
+ // Legacy hook TODO: Warn if this is accessed
260
412
  validatedFactory.type = type;
261
413
  return validatedFactory;
262
414
  }