react 0.12.2 → 0.13.0-alpha.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 (77) hide show
  1. package/dist/JSXTransformer.js +6 -4
  2. package/dist/react-with-addons.js +4022 -3267
  3. package/dist/react-with-addons.min.js +6 -6
  4. package/dist/react.js +3853 -3358
  5. package/dist/react.min.js +6 -6
  6. package/lib/BeforeInputEventPlugin.js +388 -111
  7. package/lib/CSSPropertyOperations.js +20 -0
  8. package/lib/ChangeEventPlugin.js +2 -2
  9. package/lib/Danger.js +1 -1
  10. package/lib/DefaultEventPluginOrder.js +0 -1
  11. package/lib/ExecutionEnvironment.js +2 -3
  12. package/lib/FallbackCompositionState.js +87 -0
  13. package/lib/HTMLDOMPropertyConfig.js +1 -0
  14. package/lib/Object.assign.js +3 -1
  15. package/lib/React.js +14 -49
  16. package/lib/ReactBrowserComponentMixin.js +2 -12
  17. package/lib/ReactBrowserEventEmitter.js +2 -4
  18. package/lib/ReactCSSTransitionGroup.js +3 -0
  19. package/lib/ReactCSSTransitionGroupChild.js +8 -0
  20. package/lib/ReactChildReconciler.js +121 -0
  21. package/lib/ReactClass.js +916 -0
  22. package/lib/ReactComponent.js +36 -286
  23. package/lib/ReactComponentBrowserEnvironment.js +9 -82
  24. package/lib/ReactComponentEnvironment.js +57 -0
  25. package/lib/ReactCompositeComponent.js +608 -1026
  26. package/lib/ReactContext.js +5 -1
  27. package/lib/ReactDOM.js +2 -7
  28. package/lib/ReactDOMButton.js +4 -5
  29. package/lib/ReactDOMComponent.js +97 -69
  30. package/lib/ReactDOMForm.js +4 -5
  31. package/lib/ReactDOMIDOperations.js +55 -73
  32. package/lib/ReactDOMImg.js +3 -5
  33. package/lib/ReactDOMInput.js +4 -5
  34. package/lib/ReactDOMOption.js +4 -5
  35. package/lib/ReactDOMSelect.js +55 -63
  36. package/lib/ReactDOMSelection.js +5 -1
  37. package/lib/{ReactTextComponent.js → ReactDOMTextComponent.js} +54 -34
  38. package/lib/ReactDOMTextarea.js +4 -5
  39. package/lib/ReactDefaultInjection.js +13 -7
  40. package/lib/ReactDefaultPerf.js +6 -5
  41. package/lib/ReactDefaultPerfAnalysis.js +1 -1
  42. package/lib/ReactElement.js +17 -11
  43. package/lib/ReactElementValidator.js +74 -37
  44. package/lib/ReactEmptyComponent.js +17 -10
  45. package/lib/ReactInjection.js +6 -4
  46. package/lib/ReactInputSelection.js +2 -3
  47. package/lib/ReactInstanceMap.js +47 -0
  48. package/lib/ReactMount.js +193 -64
  49. package/lib/ReactMultiChild.js +32 -42
  50. package/lib/ReactNativeComponent.js +45 -8
  51. package/lib/ReactOwner.js +3 -47
  52. package/lib/ReactPerf.js +20 -0
  53. package/lib/ReactPropTransferer.js +0 -55
  54. package/lib/ReactPropTypes.js +1 -17
  55. package/lib/ReactRef.js +96 -0
  56. package/lib/ReactServerRendering.js +3 -2
  57. package/lib/ReactTestUtils.js +82 -25
  58. package/lib/ReactTransitionGroup.js +47 -6
  59. package/lib/ReactUpdates.js +43 -42
  60. package/lib/SyntheticMouseEvent.js +1 -3
  61. package/lib/ViewportMetrics.js +1 -4
  62. package/lib/accumulate.js +47 -0
  63. package/lib/cloneWithProps.js +2 -2
  64. package/lib/copyProperties.js +2 -0
  65. package/lib/createFullPageComponent.js +2 -2
  66. package/lib/findDOMNode.js +52 -0
  67. package/lib/flattenChildren.js +1 -14
  68. package/lib/getIteratorFn.js +42 -0
  69. package/lib/instantiateReactComponent.js +88 -65
  70. package/lib/isNode.js +3 -4
  71. package/lib/isTextInputElement.js +1 -2
  72. package/lib/shouldUpdateReactComponent.js +13 -5
  73. package/lib/traverseAllChildren.js +110 -54
  74. package/package.json +1 -1
  75. package/lib/CompositionEventPlugin.js +0 -257
  76. package/lib/ReactLegacyElement.js +0 -243
  77. package/lib/deprecated.js +0 -47
