react 15.1.0 → 15.2.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 (124) hide show
  1. package/dist/react-with-addons.js +2685 -1842
  2. package/dist/react-with-addons.min.js +6 -6
  3. package/dist/react.js +2400 -1691
  4. package/dist/react.min.js +6 -6
  5. package/lib/CSSPropertyOperations.js +1 -1
  6. package/lib/CallbackQueue.js +3 -2
  7. package/lib/DOMChildrenOperations.js +9 -9
  8. package/lib/DOMLazyTree.js +3 -2
  9. package/lib/DOMProperty.js +5 -12
  10. package/lib/DOMPropertyOperations.js +21 -15
  11. package/lib/Danger.js +5 -101
  12. package/lib/DisabledInputUtils.js +5 -5
  13. package/lib/EventPluginHub.js +8 -2
  14. package/lib/EventPluginRegistry.js +13 -7
  15. package/lib/EventPluginUtils.js +3 -1
  16. package/lib/HTMLDOMPropertyConfig.js +1 -2
  17. package/lib/KeyEscapeUtils.js +2 -1
  18. package/lib/LinkedValueUtils.js +5 -3
  19. package/lib/NativeMethodsMixin.js +6 -4
  20. package/lib/PooledClass.js +4 -2
  21. package/lib/React.js +1 -1
  22. package/lib/ReactCSSTransitionGroupChild.js +15 -8
  23. package/lib/ReactChildReconciler.js +17 -8
  24. package/lib/ReactClass.js +14 -13
  25. package/lib/ReactComponent.js +3 -6
  26. package/lib/ReactComponentEnvironment.js +3 -1
  27. package/lib/ReactComponentTreeDevtool.js +89 -16
  28. package/lib/ReactComponentTreeTestUtils.js +87 -0
  29. package/lib/ReactCompositeComponent.js +87 -117
  30. package/lib/ReactDOM.js +2 -2
  31. package/lib/ReactDOMButton.js +2 -2
  32. package/lib/ReactDOMComponent.js +130 -76
  33. package/lib/ReactDOMComponentTree.js +23 -21
  34. package/lib/ReactDOMDebugTool.js +17 -11
  35. package/lib/ReactDOMEmptyComponent.js +9 -9
  36. package/lib/ReactDOMFactories.js +1 -1
  37. package/lib/ReactDOMFiber.js +78 -0
  38. package/lib/ReactDOMInput.js +64 -26
  39. package/lib/ReactDOMInstrumentation.js +7 -2
  40. package/lib/ReactDOMNullInputValuePropDevtool.js +43 -0
  41. package/lib/ReactDOMOption.js +40 -26
  42. package/lib/ReactDOMSelect.js +3 -16
  43. package/lib/ReactDOMTextComponent.js +21 -20
  44. package/lib/ReactDOMTextarea.js +59 -46
  45. package/lib/ReactDOMTreeTraversal.js +18 -16
  46. package/lib/ReactDOMUnknownPropertyDevtool.js +65 -17
  47. package/lib/ReactDebugTool.js +148 -95
  48. package/lib/ReactDefaultInjection.js +2 -2
  49. package/lib/ReactElement.js +64 -25
  50. package/lib/ReactElementValidator.js +26 -81
  51. package/lib/ReactEventListener.js +2 -2
  52. package/lib/ReactFeatureFlags.js +1 -0
  53. package/lib/ReactFragment.js +3 -1
  54. package/lib/{ReactNativeComponent.js → ReactHostComponent.js} +10 -29
  55. package/lib/{ReactNativeOperationHistoryDevtool.js → ReactHostOperationHistoryDevtool.js} +5 -5
  56. package/lib/ReactInjection.js +2 -2
  57. package/lib/ReactInstanceHandles.js +8 -6
  58. package/lib/ReactInstrumentation.js +7 -2
  59. package/lib/ReactMount.js +38 -32
  60. package/lib/ReactMultiChild.js +38 -11
  61. package/lib/ReactNativeAttributePayload.js +5 -2
  62. package/lib/ReactNativeBaseComponent.js +7 -7
  63. package/lib/ReactNativeBridgeEventPlugin.js +1 -1
  64. package/lib/ReactNativeComponentTree.js +8 -6
  65. package/lib/ReactNativeDOMIDOperations.js +1 -2
  66. package/lib/ReactNativeDefaultInjection.js +9 -7
  67. package/lib/ReactNativeGlobalResponderHandler.js +1 -1
  68. package/lib/ReactNativeMount.js +3 -14
  69. package/lib/ReactNativeReconcileTransaction.js +16 -0
  70. package/lib/ReactNativeTagHandles.js +3 -1
  71. package/lib/ReactNativeTextComponent.js +10 -9
  72. package/lib/ReactNativeTreeTraversal.js +11 -11
  73. package/lib/ReactNodeTypes.js +6 -3
  74. package/lib/ReactNoop.js +173 -0
  75. package/lib/ReactNoopUpdateQueue.js +6 -5
  76. package/lib/ReactOwner.js +4 -2
  77. package/lib/ReactPerf.js +83 -7
  78. package/lib/ReactPropTypes.js +23 -0
  79. package/lib/ReactReconcileTransaction.js +17 -1
  80. package/lib/ReactReconciler.js +12 -7
  81. package/lib/ReactServerRendering.js +5 -7
  82. package/lib/ReactServerRenderingTransaction.js +17 -0
  83. package/lib/ReactServerUpdateQueue.js +141 -0
  84. package/lib/ReactSimpleEmptyComponent.js +4 -4
  85. package/lib/ReactTestMount.js +115 -0
  86. package/lib/ReactTestReconcileTransaction.js +108 -0
  87. package/lib/ReactTestRenderer.js +133 -0
  88. package/lib/ReactTestUtils.js +17 -10
  89. package/lib/ReactTransitionChildMapping.js +7 -1
  90. package/lib/ReactTransitionGroup.js +41 -6
  91. package/lib/ReactUpdateQueue.js +13 -3
  92. package/lib/ReactUpdates.js +10 -18
  93. package/lib/ReactVersion.js +1 -1
  94. package/lib/ResponderEventPlugin.js +9 -7
  95. package/lib/ResponderTouchHistoryStore.js +99 -95
  96. package/lib/SimpleEventPlugin.js +3 -1
  97. package/lib/SyntheticEvent.js +2 -3
  98. package/lib/SyntheticUIEvent.js +1 -1
  99. package/lib/Transaction.js +4 -2
  100. package/lib/accumulate.js +17 -15
  101. package/lib/accumulateInto.js +11 -12
  102. package/lib/adler32.js +1 -0
  103. package/lib/checkReactTypeSpec.js +73 -0
  104. package/lib/createReactNativeComponentClass.js +2 -2
  105. package/lib/dangerousStyleValue.js +3 -1
  106. package/lib/deprecated.js +7 -1
  107. package/lib/escapeTextContentForBrowser.js +96 -12
  108. package/lib/findDOMNode.js +6 -4
  109. package/lib/findNodeHandle.js +5 -3
  110. package/lib/flattenChildren.js +22 -10
  111. package/lib/forEachAccumulated.js +3 -2
  112. package/lib/{getNativeComponentFromComposite.js → getHostComponentFromComposite.js} +4 -4
  113. package/lib/getIteratorFn.js +1 -0
  114. package/lib/instantiateReactComponent.js +21 -19
  115. package/lib/isTextInputElement.js +11 -1
  116. package/lib/onlyChild.js +3 -1
  117. package/lib/reactComponentExpect.js +3 -3
  118. package/lib/reactProdInvariant.js +39 -0
  119. package/lib/setInnerHTML.js +17 -1
  120. package/lib/setTextContent.js +8 -0
  121. package/lib/traverseAllChildren.js +3 -1
  122. package/lib/update.js +12 -11
  123. package/package.json +2 -2
  124. package/lib/MetaMatchers.js +0 -118
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Copyright 2015-present, 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 ReactServerUpdateQueue
10
+ *
11
+ */
12
+
13
+ 'use strict';
14
+
15
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
+
17
+ var ReactUpdateQueue = require('./ReactUpdateQueue');
18
+ var Transaction = require('./Transaction');
19
+ var warning = require('fbjs/lib/warning');
20
+
21
+ function warnNoop(publicInstance, callerName) {
22
+ if (process.env.NODE_ENV !== 'production') {
23
+ var constructor = publicInstance.constructor;
24
+ process.env.NODE_ENV !== 'production' ? warning(false, '%s(...): Can only update a mounting component. ' + 'This usually means you called %s() outside componentWillMount() on the server. ' + 'This is a no-op. Please check the code for the %s component.', callerName, callerName, constructor && (constructor.displayName || constructor.name) || 'ReactClass') : void 0;
25
+ }
26
+ }
27
+
28
+ /**
29
+ * This is the update queue used for server rendering.
30
+ * It delegates to ReactUpdateQueue while server rendering is in progress and
31
+ * switches to ReactNoopUpdateQueue after the transaction has completed.
32
+ * @class ReactServerUpdateQueue
33
+ * @param {Transaction} transaction
34
+ */
35
+
36
+ var ReactServerUpdateQueue = function () {
37
+ /* :: transaction: Transaction; */
38
+
39
+ function ReactServerUpdateQueue(transaction) {
40
+ _classCallCheck(this, ReactServerUpdateQueue);
41
+
42
+ this.transaction = transaction;
43
+ }
44
+
45
+ /**
46
+ * Checks whether or not this composite component is mounted.
47
+ * @param {ReactClass} publicInstance The instance we want to test.
48
+ * @return {boolean} True if mounted, false otherwise.
49
+ * @protected
50
+ * @final
51
+ */
52
+
53
+
54
+ ReactServerUpdateQueue.prototype.isMounted = function isMounted(publicInstance) {
55
+ return false;
56
+ };
57
+
58
+ /**
59
+ * Enqueue a callback that will be executed after all the pending updates
60
+ * have processed.
61
+ *
62
+ * @param {ReactClass} publicInstance The instance to use as `this` context.
63
+ * @param {?function} callback Called after state is updated.
64
+ * @internal
65
+ */
66
+
67
+
68
+ ReactServerUpdateQueue.prototype.enqueueCallback = function enqueueCallback(publicInstance, callback, callerName) {
69
+ if (this.transaction.isInTransaction()) {
70
+ ReactUpdateQueue.enqueueCallback(publicInstance, callback, callerName);
71
+ }
72
+ };
73
+
74
+ /**
75
+ * Forces an update. This should only be invoked when it is known with
76
+ * certainty that we are **not** in a DOM transaction.
77
+ *
78
+ * You may want to call this when you know that some deeper aspect of the
79
+ * component's state has changed but `setState` was not called.
80
+ *
81
+ * This will not invoke `shouldComponentUpdate`, but it will invoke
82
+ * `componentWillUpdate` and `componentDidUpdate`.
83
+ *
84
+ * @param {ReactClass} publicInstance The instance that should rerender.
85
+ * @internal
86
+ */
87
+
88
+
89
+ ReactServerUpdateQueue.prototype.enqueueForceUpdate = function enqueueForceUpdate(publicInstance) {
90
+ if (this.transaction.isInTransaction()) {
91
+ ReactUpdateQueue.enqueueForceUpdate(publicInstance);
92
+ } else {
93
+ warnNoop(publicInstance, 'forceUpdate');
94
+ }
95
+ };
96
+
97
+ /**
98
+ * Replaces all of the state. Always use this or `setState` to mutate state.
99
+ * You should treat `this.state` as immutable.
100
+ *
101
+ * There is no guarantee that `this.state` will be immediately updated, so
102
+ * accessing `this.state` after calling this method may return the old value.
103
+ *
104
+ * @param {ReactClass} publicInstance The instance that should rerender.
105
+ * @param {object|function} completeState Next state.
106
+ * @internal
107
+ */
108
+
109
+
110
+ ReactServerUpdateQueue.prototype.enqueueReplaceState = function enqueueReplaceState(publicInstance, completeState) {
111
+ if (this.transaction.isInTransaction()) {
112
+ ReactUpdateQueue.enqueueReplaceState(publicInstance, completeState);
113
+ } else {
114
+ warnNoop(publicInstance, 'replaceState');
115
+ }
116
+ };
117
+
118
+ /**
119
+ * Sets a subset of the state. This only exists because _pendingState is
120
+ * internal. This provides a merging strategy that is not available to deep
121
+ * properties which is confusing. TODO: Expose pendingState or don't use it
122
+ * during the merge.
123
+ *
124
+ * @param {ReactClass} publicInstance The instance that should rerender.
125
+ * @param {object|function} partialState Next partial state to be merged with state.
126
+ * @internal
127
+ */
128
+
129
+
130
+ ReactServerUpdateQueue.prototype.enqueueSetState = function enqueueSetState(publicInstance, partialState) {
131
+ if (this.transaction.isInTransaction()) {
132
+ ReactUpdateQueue.enqueueSetState(publicInstance, partialState);
133
+ } else {
134
+ warnNoop(publicInstance, 'setState');
135
+ }
136
+ };
137
+
138
+ return ReactServerUpdateQueue;
139
+ }();
140
+
141
+ module.exports = ReactServerUpdateQueue;
@@ -20,12 +20,12 @@ var ReactSimpleEmptyComponent = function (placeholderElement, instantiate) {
20
20
  this._renderedComponent = instantiate(placeholderElement);
21
21
  };
