react 0.12.0 → 0.13.0-alpha.2

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 +2345 -910
  2. package/dist/react-with-addons.js +5273 -4111
  3. package/dist/react-with-addons.min.js +5 -6
  4. package/dist/react.js +4840 -3940
  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 +21 -1
  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 +1 -1
  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 +1 -1
  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 -50
  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 +121 -0
  39. package/lib/ReactChildren.js +10 -8
  40. package/lib/ReactClass.js +874 -0
  41. package/lib/ReactComponent.js +45 -286
  42. package/lib/ReactComponentBase.js +126 -0
  43. package/lib/ReactComponentBrowserEnvironment.js +10 -83
  44. package/lib/ReactComponentEnvironment.js +57 -0
  45. package/lib/ReactComponentWithPureRenderMixin.js +1 -1
  46. package/lib/ReactCompositeComponent.js +700 -1045
  47. package/lib/ReactContext.js +6 -2
  48. package/lib/ReactCurrentOwner.js +1 -1
  49. package/lib/ReactDOM.js +3 -8
  50. package/lib/ReactDOMButton.js +5 -6
  51. package/lib/ReactDOMComponent.js +120 -77
  52. package/lib/ReactDOMForm.js +5 -6
  53. package/lib/ReactDOMIDOperations.js +56 -74
  54. package/lib/ReactDOMImg.js +4 -6
  55. package/lib/ReactDOMInput.js +5 -6
  56. package/lib/ReactDOMOption.js +5 -6
  57. package/lib/ReactDOMSelect.js +57 -65
  58. package/lib/ReactDOMSelection.js +6 -2
  59. package/lib/ReactDOMTextComponent.js +124 -0
  60. package/lib/ReactDOMTextarea.js +5 -6
  61. package/lib/ReactDefaultBatchingStrategy.js +1 -1
  62. package/lib/ReactDefaultInjection.js +14 -8
  63. package/lib/ReactDefaultPerf.js +8 -7
  64. package/lib/ReactDefaultPerfAnalysis.js +1 -1
  65. package/lib/ReactElement.js +22 -15
  66. package/lib/ReactElementValidator.js +192 -53
  67. package/lib/ReactEmptyComponent.js +29 -11
  68. package/lib/ReactEventEmitterMixin.js +1 -1
  69. package/lib/ReactEventListener.js +3 -3
  70. package/lib/ReactInjection.js +7 -5
  71. package/lib/ReactInputSelection.js +3 -4
  72. package/lib/ReactInstanceHandles.js +3 -2
  73. package/lib/ReactInstanceMap.js +47 -0
  74. package/lib/ReactLink.js +1 -1
  75. package/lib/ReactMarkupChecksum.js +1 -1
  76. package/lib/ReactMount.js +202 -66
  77. package/lib/ReactMultiChild.js +44 -45
  78. package/lib/ReactMultiChildUpdateTypes.js +1 -1
  79. package/lib/ReactNativeComponent.js +47 -10
  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/ReactRef.js +96 -0
  89. package/lib/ReactRootIndex.js +1 -1
  90. package/lib/ReactServerRendering.js +5 -3
  91. package/lib/ReactServerRenderingTransaction.js +1 -1
  92. package/lib/ReactStateSetters.js +1 -1
  93. package/lib/ReactTestUtils.js +83 -26
  94. package/lib/ReactTransitionChildMapping.js +1 -1
  95. package/lib/ReactTransitionEvents.js +1 -1
  96. package/lib/ReactTransitionGroup.js +48 -7
  97. package/lib/ReactUpdates.js +46 -45
  98. package/lib/ReactWithAddons.js +1 -1
  99. package/lib/SVGDOMPropertyConfig.js +1 -1
  100. package/lib/SelectEventPlugin.js +3 -3
  101. package/lib/ServerReactRootIndex.js +1 -1
  102. package/lib/SimpleEventPlugin.js +1 -1
  103. package/lib/SyntheticClipboardEvent.js +1 -2
  104. package/lib/SyntheticCompositionEvent.js +1 -2
  105. package/lib/SyntheticDragEvent.js +1 -1
  106. package/lib/SyntheticEvent.js +11 -3
  107. package/lib/SyntheticFocusEvent.js +1 -1
  108. package/lib/SyntheticInputEvent.js +1 -2
  109. package/lib/SyntheticKeyboardEvent.js +1 -1
  110. package/lib/SyntheticMouseEvent.js +2 -4
  111. package/lib/SyntheticTouchEvent.js +1 -1
  112. package/lib/SyntheticUIEvent.js +1 -1
  113. package/lib/SyntheticWheelEvent.js +1 -1
  114. package/lib/Transaction.js +3 -3
  115. package/lib/ViewportMetrics.js +2 -5
  116. package/lib/accumulate.js +47 -0
  117. package/lib/accumulateInto.js +1 -1
  118. package/lib/adler32.js +1 -1
  119. package/lib/cloneWithProps.js +3 -3
  120. package/lib/copyProperties.js +2 -0
  121. package/lib/createFullPageComponent.js +3 -3
  122. package/lib/dangerousStyleValue.js +1 -1
  123. package/lib/escapeTextForBrowser.js +6 -6
  124. package/lib/findDOMNode.js +51 -0
  125. package/lib/flattenChildren.js +11 -22
  126. package/lib/forEachAccumulated.js +1 -1
  127. package/lib/getEventCharCode.js +1 -1
  128. package/lib/getEventKey.js +1 -1
  129. package/lib/getEventModifierState.js +1 -1
  130. package/lib/getEventTarget.js +1 -1
  131. package/lib/getIteratorFn.js +42 -0
  132. package/lib/getNodeForCharacterOffset.js +2 -2
  133. package/lib/getReactRootElementInContainer.js +1 -1
  134. package/lib/getTextContentAccessor.js +1 -1
  135. package/lib/instantiateReactComponent.js +89 -66
  136. package/lib/isEventSupported.js +1 -1
  137. package/lib/isNode.js +3 -4
  138. package/lib/isTextInputElement.js +2 -3
  139. package/lib/joinClasses.js +1 -1
  140. package/lib/keyMirror.js +1 -1
  141. package/lib/memoizeStringOnly.js +4 -5
  142. package/lib/onlyChild.js +1 -1
  143. package/lib/setInnerHTML.js +12 -1
  144. package/lib/shallowEqual.js +1 -1
  145. package/lib/shouldUpdateReactComponent.js +48 -6
  146. package/lib/traverseAllChildren.js +111 -55
  147. package/lib/update.js +1 -1
  148. package/lib/warning.js +9 -2
  149. package/package.json +1 -1
  150. package/lib/CompositionEventPlugin.js +0 -257
  151. package/lib/ReactLegacyElement.js +0 -243
  152. package/lib/ReactTextComponent.js +0 -104
  153. package/lib/deprecated.js +0 -47