@@ -39,6 +39,21 @@ var ReactTransitionGroup = React.createClass({
39
39
  };
40
40
  },
41
41
 
42
+ componentWillMount: function() {
43
+ this.currentlyTransitioningKeys = {};
44
+ this.keysToEnter = [];
45
+ this.keysToLeave = [];
46
+ },
47
+
48
+ componentDidMount: function() {
49
+ var initialChildMapping = this.state.children;
50
+ for (var key in initialChildMapping) {
51
+ if (initialChildMapping[key]) {
52
+ this.performAppear(key);
53
+ }
54
+ }
55
+ },
56
+
42
57
  componentWillReceiveProps: function(nextProps) {
43
58
  var nextChildMapping = ReactTransitionChildMapping.getChildMapping(
44
59
  nextProps.children
@@ -73,12 +88,6 @@ var ReactTransitionGroup = React.createClass({
73
88
  // If we want to someday check for reordering, we could do it here.
74
89
  },
75
90
 
76
- componentWillMount: function() {
77
- this.currentlyTransitioningKeys = {};
78
- this.keysToEnter = [];
79
- this.keysToLeave = [];
80
- },
81
-
82
91
  componentDidUpdate: function() {
83
92
  var keysToEnter = this.keysToEnter;
84
93
  this.keysToEnter = [];
@@ -89,6 +98,38 @@ var ReactTransitionGroup = React.createClass({
89
98
  keysToLeave.forEach(this.performLeave);
90
99
  },
91
100
 
101
+ performAppear: function(key) {
102
+ this.currentlyTransitioningKeys[key] = true;
103
+
104
+ var component = this.refs[key];
105
+
106
+ if (component.componentWillAppear) {
107
+ component.componentWillAppear(
108
+ this._handleDoneAppearing.bind(this, key)
109
+ );
110
+ } else {
111
+ this._handleDoneAppearing(key);
112
+ }
113
+ },
114
+
115
+ _handleDoneAppearing: function(key) {
116
+ var component = this.refs[key];
117
+ if (component.componentDidAppear) {
118
+ component.componentDidAppear();
119
+ }
120
+
121
+ delete this.currentlyTransitioningKeys[key];
122
+
123
+ var currentChildMapping = ReactTransitionChildMapping.getChildMapping(
124
+ this.props.children
125
+ );
126
+
127
+ if (!currentChildMapping || !currentChildMapping.hasOwnProperty(key)) {
128
+ // This was removed before it had fully appeared. Remove it.
129
+ this.performLeave(key);
130
+ }
131
+ },
132
+
92
133
  performEnter: function(key) {
93
134
  this.currentlyTransitioningKeys[key] = true;
94
135
 
@@ -110,14 +110,14 @@ function batchedUpdates(callback, a, b) {
110
110
  }
111
111
 
112
112
  /**
113
- * Array comparator for ReactComponents by owner depth
113
+ * Array comparator for ReactComponents by mount ordering.
114
114
  *
115
115
  * @param {ReactComponent} c1 first component you're comparing
116
116
  * @param {ReactComponent} c2 second component you're comparing
117
117
  * @return {number} Return value usable by Array.prototype.sort().
118
118
  */
119
- function mountDepthComparator(c1, c2) {
120
- return c1._mountDepth - c2._mountDepth;
119
+ function mountOrderComparator(c1, c2) {
120
+ return c1._mountOrder - c2._mountOrder;
121
121
  }
122
122
 
123
123
  function runBatchedUpdates(transaction) {
@@ -133,56 +133,57 @@ function runBatchedUpdates(transaction) {
133
133
  // Since reconciling a component higher in the owner hierarchy usually (not
134
134
  // always -- see shouldComponentUpdate()) will reconcile children, reconcile
135
135
  // them before their children by sorting the array.
136
- dirtyComponents.sort(mountDepthComparator);
136
+ dirtyComponents.sort(mountOrderComparator);
137
137
 
138
138
  for (var i = 0; i < len; i++) {
139
- // If a component is unmounted before pending changes apply, ignore them
140
- // TODO: Queue unmounts in the same list to avoid this happening at all
139
+ // If a component is unmounted before pending changes apply, it will still
140
+ // be here, but we assume that it has cleared its _pendingCallbacks and
141
+ // that performUpdateIfNecessary is a noop.
141
142
  var component = dirtyComponents[i];
142
- if (component.isMounted()) {
143
- // If performUpdateIfNecessary happens to enqueue any new updates, we
144
- // shouldn't execute the callbacks until the next render happens, so
145
- // stash the callbacks first
146
- var callbacks = component._pendingCallbacks;
147
- component._pendingCallbacks = null;
148
- component.performUpdateIfNecessary(transaction.reconcileTransaction);
149
-
150
- if (callbacks) {
151
- for (var j = 0; j < callbacks.length; j++) {
152
- transaction.callbackQueue.enqueue(
153
- callbacks[j],
154
- component
155
- );
156
- }
143
+
144
+ // If performUpdateIfNecessary happens to enqueue any new updates, we
145
+ // shouldn't execute the callbacks until the next render happens, so
146
+ // stash the callbacks first
147
+ var callbacks = component._pendingCallbacks;
148
+ component._pendingCallbacks = null;
149
+ component.performUpdateIfNecessary(transaction.reconcileTransaction);
150
+
151
+ if (callbacks) {
152
+ for (var j = 0; j < callbacks.length; j++) {
153
+ transaction.callbackQueue.enqueue(
154
+ callbacks[j],
155
+ component
156
+ );
157
157
  }
158
158
  }
159
159
  }
160
160
  }
161
161
 
162
- var flushBatchedUpdates = ReactPerf.measure(
163
- 'ReactUpdates',
164
- 'flushBatchedUpdates',
165
- function() {
166
- // ReactUpdatesFlushTransaction's wrappers will clear the dirtyComponents
167
- // array and perform any updates enqueued by mount-ready handlers (i.e.,
168
- // componentDidUpdate) but we need to check here too in order to catch
169
- // updates enqueued by setState callbacks and asap calls.
170
- while (dirtyComponents.length || asapEnqueued) {
171
- if (dirtyComponents.length) {
172
- var transaction = ReactUpdatesFlushTransaction.getPooled();
173
- transaction.perform(runBatchedUpdates, null, transaction);
174
- ReactUpdatesFlushTransaction.release(transaction);
175
- }
162
+ var flushBatchedUpdates = function() {
163
+ // ReactUpdatesFlushTransaction's wrappers will clear the dirtyComponents
164
+ // array and perform any updates enqueued by mount-ready handlers (i.e.,
165
+ // componentDidUpdate) but we need to check here too in order to catch
166
+ // updates enqueued by setState callbacks and asap calls.
167
+ while (dirtyComponents.length || asapEnqueued) {
168
+ if (dirtyComponents.length) {
169
+ var transaction = ReactUpdatesFlushTransaction.getPooled();
170
+ transaction.perform(runBatchedUpdates, null, transaction);
171
+ ReactUpdatesFlushTransaction.release(transaction);
172
+ }
176
173
 
177
- if (asapEnqueued) {
178
- asapEnqueued = false;
179
- var queue = asapCallbackQueue;
180
- asapCallbackQueue = CallbackQueue.getPooled();
181
- queue.notifyAll();
182
- CallbackQueue.release(queue);
183
- }
174
+ if (asapEnqueued) {
175
+ asapEnqueued = false;
176
+ var queue = asapCallbackQueue;
177
+ asapCallbackQueue = CallbackQueue.getPooled();
178
+ queue.notifyAll();
179
+ CallbackQueue.release(queue);
184
180
  }
185
181
  }
182
+ };
183
+ flushBatchedUpdates = ReactPerf.measure(
184
+ 'ReactUpdates',
185
+ 'flushBatchedUpdates',
186
+ flushBatchedUpdates
186
187
  );
187
188
 
188
189
  /**
@@ -48,9 +48,7 @@ var MouseEventInterface = {
48
48
  buttons: null,
49
49
  relatedTarget: function(event) {
50
50
  return event.relatedTarget || (
51
- event.fromElement === event.srcElement ?
52
- event.toElement :
53
- event.fromElement
51
+ ((event.fromElement === event.srcElement ? event.toElement : event.fromElement))
54
52
  );
55
53
  },
56
54
  // "Proprietary" Interface.
@@ -11,16 +11,13 @@
11
11
 
12
12
  "use strict";
13
13
 
14
- var getUnboundedScrollPosition = require("./getUnboundedScrollPosition");
15
-
16
14
  var ViewportMetrics = {
17
15
 
18
16
  currentScrollLeft: 0,
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;
@@ -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.
@@ -13,7 +13,7 @@
13
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() {
@@ -0,0 +1,52 @@
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
+
15
+ var ReactComponent = require("./ReactComponent");
16
+ var ReactInstanceMap = require("./ReactInstanceMap");
17
+ var ReactMount = require("./ReactMount");
18
+
19
+ var invariant = require("./invariant");
20
+ var isNode = require("./isNode");
21
+
22
+ /**
23
+ * Returns the DOM node rendered by this element.
24
+ *
25
+ * @param {ReactComponent|DOMElement} element
26
+ * @return {DOMElement} The root node of this element.
27
+ */
28
+ function findDOMNode(componentOrElement) {
29
+ if (componentOrElement == null) {
30
+ return null;
31
+ }
32
+ if (isNode(componentOrElement)) {
33
+ return componentOrElement;
34
+ }
35
+ if (ReactInstanceMap.has(componentOrElement)) {
36
+ return ReactMount.getNodeFromInstance(componentOrElement);
37
+ }
38
+ ("production" !== process.env.NODE_ENV ? invariant(
39
+ !(componentOrElement.render != null && typeof(componentOrElement.render) === 'function'),
40
+ 'Component contains `render` method but is not mounted in the DOM',
41
+ Object.keys(componentOrElement)
42
+ ) : invariant(
43
+ !(componentOrElement.render != null && typeof(componentOrElement.render) === 'function')
44
+ ));
45
+ ("production" !== process.env.NODE_ENV ? invariant(
46
+ false,
47
+ 'Element appears to be neither ReactComponent nor DOMNode (keys: %s)',
48
+ Object.keys(componentOrElement)
49
+ ) : invariant(false));
50
+ }
51
+
52
+ module.exports = findDOMNode;
@@ -11,8 +11,6 @@
11
11
 
12
12
  "use strict";
13
13
 
14
- var ReactTextComponent = require("./ReactTextComponent");
15
-
16
14
  var traverseAllChildren = require("./traverseAllChildren");
17
15
  var warning = require("./warning");
18
16
 
@@ -33,18 +31,7 @@ function flattenSingleChildIntoContext(traverseContext, child, name) {
33
31
  name
34
32
  ) : null);
35
33
  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;
34
+ result[name] = child;
48
35
  }
49
36
  }
50
37
 
@@ -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;
@@ -12,97 +12,120 @@
12
12
 
13
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
  }