22
22
  _assign(ReactSimpleEmptyComponent.prototype, {
23
- mountComponent: function (transaction, nativeParent, nativeContainerInfo, context) {
24
- return ReactReconciler.mountComponent(this._renderedComponent, transaction, nativeParent, nativeContainerInfo, context);
23
+ mountComponent: function (transaction, hostParent, hostContainerInfo, context) {
24
+ return ReactReconciler.mountComponent(this._renderedComponent, transaction, hostParent, hostContainerInfo, context);
25
25
  },
26
26
  receiveComponent: function () {},
27
- getNativeNode: function () {
28
- return ReactReconciler.getNativeNode(this._renderedComponent);
27
+ getHostNode: function () {
28
+ return ReactReconciler.getHostNode(this._renderedComponent);
29
29
  },
30
30
  unmountComponent: function () {
31
31
  ReactReconciler.unmountComponent(this._renderedComponent);
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Copyright (c) 2015-present, 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 ReactTestMount
10
+ *
11
+ */
12
+ 'use strict';
13
+
14
+ var ReactElement = require('./ReactElement');
15
+ var ReactInstrumentation = require('./ReactInstrumentation');
16
+ var ReactReconciler = require('./ReactReconciler');
17
+ var ReactUpdates = require('./ReactUpdates');
18
+
19
+ var emptyObject = require('fbjs/lib/emptyObject');
20
+ var getHostComponentFromComposite = require('./getHostComponentFromComposite');
21
+ var instantiateReactComponent = require('./instantiateReactComponent');
22
+
23
+ /**
24
+ * Temporary (?) hack so that we can store all top-level pending updates on
25
+ * composites instead of having to worry about different types of components
26
+ * here.
27
+ */
28
+ var TopLevelWrapper = function () {};
29
+ TopLevelWrapper.prototype.isReactComponent = {};
30
+ if (process.env.NODE_ENV !== 'production') {
31
+ TopLevelWrapper.displayName = 'TopLevelWrapper';
32
+ }
33
+ TopLevelWrapper.prototype.render = function () {
34
+ // this.props is actually a ReactElement
35
+ return this.props;
36
+ };
37
+
38
+ /**
39
+ * Mounts this component and inserts it into the DOM.
40
+ *
41
+ * @param {ReactComponent} componentInstance The instance to mount.
42
+ * @param {number} rootID ID of the root node.
43
+ * @param {number} containerTag container element to mount into.
44
+ * @param {ReactReconcileTransaction} transaction
45
+ */
46
+ function mountComponentIntoNode(componentInstance, transaction) {
47
+ var image = ReactReconciler.mountComponent(componentInstance, transaction, null, null, emptyObject);
48
+ componentInstance._renderedComponent._topLevelWrapper = componentInstance;
49
+ return image;
50
+ }
51
+
52
+ /**
53
+ * Batched mount.
54
+ *
55
+ * @param {ReactComponent} componentInstance The instance to mount.
56
+ * @param {number} rootID ID of the root node.
57
+ * @param {number} containerTag container element to mount into.
58
+ */
59
+ function batchedMountComponentIntoNode(componentInstance) {
60
+ var transaction = ReactUpdates.ReactReconcileTransaction.getPooled();
61
+ var image = transaction.perform(mountComponentIntoNode, null, componentInstance, transaction);
62
+ ReactUpdates.ReactReconcileTransaction.release(transaction);
63
+ return image;
64
+ }
65
+
66
+ var ReactTestInstance = function (component) {
67
+ this._component = component;
68
+ };
69
+ ReactTestInstance.prototype.getInstance = function () {
70
+ return this._component._renderedComponent.getPublicInstance();
71
+ };
72
+ ReactTestInstance.prototype.toJSON = function () {
73
+ var inst = getHostComponentFromComposite(this._component);
74
+ return inst.toJSON();
75
+ };
76
+
77
+ /**
78
+ * As soon as `ReactMount` is refactored to not rely on the DOM, we can share
79
+ * code between the two. For now, we'll hard code the ID logic.
80
+ */
81
+ var ReactHostMount = {
82
+
83
+ render: function (nextElement) {
84
+ var nextWrappedElement = new ReactElement(TopLevelWrapper, null, null, null, null, null, nextElement);
85
+
86
+ // var prevComponent = ReactHostMount._instancesByContainerID[containerTag];
87
+ // if (prevComponent) {
88
+ // var prevWrappedElement = prevComponent._currentElement;
89
+ // var prevElement = prevWrappedElement.props;
90
+ // if (shouldUpdateReactComponent(prevElement, nextElement)) {
91
+ // ReactUpdateQueue.enqueueElementInternal(prevComponent, nextWrappedElement);
92
+ // if (callback) {
93
+ // ReactUpdateQueue.enqueueCallbackInternal(prevComponent, callback);
94
+ // }
95
+ // return prevComponent;
96
+ // }
97
+ // }
98
+
99
+ var instance = instantiateReactComponent(nextWrappedElement, false);
100
+
101
+ // The initial render is synchronous but any updates that happen during
102
+ // rendering, in componentWillMount or componentDidMount, will be batched
103
+ // according to the current batching strategy.
104
+
105
+ ReactUpdates.batchedUpdates(batchedMountComponentIntoNode, instance);
106
+ if (process.env.NODE_ENV !== 'production') {
107
+ // The instance here is TopLevelWrapper so we report mount for its child.
108
+ ReactInstrumentation.debugTool.onMountRootComponent(instance._renderedComponent._debugID);
109
+ }
110
+ return new ReactTestInstance(instance);
111
+ }
112
+
113
+ };
114
+
115
+ module.exports = ReactHostMount;
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Copyright (c) 2015-present, 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 ReactTestReconcileTransaction
10
+ *
11
+ */
12
+ 'use strict';
13
+
14
+ var _assign = require('object-assign');
15
+
16
+ var CallbackQueue = require('./CallbackQueue');
17
+ var PooledClass = require('./PooledClass');
18
+ var Transaction = require('./Transaction');
19
+ var ReactUpdateQueue = require('./ReactUpdateQueue');
20
+
21
+ /**
22
+ * Provides a `CallbackQueue` queue for collecting `onDOMReady` callbacks during
23
+ * the performing of the transaction.
24
+ */
25
+ var ON_DOM_READY_QUEUEING = {
26
+ /**
27
+ * Initializes the internal `onDOMReady` queue.
28
+ */
29
+ initialize: function () {
30
+ this.reactMountReady.reset();
31
+ },
32
+
33
+ /**
34
+ * After DOM is flushed, invoke all registered `onDOMReady` callbacks.
35
+ */
36
+ close: function () {
37
+ this.reactMountReady.notifyAll();
38
+ }
39
+ };
40
+
41
+ /**
42
+ * Executed within the scope of the `Transaction` instance. Consider these as
43
+ * being member methods, but with an implied ordering while being isolated from
44
+ * each other.
45
+ */
46
+ var TRANSACTION_WRAPPERS = [ON_DOM_READY_QUEUEING];
47
+
48
+ /**
49
+ * Currently:
50
+ * - The order that these are listed in the transaction is critical:
51
+ * - Suppresses events.
52
+ * - Restores selection range.
53
+ *
54
+ * Future:
55
+ * - Restore document/overflow scroll positions that were unintentionally
56
+ * modified via DOM insertions above the top viewport boundary.
57
+ * - Implement/integrate with customized constraint based layout system and keep
58
+ * track of which dimensions must be remeasured.
59
+ *
60
+ * @class ReactTestReconcileTransaction
61
+ */
62
+ function ReactTestReconcileTransaction() {
63
+ this.reinitializeTransaction();
64
+ this.reactMountReady = CallbackQueue.getPooled(null);
65
+ }
66
+
67
+ var Mixin = {
68
+ /**
69
+ * @see Transaction
70
+ * @abstract
71
+ * @final
72
+ * @return {array<object>} List of operation wrap procedures.
73
+ * TODO: convert to array<TransactionWrapper>
74
+ */
75
+ getTransactionWrappers: function () {
76
+ return TRANSACTION_WRAPPERS;
77
+ },
78
+
79
+ /**
80
+ * @return {object} The queue to collect `onDOMReady` callbacks with.
81
+ * TODO: convert to ReactMountReady
82
+ */
83
+ getReactMountReady: function () {
84
+ return this.reactMountReady;
85
+ },
86
+
87
+ /**
88
+ * @return {object} The queue to collect React async events.
89
+ */
90
+ getUpdateQueue: function () {
91
+ return ReactUpdateQueue;
92
+ },
93
+
94
+ /**
95
+ * `PooledClass` looks for this, and will invoke this before allowing this
96
+ * instance to be reused.
97
+ */
98
+ destructor: function () {
99
+ CallbackQueue.release(this.reactMountReady);
100
+ this.reactMountReady = null;
101
+ }
102
+ };
103
+
104
+ _assign(ReactTestReconcileTransaction.prototype, Transaction.Mixin, ReactTestReconcileTransaction, Mixin);
105
+
106
+ PooledClass.addPoolingTo(ReactTestReconcileTransaction);
107
+
108
+ module.exports = ReactTestReconcileTransaction;
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Copyright 2013-present, 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 ReactTestRenderer
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ var _assign = require('object-assign');
15
+
16
+ function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
17
+
18
+ var ReactDefaultBatchingStrategy = require('./ReactDefaultBatchingStrategy');
19
+ var ReactEmptyComponent = require('./ReactEmptyComponent');
20
+ var ReactMultiChild = require('./ReactMultiChild');
21
+ var ReactHostComponent = require('./ReactHostComponent');
22
+ var ReactTestMount = require('./ReactTestMount');
23
+ var ReactTestReconcileTransaction = require('./ReactTestReconcileTransaction');
24
+ var ReactUpdates = require('./ReactUpdates');
25
+
26
+ var renderSubtreeIntoContainer = require('./renderSubtreeIntoContainer');
27
+
28
+ /**
29
+ * Drill down (through composites and empty components) until we get a native or
30
+ * native text component.
31
+ *
32
+ * This is pretty polymorphic but unavoidable with the current structure we have
33
+ * for `_renderedChildren`.
34
+ */
35
+ function getRenderedHostOrTextFromComponent(component) {
36
+ var rendered;
37
+ while (rendered = component._renderedComponent) {
38
+ component = rendered;
39
+ }
40
+ return component;
41
+ }
42
+
43
+ // =============================================================================
44
+
45
+ var ReactTestComponent = function (element) {
46
+ this._currentElement = element;
47
+ this._renderedChildren = null;
48
+ this._topLevelWrapper = null;
49
+ };
50
+ ReactTestComponent.prototype.mountComponent = function (transaction, nativeParent, nativeContainerInfo, context) {
51
+ var element = this._currentElement;
52
+ this.mountChildren(element.props.children, transaction, context);
53
+ };
54
+ ReactTestComponent.prototype.receiveComponent = function (nextElement, transaction, context) {
55
+ this._currentElement = nextElement;
56
+ this.updateChildren(nextElement.props.children, transaction, context);
57
+ };
58
+ ReactTestComponent.prototype.getHostNode = function () {};
59
+ ReactTestComponent.prototype.unmountComponent = function () {};
60
+ ReactTestComponent.prototype.toJSON = function () {
61
+ var _currentElement$props = this._currentElement.props;
62
+ var children = _currentElement$props.children;
63
+
64
+ var props = _objectWithoutProperties(_currentElement$props, ['children']);
65
+
66
+ var childrenJSON = [];
67
+ for (var key in this._renderedChildren) {
68
+ var inst = this._renderedChildren[key];
69
+ inst = getRenderedHostOrTextFromComponent(inst);
70
+ var json = inst.toJSON();
71
+ if (json !== undefined) {
72
+ childrenJSON.push(json);
73
+ }
74
+ }
75
+ var object = {
76
+ type: this._currentElement.type,
77
+ props: props,
78
+ children: childrenJSON.length ? childrenJSON : null
79
+ };
80
+ Object.defineProperty(object, '$$typeof', {
81
+ value: Symbol['for']('react.test.json')
82
+ });
83
+ return object;
84
+ };
85
+ _assign(ReactTestComponent.prototype, ReactMultiChild.Mixin);
86
+
87
+ // =============================================================================
88
+
89
+ var ReactTestTextComponent = function (element) {
90
+ this._currentElement = element;
91
+ };
92
+ ReactTestTextComponent.prototype.mountComponent = function () {};
93
+ ReactTestTextComponent.prototype.receiveComponent = function (nextElement) {
94
+ this._currentElement = nextElement;
95
+ };
96
+ ReactTestTextComponent.prototype.getHostNode = function () {};
97
+ ReactTestTextComponent.prototype.unmountComponent = function () {};
98
+ ReactTestTextComponent.prototype.toJSON = function () {
99
+ return this._currentElement;
100
+ };
101
+
102
+ // =============================================================================
103
+
104
+ var ReactTestEmptyComponent = function (element) {
105
+ this._currentElement = null;
106
+ };
107
+ ReactTestEmptyComponent.prototype.mountComponent = function () {};
108
+ ReactTestEmptyComponent.prototype.receiveComponent = function () {};
109
+ ReactTestEmptyComponent.prototype.getHostNode = function () {};
110
+ ReactTestEmptyComponent.prototype.unmountComponent = function () {};
111
+ ReactTestEmptyComponent.prototype.toJSON = function () {};
112
+
113
+ // =============================================================================
114
+
115
+ ReactUpdates.injection.injectReconcileTransaction(ReactTestReconcileTransaction);
116
+ ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy);
117
+
118
+ ReactHostComponent.injection.injectGenericComponentClass(ReactTestComponent);
119
+ ReactHostComponent.injection.injectTextComponentClass(ReactTestTextComponent);
120
+ ReactEmptyComponent.injection.injectEmptyComponentFactory(function () {
121
+ return new ReactTestEmptyComponent();
122
+ });
123
+
124
+ var ReactTestRenderer = {
125
+ create: ReactTestMount.render,
126
+
127
+ /* eslint-disable camelcase */
128
+ unstable_batchedUpdates: ReactUpdates.batchedUpdates,
129
+ unstable_renderSubtreeIntoContainer: renderSubtreeIntoContainer
130
+ };
131
+
132
+ /* eslint-enable camelcase */
133
+ module.exports = ReactTestRenderer;