@@ -10,7 +10,7 @@
10
10
  * @typechecks static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var SyntheticMouseEvent = require("./SyntheticMouseEvent");
16
16
 
@@ -9,7 +9,7 @@
9
9
  * @providesModule Transaction
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var invariant = require("./invariant");
15
15
 
@@ -203,8 +203,8 @@ var Mixin = {
203
203
  // close -- if it's still set to true in the finally block, it means
204
204
  // wrapper.close threw.
205
205
  errorThrown = true;
206
- if (initData !== Transaction.OBSERVED_ERROR) {
207
- wrapper.close && wrapper.close.call(this, initData);
206
+ if (initData !== Transaction.OBSERVED_ERROR && wrapper.close) {
207
+ wrapper.close.call(this, initData);
208
208
  }
209
209
  errorThrown = false;
210
210
  } finally {
@@ -9,9 +9,7 @@
9
9
  * @providesModule ViewportMetrics
10
10
  */
11
11
 
12
- "use strict";
13
-
14
- var getUnboundedScrollPosition = require("./getUnboundedScrollPosition");
12
+ 'use strict';
15
13
 
16
14
  var ViewportMetrics = {
17
15
 
@@ -19,8 +17,7 @@ var ViewportMetrics = {
19
17
 
20
18
  currentScrollTop: 0,
21
19
 
22
- refreshScrollValues: function() {
23
- var scrollPosition = getUnboundedScrollPosition(window);
20
+ refreshScrollValues: function(scrollPosition) {
24
21
  ViewportMetrics.currentScrollLeft = scrollPosition.x;
25
22
  ViewportMetrics.currentScrollTop = scrollPosition.y;
26
23
  }
@@ -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 accumulate
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ var invariant = require("./invariant");
15
+
16
+ /**
17
+ * Accumulates items that must not be null or undefined.
18
+ *
19
+ * This is used to conserve memory by avoiding array allocations.
20
+ *
21
+ * @return {*|array<*>} An accumulation of items.
22
+ */
23
+ function accumulate(current, next) {
24
+ ("production" !== process.env.NODE_ENV ? invariant(
25
+ next != null,
26
+ 'accumulate(...): Accumulated items must be not be null or undefined.'
27
+ ) : invariant(next != null));
28
+ if (current == null) {
29
+ return next;
30
+ } else {
31
+ // Both are not empty. Warning: Never call x.concat(y) when you are not
32
+ // certain that x is an Array (x could be a string with concat method).
33
+ var currentIsArray = Array.isArray(current);
34
+ var nextIsArray = Array.isArray(next);
35
+ if (currentIsArray) {
36
+ return current.concat(next);
37
+ } else {
38
+ if (nextIsArray) {
39
+ return [current].concat(next);
40
+ } else {
41
+ return [current, next];
42
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ module.exports = accumulate;
@@ -9,7 +9,7 @@
9
9
  * @providesModule accumulateInto
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var invariant = require("./invariant");
15
15
 
package/lib/adler32.js CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  /* jslint bitwise:true */
13
13
 
14
- "use strict";
14
+ 'use strict';
15
15
 
16
16
  var MOD = 65521;
17
17
 
@@ -10,7 +10,7 @@
10
10
  * @providesModule cloneWithProps
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var ReactElement = require("./ReactElement");
16
16
  var ReactPropTransferer = require("./ReactPropTransferer");
@@ -25,8 +25,8 @@ var CHILDREN_PROP = keyOf({children: null});
25
25
  * this is to add a CSS class.
26
26
  *
27
27
  * @param {object} child child component you'd like to clone
28
- * @param {object} props props you'd like to modify. They will be merged
29
- * as if you used `transferPropsTo()`.
28
+ * @param {object} props props you'd like to modify. className and style will be
29
+ * merged automatically.
30
30
  * @return {object} a clone of child with props merged in.
31
31
  */
32
32
  function cloneWithProps(child, props) {
@@ -9,6 +9,8 @@
9
9
  * @providesModule copyProperties
10
10
  */
11
11
 
12
+ "use strict";
13
+
12
14
  /**
13
15
  * Copy properties from one or more objects (up to 5) into the first object.
14
16
  * This is a shallow copy. It mutates the first object and also returns it.
@@ -10,10 +10,10 @@
10
10
  * @typechecks
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  // Defeat circular references by requiring this directly.
16
- var ReactCompositeComponent = require("./ReactCompositeComponent");
16
+ var ReactClass = require("./ReactClass");
17
17
  var ReactElement = require("./ReactElement");
18
18
 
19
19
  var invariant = require("./invariant");
@@ -32,7 +32,7 @@ var invariant = require("./invariant");
32
32
  function createFullPageComponent(tag) {
33
33
  var elementFactory = ReactElement.createFactory(tag);
34
34
 
35
- var FullPageComponent = ReactCompositeComponent.createClass({
35
+ var FullPageComponent = ReactClass.createClass({
36
36
  displayName: 'ReactFullPageComponent' + tag,
37
37
 
38
38
  componentWillUnmount: function() {
@@ -10,7 +10,7 @@
10
10
  * @typechecks static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var CSSProperty = require("./CSSProperty");
16
16
 
@@ -10,14 +10,14 @@
10
10
  * @typechecks static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var ESCAPE_LOOKUP = {
16
- "&": "&amp;",
17
- ">": "&gt;",
18
- "<": "&lt;",
19
- "\"": "&quot;",
20
- "'": "&#x27;"
16
+ '&': '&amp;',
17
+ '>': '&gt;',
18
+ '<': '&lt;',
19
+ '"': '&quot;',
20
+ '\'': '&#x27;'
21
21
  };
22
22
 
23
23
  var ESCAPE_REGEX = /[&><"']/g;
@@ -0,0 +1,51 @@
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 findDOMNode
10
+ * @typechecks static-only
11
+ */
12
+
13
+ 'use strict';
14
+ var ReactInstanceMap = require("./ReactInstanceMap");
15
+ var ReactMount = require("./ReactMount");
16
+
17
+ var invariant = require("./invariant");
18
+ var isNode = require("./isNode");
19
+
20
+ /**
21
+ * Returns the DOM node rendered by this element.
22
+ *
23
+ * @param {ReactComponent|DOMElement} componentOrElement
24
+ * @return {DOMElement} The root node of this element.
25
+ */
26
+ function findDOMNode(componentOrElement) {
27
+ if (componentOrElement == null) {
28
+ return null;
29
+ }
30
+ if (isNode(componentOrElement)) {
31
+ return componentOrElement;
32
+ }
33
+ if (ReactInstanceMap.has(componentOrElement)) {
34
+ return ReactMount.getNodeFromInstance(componentOrElement);
35
+ }
36
+ ("production" !== process.env.NODE_ENV ? invariant(
37
+ componentOrElement.render == null ||
38
+ typeof componentOrElement.render !== 'function',
39
+ 'Component (with keys: %s) contains `render` method ' +
40
+ 'but is not mounted in the DOM',
41
+ Object.keys(componentOrElement)
42
+ ) : invariant(componentOrElement.render == null ||
43
+ typeof componentOrElement.render !== 'function'));
44
+ ("production" !== process.env.NODE_ENV ? invariant(
45
+ false,
46
+ 'Element appears to be neither ReactComponent nor DOMNode (keys: %s)',
47
+ Object.keys(componentOrElement)
48
+ ) : invariant(false));
49
+ }
50
+
51
+ module.exports = findDOMNode;
@@ -9,9 +9,7 @@
9
9
  * @providesModule flattenChildren
10
10
  */
11
11
 
12
- "use strict";
13
-
14
- var ReactTextComponent = require("./ReactTextComponent");
12
+ 'use strict';
15
13
 
16
14
  var traverseAllChildren = require("./traverseAllChildren");
17
15
  var warning = require("./warning");
@@ -25,26 +23,17 @@ function flattenSingleChildIntoContext(traverseContext, child, name) {
25
23
  // We found a component instance.
26
24
  var result = traverseContext;
27
25
  var keyUnique = !result.hasOwnProperty(name);
28
- ("production" !== process.env.NODE_ENV ? warning(
29
- keyUnique,
30
- 'flattenChildren(...): Encountered two children with the same key, ' +
31
- '`%s`. Child keys must be unique; when two children share a key, only ' +
32
- 'the first child will be used.',
33
- name
34
- ) : null);
26
+ if ("production" !== process.env.NODE_ENV) {
27
+ ("production" !== process.env.NODE_ENV ? warning(
28
+ keyUnique,
29
+ 'flattenChildren(...): Encountered two children with the same key, ' +
30
+ '`%s`. Child keys must be unique; when two children share a key, only ' +
31
+ 'the first child will be used.',
32
+ name
33
+ ) : null);
34
+ }
35
35
  if (keyUnique && child != null) {
36
- var type = typeof child;
37
- var normalizedValue;
38
-
39
- if (type === 'string') {
40
- normalizedValue = ReactTextComponent(child);
41
- } else if (type === 'number') {
42
- normalizedValue = ReactTextComponent('' + child);
43
- } else {
44
- normalizedValue = child;
45
- }
46
-
47
- result[name] = normalizedValue;
36
+ result[name] = child;
48
37
  }
49
38
  }
50
39
 
@@ -9,7 +9,7 @@
9
9
  * @providesModule forEachAccumulated
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  /**
15
15
  * @param {array} an "accumulation" of items which is either an Array or
@@ -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
  * `charCode` represents the actual "character code" and is safe to use with
@@ -10,7 +10,7 @@
10
10
  * @typechecks static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var getEventCharCode = require("./getEventCharCode");
16
16
 
@@ -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
  * Translation from modifier key to the associated property in the event.
@@ -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
  * Gets the target node from a native browser event by accounting for
@@ -0,0 +1,42 @@
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 getIteratorFn
10
+ * @typechecks static-only
11
+ */
12
+
13
+ 'use strict';
14
+
15
+ /* global Symbol */
16
+ var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
17
+ var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
18
+
19
+ /**
20
+ * Returns the iterator method function contained on the iterable object.
21
+ *
22
+ * Be sure to invoke the function with the iterable as context:
23
+ *
24
+ * var iteratorFn = getIteratorFn(myIterable);
25
+ * if (iteratorFn) {
26
+ * var iterator = iteratorFn.call(myIterable);
27
+ * ...
28
+ * }
29
+ *
30
+ * @param {?object} maybeIterable
31
+ * @return {?function}
32
+ */
33
+ function getIteratorFn(maybeIterable) {
34
+ var iteratorFn = maybeIterable && (
35
+ (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL])
36
+ );
37
+ if (typeof iteratorFn === 'function') {
38
+ return iteratorFn;
39
+ }
40
+ }
41
+
42
+ module.exports = getIteratorFn;
@@ -9,7 +9,7 @@
9
9
  * @providesModule getNodeForCharacterOffset
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  /**
15
15
  * Given any node return the first leaf node without children.
@@ -53,7 +53,7 @@ function getNodeForCharacterOffset(root, offset) {
53
53
  var nodeEnd = 0;
54
54
 
55
55
  while (node) {
56
- if (node.nodeType == 3) {
56
+ if (node.nodeType === 3) {
57
57
  nodeEnd = nodeStart + node.textContent.length;
58
58
 
59
59
  if (nodeStart <= offset && nodeEnd >= offset) {
@@ -9,7 +9,7 @@
9
9
  * @providesModule getReactRootElementInContainer
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var DOC_NODE_TYPE = 9;
15
15
 
@@ -9,7 +9,7 @@
9
9
  * @providesModule getTextContentAccessor
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var ExecutionEnvironment = require("./ExecutionEnvironment");
15
15
 
@@ -10,99 +10,122 @@
10
10
  * @typechecks static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
+ var ReactCompositeComponent = require("./ReactCompositeComponent");
16
+ var ReactEmptyComponent = require("./ReactEmptyComponent");
17
+ var ReactNativeComponent = require("./ReactNativeComponent");
18
+
19
+ var assign = require("./Object.assign");
20
+ var invariant = require("./invariant");
15
21
  var warning = require("./warning");
16
22
 
17
- var ReactElement = require("./ReactElement");
18
- var ReactLegacyElement = require("./ReactLegacyElement");
19
- var ReactNativeComponent = require("./ReactNativeComponent");
20
- var ReactEmptyComponent = require("./ReactEmptyComponent");
23
+ // To avoid a cyclic dependency, we create the final class in this module
24
+ var ReactCompositeComponentWrapper = function(inst) {
25
+ this._instance = inst;
26
+ };
27
+ assign(
28
+ ReactCompositeComponentWrapper.prototype,
29
+ ReactCompositeComponent.Mixin,
30
+ {
31
+ _instantiateReactComponent: instantiateReactComponent
32
+ }
33
+ );
21
34
 
22
35
  /**
23
- * Given an `element` create an instance that will actually be mounted.
36
+ * Check if the type reference is a known internal type. I.e. not a user
37
+ * provided composite type.
24
38
  *
25
- * @param {object} element
39
+ * @param {function} type
40
+ * @return {boolean} Returns true if this is a valid internal type.
41
+ */
42
+ function isInternalComponentType(type) {
43
+ return (
44
+ typeof type === 'function' &&
45
+ typeof type.prototype.mountComponent === 'function' &&
46
+ typeof type.prototype.receiveComponent === 'function'
47
+ );
48
+ }
49
+
50
+ /**
51
+ * Given a ReactNode, create an instance that will actually be mounted.
52
+ *
53
+ * @param {ReactNode} node
26
54
  * @param {*} parentCompositeType The composite type that resolved this.
27
55
  * @return {object} A new instance of the element's constructor.
28
56
  * @protected
29
57
  */
30
- function instantiateReactComponent(element, parentCompositeType) {
58
+ function instantiateReactComponent(node, parentCompositeType) {
31
59
  var instance;
32
60
 
33
- if ("production" !== process.env.NODE_ENV) {
34
- ("production" !== process.env.NODE_ENV ? warning(
35
- element && (typeof element.type === 'function' ||
36
- typeof element.type === 'string'),
37
- 'Only functions or strings can be mounted as React components.'
38
- ) : null);
39
-
40
- // Resolve mock instances
41
- if (element.type._mockedReactClassConstructor) {
42
- // If this is a mocked class, we treat the legacy factory as if it was the
43
- // class constructor for future proofing unit tests. Because this might
44
- // be mocked as a legacy factory, we ignore any warnings triggerd by
45
- // this temporary hack.
46
- ReactLegacyElement._isLegacyCallWarningEnabled = false;
47
- try {
48
- instance = new element.type._mockedReactClassConstructor(
49
- element.props
50
- );
51
- } finally {
52
- ReactLegacyElement._isLegacyCallWarningEnabled = true;
53
- }
61
+ if (node === null || node === false) {
62
+ node = ReactEmptyComponent.emptyElement;
63
+ }
54
64
 
55
- // If the mock implementation was a legacy factory, then it returns a
56
- // element. We need to turn this into a real component instance.
57
- if (ReactElement.isValidElement(instance)) {
58
- instance = new instance.type(instance.props);
59
- }
65
+ if (typeof node === 'object') {
66
+ var element = node;
67
+ if ("production" !== process.env.NODE_ENV) {
68
+ ("production" !== process.env.NODE_ENV ? warning(
69
+ element && (typeof element.type === 'function' ||
70
+ typeof element.type === 'string'),
71
+ 'Only functions or strings can be mounted as React components.'
72
+ ) : null);
73
+ }
60
74
 
61
- var render = instance.render;
62
- if (!render) {
63
- // For auto-mocked factories, the prototype isn't shimmed and therefore
64
- // there is no render function on the instance. We replace the whole
65
- // component with an empty component instance instead.
66
- element = ReactEmptyComponent.getEmptyComponent();
67
- } else {
68
- if (render._isMockFunction && !render._getMockImplementation()) {
69
- // Auto-mocked components may have a prototype with a mocked render
70
- // function. For those, we'll need to mock the result of the render
71
- // since we consider undefined to be invalid results from render.
72
- render.mockImplementation(
73
- ReactEmptyComponent.getEmptyComponent
74
- );
75
- }
76
- instance.construct(element);
77
- return instance;
75
+ // Special case string values
76
+ if (typeof element.type === 'string') {
77
+ instance = ReactNativeComponent.createInstanceForTag(
78
+ element.type,
79
+ element.props,
80
+ parentCompositeType
81
+ );
82
+ // If the injected special class is not an internal class, but another
83
+ // composite, then we must wrap it.
84
+ // TODO: Move this resolution around to something cleaner.
85
+ if (typeof instance.mountComponent !== 'function') {
86
+ instance = new ReactCompositeComponentWrapper(instance);
78
87
  }
88
+ } else if (isInternalComponentType(element.type)) {
89
+ // This is temporarily available for custom components that are not string
90
+ // represenations. I.e. ART. Once those are updated to use the string
91
+ // representation, we can drop this code path.
92
+ instance = new element.type(element);
93
+ } else {
94
+ // TODO: Update to follow new ES6 initialization. Ideally, we can use
95
+ // props in property initializers.
96
+ var inst = new element.type(element.props);
97
+ instance = new ReactCompositeComponentWrapper(inst);
79
98
  }
80
- }
81
-
82
- // Special case string values
83
- if (typeof element.type === 'string') {
84
- instance = ReactNativeComponent.createInstanceForTag(
85
- element.type,
86
- element.props,
87
- parentCompositeType
88
- );
99
+ } else if (typeof node === 'string' || typeof node === 'number') {
100
+ instance = ReactNativeComponent.createInstanceForText(node);
89
101
  } else {
90
- // Normal case for non-mocks and non-strings
91
- instance = new element.type(element.props);
102
+ ("production" !== process.env.NODE_ENV ? invariant(
103
+ false,
104
+ 'Encountered invalid React node of type %s',
105
+ typeof node
106
+ ) : invariant(false));
92
107
  }
93
108
 
94
109
  if ("production" !== process.env.NODE_ENV) {
95
110
  ("production" !== process.env.NODE_ENV ? warning(
96
111
  typeof instance.construct === 'function' &&
97
112
  typeof instance.mountComponent === 'function' &&
98
- typeof instance.receiveComponent === 'function',
113
+ typeof instance.receiveComponent === 'function' &&
114
+ typeof instance.unmountComponent === 'function',
99
115
  'Only React Components can be mounted.'
100
116
  ) : null);
101
117
  }
102
118
 
103
- // This actually sets up the internal instance. This will become decoupled
104
- // from the public instance in a future diff.
105
- instance.construct(element);
119
+ // Sets up the instance. This can probably just move into the constructor now.
120
+ instance.construct(node);
121
+
122
+ // Internal instances should fully constructed at this point, so they should
123
+ // not get any new fields added to them at this point.
124
+ if ("production" !== process.env.NODE_ENV) {
125
+ if (Object.preventExtensions) {
126
+ Object.preventExtensions(instance);
127
+ }
128
+ }
106
129
 
107
130
  return instance;
108
131
  }