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,9 +9,10 @@
9
9
  * @providesModule ReactEmptyComponent
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var ReactElement = require("./ReactElement");
15
+ var ReactInstanceMap = require("./ReactInstanceMap");
15
16
 
16
17
  var invariant = require("./invariant");
17
18
 
@@ -26,17 +27,36 @@ var ReactEmptyComponentInjection = {
26
27
  }
27
28
  };
28
29
 
29
- /**
30
- * @return {ReactComponent} component The injected empty component.
31
- */
32
- function getEmptyComponent() {
30
+ var ReactEmptyComponentType = function() {};
31
+ ReactEmptyComponentType.prototype.componentDidMount = function() {
32
+ var internalInstance = ReactInstanceMap.get(this);
33
+ // TODO: Make sure we run these methods in the correct order, we shouldn't
34
+ // need this check. We're going to assume if we're here it means we ran
35
+ // componentWillUnmount already so there is no internal instance (it gets
36
+ // removed as part of the unmounting process).
37
+ if (!internalInstance) {
38
+ return;
39
+ }
40
+ registerNullComponentID(internalInstance._rootNodeID);
41
+ };
42
+ ReactEmptyComponentType.prototype.componentWillUnmount = function() {
43
+ var internalInstance = ReactInstanceMap.get(this);
44
+ // TODO: Get rid of this check. See TODO in componentDidMount.
45
+ if (!internalInstance) {
46
+ return;
47
+ }
48
+ deregisterNullComponentID(internalInstance._rootNodeID);
49
+ };
50
+ ReactEmptyComponentType.prototype.render = function() {
33
51
  ("production" !== process.env.NODE_ENV ? invariant(
34
52
  component,
35
53
  'Trying to return null from a render, but no null placeholder component ' +
36
54
  'was injected.'
37
55
  ) : invariant(component));
38
56
  return component();
39
- }
57
+ };
58
+
59
+ var emptyElement = ReactElement.createElement(ReactEmptyComponentType);
40
60
 
41
61
  /**
42
62
  * Mark the component as having rendered to null.
@@ -59,15 +79,13 @@ function deregisterNullComponentID(id) {
59
79
  * @return {boolean} True if the component is rendered to null.
60
80
  */
61
81
  function isNullComponentID(id) {
62
- return nullComponentIdsRegistry[id];
82
+ return !!nullComponentIdsRegistry[id];
63
83
  }
64
84
 
65
85
  var ReactEmptyComponent = {
66
- deregisterNullComponentID: deregisterNullComponentID,
67
- getEmptyComponent: getEmptyComponent,
86
+ emptyElement: emptyElement,
68
87
  injection: ReactEmptyComponentInjection,
69
- isNullComponentID: isNullComponentID,
70
- registerNullComponentID: registerNullComponentID
88
+ isNullComponentID: isNullComponentID
71
89
  };
72
90
 
73
91
  module.exports = ReactEmptyComponent;
@@ -9,7 +9,7 @@
9
9
  * @providesModule ReactEventEmitterMixin
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var EventPluginHub = require("./EventPluginHub");
15
15
 
@@ -10,7 +10,7 @@
10
10
  * @typechecks static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var EventListener = require("./EventListener");
16
16
  var ExecutionEnvironment = require("./ExecutionEnvironment");
@@ -123,7 +123,7 @@ var ReactEventListener = {
123
123
  trapBubbledEvent: function(topLevelType, handlerBaseName, handle) {
124
124
  var element = handle;
125
125
  if (!element) {
126
- return;
126
+ return null;
127
127
  }
128
128
  return EventListener.listen(
129
129
  element,
@@ -145,7 +145,7 @@ var ReactEventListener = {
145
145
  trapCapturedEvent: function(topLevelType, handlerBaseName, handle) {
146
146
  var element = handle;
147
147
  if (!element) {
148
- return;
148
+ return null;
149
149
  }
150
150
  return EventListener.capture(
151
151
  element,
@@ -157,7 +157,6 @@ var ReactEventListener = {
157
157
  monitorScrollValue: function(refresh) {
158
158
  var callback = scrollValueMonitor.bind(null, refresh);
159
159
  EventListener.listen(window, 'scroll', callback);
160
- EventListener.listen(window, 'resize', callback);
161
160
  },
162
161
 
163
162
  dispatchEvent: function(topLevelType, nativeEvent) {
@@ -9,22 +9,24 @@
9
9
  * @providesModule ReactInjection
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var DOMProperty = require("./DOMProperty");
15
15
  var EventPluginHub = require("./EventPluginHub");
16
- var ReactComponent = require("./ReactComponent");
17
- var ReactCompositeComponent = require("./ReactCompositeComponent");
16
+ var ReactComponentEnvironment = require("./ReactComponentEnvironment");
17
+ var ReactClass = require("./ReactClass");
18
18
  var ReactEmptyComponent = require("./ReactEmptyComponent");
19
19
  var ReactBrowserEventEmitter = require("./ReactBrowserEventEmitter");
20
20
  var ReactNativeComponent = require("./ReactNativeComponent");
21
+ var ReactDOMComponent = require("./ReactDOMComponent");
21
22
  var ReactPerf = require("./ReactPerf");
22
23
  var ReactRootIndex = require("./ReactRootIndex");
23
24
  var ReactUpdates = require("./ReactUpdates");
24
25
 
25
26
  var ReactInjection = {
26
- Component: ReactComponent.injection,
27
- CompositeComponent: ReactCompositeComponent.injection,
27
+ Component: ReactComponentEnvironment.injection,
28
+ Class: ReactClass.injection,
29
+ DOMComponent: ReactDOMComponent.injection,
28
30
  DOMProperty: DOMProperty.injection,
29
31
  EmptyComponent: ReactEmptyComponent.injection,
30
32
  EventPluginHub: EventPluginHub.injection,
@@ -9,7 +9,7 @@
9
9
  * @providesModule ReactInputSelection
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var ReactDOMSelection = require("./ReactDOMSelection");
15
15
 
@@ -31,9 +31,8 @@ var ReactInputSelection = {
31
31
 
32
32
  hasSelectionCapabilities: function(elem) {
33
33
  return elem && (
34
- (elem.nodeName === 'INPUT' && elem.type === 'text') ||
35
- elem.nodeName === 'TEXTAREA' ||
36
- elem.contentEditable === 'true'
34
+ ((elem.nodeName === 'INPUT' && elem.type === 'text') ||
35
+ elem.nodeName === 'TEXTAREA' || elem.contentEditable === 'true')
37
36
  );
38
37
  },
39
38
 
@@ -10,7 +10,7 @@
10
10
  * @typechecks static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var ReactRootIndex = require("./ReactRootIndex");
16
16
 
@@ -115,7 +115,8 @@ function getNextDescendantID(ancestorID, destinationID) {
115
115
  // Skip over the ancestor and the immediate separator. Traverse until we hit
116
116
  // another separator or we reach the end of `destinationID`.
117
117
  var start = ancestorID.length + SEPARATOR_LENGTH;
118
- for (var i = start; i < destinationID.length; i++) {
118
+ var i;
119
+ for (i = start; i < destinationID.length; i++) {
119
120
  if (isBoundary(destinationID, i)) {
120
121
  break;
121
122
  }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Copyright 2013-2014, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ * @providesModule ReactInstanceMap
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ /**
15
+ * `ReactInstanceMap` maintains a mapping from a public facing stateful
16
+ * instance (key) and the internal representation (value). This allows public
17
+ * methods to accept the user facing instance as an argument and map them back
18
+ * to internal methods.
19
+ */
20
+
21
+ // TODO: Replace this with ES6: var ReactInstanceMap = new Map();
22
+ var ReactInstanceMap = {
23
+
24
+ /**
25
+ * This API should be called `delete` but we'd have to make sure to always
26
+ * transform these to strings for IE support. When this transform is fully
27
+ * supported we can rename it.
28
+ */
29
+ remove: function(key) {
30
+ key._reactInternalInstance = undefined;
31
+ },
32
+
33
+ get: function(key) {
34
+ return key._reactInternalInstance;
35
+ },
36
+
37
+ has: function(key) {
38
+ return key._reactInternalInstance !== undefined;
39
+ },
40
+
41
+ set: function(key, value) {
42
+ key._reactInternalInstance = value;
43
+ }
44
+
45
+ };
46
+
47
+ module.exports = ReactInstanceMap;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Copyright 2015, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ * @providesModule ReactLifeCycle
10
+ */
11
+
12
+ "use strict";
13
+
14
+ /**
15
+ * This module manages the bookkeeping when a component is in the process
16
+ * of being mounted or being unmounted. This is used as a way to enforce
17
+ * invariants (or warnings) when it is not recommended to call
18
+ * setState/forceUpdate.
19
+ *
20
+ * currentlyMountingInstance: During the construction phase, it is not possible
21
+ * to trigger an update since the instance is not fully mounted yet. However, we
22
+ * currently allow this as a convenience for mutating the initial state.
23
+ *
24
+ * currentlyUnmountingInstance: During the unmounting phase, the instance is
25
+ * still mounted and can therefore schedule an update. However, this is not
26
+ * recommended and probably an error since it's about to be unmounted.
27
+ * Therefore we still want to trigger in an error for that case.
28
+ */
29
+
30
+ var ReactLifeCycle = {
31
+ currentlyMountingInstance: null,
32
+ currentlyUnmountingInstance: null
33
+ };
34
+
35
+ module.exports = ReactLifeCycle;
package/lib/ReactLink.js CHANGED
@@ -10,7 +10,7 @@
10
10
  * @typechecks static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  /**
16
16
  * ReactLink encapsulates a common pattern in which a component wants to modify
@@ -9,7 +9,7 @@
9
9
  * @providesModule ReactMarkupChecksum
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var adler32 = require("./adler32");
15
15
 
package/lib/ReactMount.js CHANGED
@@ -9,28 +9,31 @@
9
9
  * @providesModule ReactMount
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var DOMProperty = require("./DOMProperty");
15
15
  var ReactBrowserEventEmitter = require("./ReactBrowserEventEmitter");
16
16
  var ReactCurrentOwner = require("./ReactCurrentOwner");
17
17
  var ReactElement = require("./ReactElement");
18
- var ReactLegacyElement = require("./ReactLegacyElement");
18
+ var ReactElementValidator = require("./ReactElementValidator");
19
+ var ReactEmptyComponent = require("./ReactEmptyComponent");
19
20
  var ReactInstanceHandles = require("./ReactInstanceHandles");
21
+ var ReactInstanceMap = require("./ReactInstanceMap");
22
+ var ReactMarkupChecksum = require("./ReactMarkupChecksum");
20
23
  var ReactPerf = require("./ReactPerf");
24
+ var ReactReconciler = require("./ReactReconciler");
25
+ var ReactUpdateQueue = require("./ReactUpdateQueue");
26
+ var ReactUpdates = require("./ReactUpdates");
21
27
 
28
+ var emptyObject = require("./emptyObject");
22
29
  var containsNode = require("./containsNode");
23
- var deprecated = require("./deprecated");
24
30
  var getReactRootElementInContainer = require("./getReactRootElementInContainer");
25
31
  var instantiateReactComponent = require("./instantiateReactComponent");
26
32
  var invariant = require("./invariant");
33
+ var setInnerHTML = require("./setInnerHTML");
27
34
  var shouldUpdateReactComponent = require("./shouldUpdateReactComponent");
28
35
  var warning = require("./warning");
29
36
 
30
- var createElement = ReactLegacyElement.wrapCreateElement(
31
- ReactElement.createElement
32
- );
33
-
34
37
  var SEPARATOR = ReactInstanceHandles.SEPARATOR;
35
38
 
36
39
  var ATTR_NAME = DOMProperty.ID_ATTRIBUTE_NAME;
@@ -53,6 +56,22 @@ if ("production" !== process.env.NODE_ENV) {
53
56
  // Used to store breadth-first search state in findComponentRoot.
54
57
  var findComponentRootReusableArray = [];
55
58
 
59
+ /**
60
+ * Finds the index of the first character
61
+ * that's not common between the two given strings.
62
+ *
63
+ * @return {number} the index of the character where the strings diverge
64
+ */
65
+ function firstDifferenceIndex(string1, string2) {
66
+ var minLen = Math.min(string1.length, string2.length);
67
+ for (var i = 0; i < minLen; i++) {
68
+ if (string1.charAt(i) !== string2.charAt(i)) {
69
+ return i;
70
+ }
71
+ }
72
+ return string1.length === string2.length ? -1 : minLen;
73
+ }
74
+
56
75
  /**
57
76
  * @param {DOMElement} container DOM element that may contain a React component.
58
77
  * @return {?string} A "reactRoot" ID, if a React component is rendered.
@@ -130,6 +149,24 @@ function getNode(id) {
130
149
  return nodeCache[id];
131
150
  }
132
151
 
152
+ /**
153
+ * Finds the node with the supplied public React instance.
154
+ *
155
+ * @param {*} instance A public React instance.
156
+ * @return {?DOMElement} DOM node with the suppled `id`.
157
+ * @internal
158
+ */
159
+ function getNodeFromInstance(instance) {
160
+ var id = ReactInstanceMap.get(instance)._rootNodeID;
161
+ if (ReactEmptyComponent.isNullComponentID(id)) {
162
+ return null;
163
+ }
164
+ if (!nodeCache.hasOwnProperty(id) || !isValid(nodeCache[id], id)) {
165
+ nodeCache[id] = ReactMount.findReactNodeByID(id);
166
+ }
167
+ return nodeCache[id];
168
+ }
169
+
133
170
  /**
134
171
  * A node is "valid" if it is contained by a currently mounted container.
135
172
  *
@@ -193,6 +230,54 @@ function findDeepestCachedAncestor(targetID) {
193
230
  return foundNode;
194
231
  }
195
232
 
233
+ /**
234
+ * Mounts this component and inserts it into the DOM.
235
+ *
236
+ * @param {ReactComponent} componentInstance The instance to mount.
237
+ * @param {string} rootID DOM ID of the root node.
238
+ * @param {DOMElement} container DOM element to mount into.
239
+ * @param {ReactReconcileTransaction} transaction
240
+ * @param {boolean} shouldReuseMarkup If true, do not insert markup
241
+ */
242
+ function mountComponentIntoNode(
243
+ componentInstance,
244
+ rootID,
245
+ container,
246
+ transaction,
247
+ shouldReuseMarkup) {
248
+ var markup = ReactReconciler.mountComponent(
249
+ componentInstance, rootID, transaction, emptyObject
250
+ );
251
+ componentInstance._isTopLevel = true;
252
+ ReactMount._mountImageIntoNode(markup, container, shouldReuseMarkup);
253
+ }
254
+
255
+ /**
256
+ * Batched mount.
257
+ *
258
+ * @param {ReactComponent} componentInstance The instance to mount.
259
+ * @param {string} rootID DOM ID of the root node.
260
+ * @param {DOMElement} container DOM element to mount into.
261
+ * @param {boolean} shouldReuseMarkup If true, do not insert markup
262
+ */
263
+ function batchedMountComponentIntoNode(
264
+ componentInstance,
265
+ rootID,
266
+ container,
267
+ shouldReuseMarkup) {
268
+ var transaction = ReactUpdates.ReactReconcileTransaction.getPooled();
269
+ transaction.perform(
270
+ mountComponentIntoNode,
271
+ null,
272
+ componentInstance,
273
+ rootID,
274
+ container,
275
+ transaction,
276
+ shouldReuseMarkup
277
+ );
278
+ ReactUpdates.ReactReconcileTransaction.release(transaction);
279
+ }
280
+
196
281
  /**
197
282
  * Mounting is the process of initializing a React component by creatings its
198
283
  * representative DOM elements and inserting them into a supplied `container`.
@@ -230,18 +315,24 @@ var ReactMount = {
230
315
  /**
231
316
  * Take a component that's already mounted into the DOM and replace its props
232
317
  * @param {ReactComponent} prevComponent component instance already in the DOM
233
- * @param {ReactComponent} nextComponent component instance to render
318
+ * @param {ReactElement} nextElement component instance to render
234
319
  * @param {DOMElement} container container to render into
235
320
  * @param {?function} callback function triggered on completion
236
321
  */
237
322
  _updateRootComponent: function(
238
323
  prevComponent,
239
- nextComponent,
324
+ nextElement,
240
325
  container,
241
326
  callback) {
242
- var nextProps = nextComponent.props;
327
+ if ("production" !== process.env.NODE_ENV) {
328
+ ReactElementValidator.checkAndWarnForMutatedProps(nextElement);
329
+ }
330
+
243
331
  ReactMount.scrollMonitor(container, function() {
244
- prevComponent.replaceProps(nextProps, callback);
332
+ ReactUpdateQueue.enqueueElementInternal(prevComponent, nextElement);
333
+ if (callback) {
334
+ ReactUpdateQueue.enqueueCallbackInternal(prevComponent, callback);
335
+ }
245
336
  });
246
337
 
247
338
  if ("production" !== process.env.NODE_ENV) {
@@ -263,13 +354,11 @@ var ReactMount = {
263
354
  _registerComponent: function(nextComponent, container) {
264
355
  ("production" !== process.env.NODE_ENV ? invariant(
265
356
  container && (
266
- container.nodeType === ELEMENT_NODE_TYPE ||
267
- container.nodeType === DOC_NODE_TYPE
357
+ (container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
268
358
  ),
269
359
  '_registerComponent(...): Target container is not a DOM element.'
270
360
  ) : invariant(container && (
271
- container.nodeType === ELEMENT_NODE_TYPE ||
272
- container.nodeType === DOC_NODE_TYPE
361
+ (container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
273
362
  )));
274
363
 
275
364
  ReactBrowserEventEmitter.ensureScrollValueMonitoring();
@@ -286,44 +375,48 @@ var ReactMount = {
286
375
  * @param {boolean} shouldReuseMarkup if we should skip the markup insertion
287
376
  * @return {ReactComponent} nextComponent
288
377
  */
289
- _renderNewRootComponent: ReactPerf.measure(
290
- 'ReactMount',
291
- '_renderNewRootComponent',
292
- function(
293
- nextComponent,
294
- container,
295
- shouldReuseMarkup) {
296
- // Various parts of our code (such as ReactCompositeComponent's
297
- // _renderValidatedComponent) assume that calls to render aren't nested;
298
- // verify that that's the case.
299
- ("production" !== process.env.NODE_ENV ? warning(
300
- ReactCurrentOwner.current == null,
301
- '_renderNewRootComponent(): Render methods should be a pure function ' +
302
- 'of props and state; triggering nested component updates from ' +
303
- 'render is not allowed. If necessary, trigger nested updates in ' +
304
- 'componentDidUpdate.'
305
- ) : null);
306
-
307
- var componentInstance = instantiateReactComponent(nextComponent, null);
308
- var reactRootID = ReactMount._registerComponent(
309
- componentInstance,
310
- container
311
- );
312
- componentInstance.mountComponentIntoNode(
313
- reactRootID,
314
- container,
315
- shouldReuseMarkup
316
- );
317
-
318
- if ("production" !== process.env.NODE_ENV) {
319
- // Record the root element in case it later gets transplanted.
320
- rootElementsByReactRootID[reactRootID] =
321
- getReactRootElementInContainer(container);
322
- }
378
+ _renderNewRootComponent: function(
379
+ nextComponent,
380
+ container,
381
+ shouldReuseMarkup
382
+ ) {
383
+ // Various parts of our code (such as ReactCompositeComponent's
384
+ // _renderValidatedComponent) assume that calls to render aren't nested;
385
+ // verify that that's the case.
386
+ ("production" !== process.env.NODE_ENV ? warning(
387
+ ReactCurrentOwner.current == null,
388
+ '_renderNewRootComponent(): Render methods should be a pure function ' +
389
+ 'of props and state; triggering nested component updates from ' +
390
+ 'render is not allowed. If necessary, trigger nested updates in ' +
391
+ 'componentDidUpdate.'
392
+ ) : null);
393
+
394
+ var componentInstance = instantiateReactComponent(nextComponent, null);
395
+ var reactRootID = ReactMount._registerComponent(
396
+ componentInstance,
397
+ container
398
+ );
323
399
 
324
- return componentInstance;
400
+ // The initial render is synchronous but any updates that happen during
401
+ // rendering, in componentWillMount or componentDidMount, will be batched
402
+ // according to the current batching strategy.
403
+
404
+ ReactUpdates.batchedUpdates(
405
+ batchedMountComponentIntoNode,
406
+ componentInstance,
407
+ reactRootID,
408
+ container,
409
+ shouldReuseMarkup
410
+ );
411
+
412
+ if ("production" !== process.env.NODE_ENV) {
413
+ // Record the root element in case it later gets transplanted.
414
+ rootElementsByReactRootID[reactRootID] =
415
+ getReactRootElementInContainer(container);
325
416
  }
326
- ),
417
+
418
+ return componentInstance;
419
+ },
327
420
 
328
421
  /**
329
422
  * Renders a React component into the DOM in the supplied `container`.
@@ -340,16 +433,16 @@ var ReactMount = {
340
433
  render: function(nextElement, container, callback) {
341
434
  ("production" !== process.env.NODE_ENV ? invariant(
342
435
  ReactElement.isValidElement(nextElement),
343
- 'renderComponent(): Invalid component element.%s',
436
+ 'React.render(): Invalid component element.%s',
344
437
  (
345
438
  typeof nextElement === 'string' ?
346
439
  ' Instead of passing an element string, make sure to instantiate ' +
347
440
  'it by passing it to React.createElement.' :
348
- ReactLegacyElement.isValidFactory(nextElement) ?
441
+ typeof nextElement === 'function' ?
349
442
  ' Instead of passing a component class, make sure to instantiate ' +
350
443
  'it by passing it to React.createElement.' :
351
- // Check if it quacks like a element
352
- typeof nextElement.props !== "undefined" ?
444
+ // Check if it quacks like an element
445
+ nextElement != null && nextElement.props !== undefined ?
353
446
  ' This may be caused by unintentionally loading two independent ' +
354
447
  'copies of React.' :
355
448
  ''
@@ -366,7 +459,7 @@ var ReactMount = {
366
459
  nextElement,
367
460
  container,
368
461
  callback
369
- );
462
+ ).getPublicInstance();
370
463
  } else {
371
464
  ReactMount.unmountComponentAtNode(container);
372
465
  }
@@ -382,8 +475,10 @@ var ReactMount = {
382
475
  nextElement,
383
476
  container,
384
477
  shouldReuseMarkup
385
- );
386
- callback && callback.call(component);
478
+ ).getPublicInstance();
479
+ if (callback) {
480
+ callback.call(component);
481
+ }
387
482
  return component;
388
483
  },
389
484
 
@@ -397,7 +492,7 @@ var ReactMount = {
397
492
  * @return {ReactComponent} Component instance rendered in `container`.
398
493
  */
399
494
  constructAndRenderComponent: function(constructor, props, container) {
400
- var element = createElement(constructor, props);
495
+ var element = ReactElement.createElement(constructor, props);
401
496
  return ReactMount.render(element, container);
402
497
  },
403
498
 
@@ -462,6 +557,15 @@ var ReactMount = {
462
557
  'componentDidUpdate.'
463
558
  ) : null);
464
559
 
560
+ ("production" !== process.env.NODE_ENV ? invariant(
561
+ container && (
562
+ (container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
563
+ ),
564
+ 'unmountComponentAtNode(...): Target container is not a DOM element.'
565
+ ) : invariant(container && (
566
+ (container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
567
+ )));
568
+
465
569
  var reactRootID = getReactRootID(container);
466
570
  var component = instancesByReactRootID[reactRootID];
467
571
  if (!component) {
@@ -486,7 +590,7 @@ var ReactMount = {
486
590
  * @see {ReactMount.unmountComponentAtNode}
487
591
  */
488
592
  unmountComponentFromNode: function(instance, container) {
489
- instance.unmountComponent();
593
+ ReactReconciler.unmountComponent(instance);
490
594
 
491
595
  if (container.nodeType === DOC_NODE_TYPE) {
492
596
  container = container.documentElement;
@@ -666,6 +770,75 @@ var ReactMount = {
666
770
  ) : invariant(false));
667
771
  },
668
772
 
773
+ _mountImageIntoNode: function(markup, container, shouldReuseMarkup) {
774
+ ("production" !== process.env.NODE_ENV ? invariant(
775
+ container && (
776
+ (container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
777
+ ),
778
+ 'mountComponentIntoNode(...): Target container is not valid.'
779
+ ) : invariant(container && (
780
+ (container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
781
+ )));
782
+
783
+ if (shouldReuseMarkup) {
784
+ var rootElement = getReactRootElementInContainer(container);
785
+ if (ReactMarkupChecksum.canReuseMarkup(markup, rootElement)) {
786
+ return;
787
+ } else {
788
+ var checksum = rootElement.getAttribute(
789
+ ReactMarkupChecksum.CHECKSUM_ATTR_NAME
790
+ );
791
+ rootElement.removeAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME);
792
+
793
+ var rootMarkup = rootElement.outerHTML;
794
+ rootElement.setAttribute(
795
+ ReactMarkupChecksum.CHECKSUM_ATTR_NAME,
796
+ checksum
797
+ );
798
+
799
+ var diffIndex = firstDifferenceIndex(markup, rootMarkup);
800
+ var difference = ' (client) ' +
801
+ markup.substring(diffIndex - 20, diffIndex + 20) +
802
+ '\n (server) ' + rootMarkup.substring(diffIndex - 20, diffIndex + 20);
803
+
804
+ ("production" !== process.env.NODE_ENV ? invariant(
805
+ container.nodeType !== DOC_NODE_TYPE,
806
+ 'You\'re trying to render a component to the document using ' +
807
+ 'server rendering but the checksum was invalid. This usually ' +
808
+ 'means you rendered a different component type or props on ' +
809
+ 'the client from the one on the server, or your render() ' +
810
+ 'methods are impure. React cannot handle this case due to ' +
811
+ 'cross-browser quirks by rendering at the document root. You ' +
812
+ 'should look for environment dependent code in your components ' +
813
+ 'and ensure the props are the same client and server side:\n%s',
814
+ difference
815
+ ) : invariant(container.nodeType !== DOC_NODE_TYPE));
816
+
817
+ if ("production" !== process.env.NODE_ENV) {
818
+ console.warn(
819
+ 'React attempted to reuse markup in a container but the ' +
820
+ 'checksum was invalid. This generally means that you are ' +
821
+ 'using server rendering and the markup generated on the ' +
822
+ 'server was not what the client was expecting. React injected ' +
823
+ 'new markup to compensate which works but you have lost many ' +
824
+ 'of the benefits of server rendering. Instead, figure out ' +
825
+ 'why the markup being generated is different on the client ' +
826
+ 'or server:\n' + difference
827
+ );
828
+ }
829
+ }
830
+ }
831
+
832
+ ("production" !== process.env.NODE_ENV ? invariant(
833
+ container.nodeType !== DOC_NODE_TYPE,
834
+ 'You\'re trying to render a component to the document but ' +
835
+ 'you didn\'t use server rendering. We can\'t do this ' +
836
+ 'without using server rendering due to cross-browser quirks. ' +
837
+ 'See React.renderToString() for server rendering.'
838
+ ) : invariant(container.nodeType !== DOC_NODE_TYPE));
839
+
840
+ setInnerHTML(container, markup);
841
+ },
669
842
 
670
843
  /**
671
844
  * React ID utilities.
@@ -679,16 +852,14 @@ var ReactMount = {
679
852
 
680
853
  getNode: getNode,
681
854
 
855
+ getNodeFromInstance: getNodeFromInstance,
856
+
682
857
  purgeID: purgeID
683
858
  };
684
859
 
685
- // Deprecations (remove for 0.13)
686
- ReactMount.renderComponent = deprecated(
687
- 'ReactMount',
688
- 'renderComponent',
689
- 'render',
690
- this,
691
- ReactMount.render
692
- );
860
+ ReactPerf.measureMethods(ReactMount, 'ReactMount', {
861
+ _renderNewRootComponent: '_renderNewRootComponent',
862
+ _mountImageIntoNode: '_mountImageIntoNode'
863
+ });
693
864
 
694
865
  module.exports = ReactMount;