react 15.0.3-alpha.2 → 15.2.0-rc.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.
- package/dist/react-with-addons.js +3324 -2009
- package/dist/react-with-addons.min.js +7 -6
- package/dist/react.js +2736 -2005
- package/dist/react.min.js +6 -6
- package/lib/CSSPropertyOperations.js +5 -5
- package/lib/CallbackQueue.js +3 -2
- package/lib/DOMChildrenOperations.js +42 -7
- package/lib/DOMLazyTree.js +9 -3
- package/lib/DOMProperty.js +6 -4
- package/lib/DOMPropertyOperations.js +35 -12
- package/lib/Danger.js +10 -8
- package/lib/DisabledInputUtils.js +5 -5
- package/lib/EventPluginHub.js +8 -2
- package/lib/EventPluginRegistry.js +13 -7
- package/lib/EventPluginUtils.js +3 -1
- package/lib/HTMLDOMPropertyConfig.js +1 -2
- package/lib/LinkedStateMixin.js +1 -0
- package/lib/LinkedValueUtils.js +5 -3
- package/lib/NativeMethodsMixin.js +6 -4
- package/lib/PooledClass.js +3 -1
- package/lib/React.js +1 -1
- package/lib/ReactCSSTransitionGroup.js +5 -0
- package/lib/ReactCSSTransitionGroupChild.js +15 -8
- package/lib/ReactChildReconciler.js +15 -6
- package/lib/ReactChildren.js +9 -1
- package/lib/ReactClass.js +15 -13
- package/lib/ReactComponent.js +3 -6
- package/lib/ReactComponentBrowserEnvironment.js +0 -5
- package/lib/ReactComponentEnvironment.js +3 -1
- package/lib/ReactComponentTreeDevtool.js +223 -0
- package/lib/ReactComponentTreeTestUtils.js +87 -0
- package/lib/ReactComponentWithPureRenderMixin.js +2 -0
- package/lib/ReactCompositeComponent.js +208 -119
- package/lib/ReactDOM.js +3 -6
- package/lib/ReactDOMButton.js +2 -2
- package/lib/ReactDOMComponent.js +162 -68
- package/lib/ReactDOMComponentTree.js +23 -21
- package/lib/ReactDOMDebugTool.js +7 -1
- package/lib/ReactDOMEmptyComponent.js +9 -9
- package/lib/ReactDOMFactories.js +1 -1
- package/lib/ReactDOMIDOperations.js +0 -5
- package/lib/ReactDOMInput.js +56 -18
- package/lib/ReactDOMOption.js +40 -26
- package/lib/ReactDOMSelect.js +3 -3
- package/lib/ReactDOMTextComponent.js +28 -26
- package/lib/ReactDOMTextarea.js +59 -32
- package/lib/ReactDOMTreeTraversal.js +18 -16
- package/lib/ReactDOMUnknownPropertyDevtool.js +65 -17
- package/lib/ReactDebugTool.js +250 -11
- package/lib/ReactDefaultInjection.js +2 -11
- package/lib/ReactElement.js +90 -25
- package/lib/ReactElementValidator.js +26 -81
- package/lib/ReactEventListener.js +2 -2
- package/lib/ReactFragment.js +8 -3
- package/lib/{ReactNativeComponent.js → ReactHostComponent.js} +10 -29
- package/lib/ReactHostOperationHistoryDevtool.js +37 -0
- package/lib/ReactInjection.js +2 -4
- package/lib/ReactInstanceHandles.js +8 -6
- package/lib/ReactLink.js +3 -0
- package/lib/ReactMount.js +43 -20
- package/lib/ReactMultiChild.js +51 -8
- package/lib/ReactNativeAttributePayload.js +5 -2
- package/lib/ReactNativeBaseComponent.js +7 -7
- package/lib/ReactNativeBridgeEventPlugin.js +1 -1
- package/lib/ReactNativeComponentTree.js +8 -6
- package/lib/ReactNativeDOMIDOperations.js +4 -8
- package/lib/ReactNativeDefaultInjection.js +9 -7
- package/lib/ReactNativeGlobalResponderHandler.js +1 -1
- package/lib/ReactNativeMount.js +25 -8
- package/lib/ReactNativeTagHandles.js +3 -1
- package/lib/ReactNativeTextComponent.js +18 -9
- package/lib/ReactNativeTreeTraversal.js +11 -11
- package/lib/ReactNodeTypes.js +5 -3
- package/lib/ReactNoop.js +76 -0
- package/lib/ReactOwner.js +4 -2
- package/lib/ReactPerf.js +473 -75
- package/lib/ReactPropTypes.js +23 -0
- package/lib/ReactReconcileTransaction.js +1 -1
- package/lib/ReactReconciler.js +57 -11
- package/lib/ReactServerRendering.js +24 -3
- package/lib/ReactSimpleEmptyComponent.js +4 -4
- package/lib/ReactTestMount.js +126 -0
- package/lib/ReactTestReconcileTransaction.js +100 -0
- package/lib/ReactTestRenderer.js +133 -0
- package/lib/ReactTestUtils.js +25 -10
- package/lib/ReactTransitionChildMapping.js +7 -1
- package/lib/ReactTransitionGroup.js +44 -5
- package/lib/ReactUpdateQueue.js +9 -1
- package/lib/ReactUpdates.js +30 -11
- package/lib/ReactVersion.js +1 -1
- package/lib/ReactWithAddons.js +1 -1
- package/lib/ResponderEventPlugin.js +8 -6
- package/lib/ResponderTouchHistoryStore.js +6 -4
- package/lib/SimpleEventPlugin.js +3 -1
- package/lib/SyntheticEvent.js +2 -3
- package/lib/SyntheticUIEvent.js +1 -1
- package/lib/Transaction.js +4 -2
- package/lib/accumulate.js +3 -1
- package/lib/accumulateInto.js +3 -1
- package/lib/checkReactTypeSpec.js +71 -0
- package/lib/createReactNativeComponentClass.js +2 -2
- package/lib/dangerousStyleValue.js +3 -1
- package/lib/escapeTextContentForBrowser.js +96 -12
- package/lib/findDOMNode.js +8 -4
- package/lib/findNodeHandle.js +5 -3
- package/lib/flattenChildren.js +13 -4
- package/lib/{getNativeComponentFromComposite.js → getHostComponentFromComposite.js} +4 -4
- package/lib/instantiateReactComponent.js +44 -10
- package/lib/onlyChild.js +10 -5
- package/lib/reactComponentExpect.js +3 -3
- package/lib/reactProdInvariant.js +38 -0
- package/lib/setInnerHTML.js +17 -1
- package/lib/setTextContent.js +8 -0
- package/lib/shallowCompare.js +1 -0
- package/lib/traverseAllChildren.js +3 -1
- package/lib/update.js +16 -11
- package/package.json +2 -2
- package/lib/MetaMatchers.js +0 -118
- package/lib/ReactDebugInstanceMap.js +0 -102
- package/lib/ReactDefaultPerf.js +0 -316
- package/lib/ReactDefaultPerfAnalysis.js +0 -210
package/lib/ReactPropTypes.js
CHANGED
|
@@ -73,6 +73,7 @@ var ReactPropTypes = {
|
|
|
73
73
|
number: createPrimitiveTypeChecker('number'),
|
|
74
74
|
object: createPrimitiveTypeChecker('object'),
|
|
75
75
|
string: createPrimitiveTypeChecker('string'),
|
|
76
|
+
symbol: createPrimitiveTypeChecker('symbol'),
|
|
76
77
|
|
|
77
78
|
any: createAnyTypeChecker(),
|
|
78
79
|
arrayOf: createArrayOfTypeChecker,
|
|
@@ -340,6 +341,25 @@ function isNode(propValue) {
|
|
|
340
341
|
}
|
|
341
342
|
}
|
|
342
343
|
|
|
344
|
+
function isSymbol(propType, propValue) {
|
|
345
|
+
// Native Symbol.
|
|
346
|
+
if (propType === 'symbol') {
|
|
347
|
+
return true;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
|
|
351
|
+
if (propValue['@@toStringTag'] === 'Symbol') {
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// Fallback for non-spec compliant Symbols which are polyfilled.
|
|
356
|
+
if (typeof Symbol === 'function' && propValue instanceof Symbol) {
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
|
|
343
363
|
// Equivalent of `typeof` but with special handling for array and regexp.
|
|
344
364
|
function getPropType(propValue) {
|
|
345
365
|
var propType = typeof propValue;
|
|
@@ -352,6 +372,9 @@ function getPropType(propValue) {
|
|
|
352
372
|
// passes PropTypes.object.
|
|
353
373
|
return 'object';
|
|
354
374
|
}
|
|
375
|
+
if (isSymbol(propType, propValue)) {
|
|
376
|
+
return 'symbol';
|
|
377
|
+
}
|
|
355
378
|
return propType;
|
|
356
379
|
}
|
|
357
380
|
|
|
@@ -107,7 +107,7 @@ function ReactReconcileTransaction(useCreateElement) {
|
|
|
107
107
|
// `ReactServerRendering`), but server-side uses
|
|
108
108
|
// `ReactServerRenderingTransaction` instead. This option is here so that it's
|
|
109
109
|
// accessible and defaults to false when `ReactDOMComponent` and
|
|
110
|
-
// `
|
|
110
|
+
// `ReactDOMTextComponent` checks it in `mountComponent`.`
|
|
111
111
|
this.renderToStaticMarkup = false;
|
|
112
112
|
this.reactMountReady = CallbackQueue.getPooled(null);
|
|
113
113
|
this.useCreateElement = useCreateElement;
|
package/lib/ReactReconciler.js
CHANGED
|
@@ -11,9 +11,13 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
+
var _prodInvariant = require('./reactProdInvariant');
|
|
15
|
+
|
|
14
16
|
var ReactRef = require('./ReactRef');
|
|
15
17
|
var ReactInstrumentation = require('./ReactInstrumentation');
|
|
16
18
|
|
|
19
|
+
var invariant = require('fbjs/lib/invariant');
|
|
20
|
+
|
|
17
21
|
/**
|
|
18
22
|
* Helper to call ReactRef.attachRefs with this composite component, split out
|
|
19
23
|
* to avoid allocations in the transaction mount-ready queue.
|
|
@@ -29,19 +33,28 @@ var ReactReconciler = {
|
|
|
29
33
|
*
|
|
30
34
|
* @param {ReactComponent} internalInstance
|
|
31
35
|
* @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
|
|
32
|
-
* @param {?object} the containing
|
|
33
|
-
* @param {?object} info about the
|
|
36
|
+
* @param {?object} the containing host component instance
|
|
37
|
+
* @param {?object} info about the host container
|
|
34
38
|
* @return {?string} Rendered markup to be inserted into the DOM.
|
|
35
39
|
* @final
|
|
36
40
|
* @internal
|
|
37
41
|
*/
|
|
38
|
-
mountComponent: function (internalInstance, transaction,
|
|
39
|
-
|
|
42
|
+
mountComponent: function (internalInstance, transaction, hostParent, hostContainerInfo, context) {
|
|
43
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
44
|
+
if (internalInstance._debugID !== 0) {
|
|
45
|
+
ReactInstrumentation.debugTool.onBeforeMountComponent(internalInstance._debugID, internalInstance._currentElement);
|
|
46
|
+
ReactInstrumentation.debugTool.onBeginReconcilerTimer(internalInstance._debugID, 'mountComponent');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
var markup = internalInstance.mountComponent(transaction, hostParent, hostContainerInfo, context);
|
|
40
50
|
if (internalInstance._currentElement && internalInstance._currentElement.ref != null) {
|
|
41
51
|
transaction.getReactMountReady().enqueue(attachRefs, internalInstance);
|
|
42
52
|
}
|
|
43
53
|
if (process.env.NODE_ENV !== 'production') {
|
|
44
|
-
|
|
54
|
+
if (internalInstance._debugID !== 0) {
|
|
55
|
+
ReactInstrumentation.debugTool.onEndReconcilerTimer(internalInstance._debugID, 'mountComponent');
|
|
56
|
+
ReactInstrumentation.debugTool.onMountComponent(internalInstance._debugID);
|
|
57
|
+
}
|
|
45
58
|
}
|
|
46
59
|
return markup;
|
|
47
60
|
},
|
|
@@ -50,8 +63,8 @@ var ReactReconciler = {
|
|
|
50
63
|
* Returns a value that can be passed to
|
|
51
64
|
* ReactComponentEnvironment.replaceNodeWithMarkup.
|
|
52
65
|
*/
|
|
53
|
-
|
|
54
|
-
return internalInstance.
|
|
66
|
+
getHostNode: function (internalInstance) {
|
|
67
|
+
return internalInstance.getHostNode();
|
|
55
68
|
},
|
|
56
69
|
|
|
57
70
|
/**
|
|
@@ -61,10 +74,18 @@ var ReactReconciler = {
|
|
|
61
74
|
* @internal
|
|
62
75
|
*/
|
|
63
76
|
unmountComponent: function (internalInstance, safely) {
|
|
77
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
78
|
+
if (internalInstance._debugID !== 0) {
|
|
79
|
+
ReactInstrumentation.debugTool.onBeginReconcilerTimer(internalInstance._debugID, 'unmountComponent');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
64
82
|
ReactRef.detachRefs(internalInstance, internalInstance._currentElement);
|
|
65
83
|
internalInstance.unmountComponent(safely);
|
|
66
84
|
if (process.env.NODE_ENV !== 'production') {
|
|
67
|
-
|
|
85
|
+
if (internalInstance._debugID !== 0) {
|
|
86
|
+
ReactInstrumentation.debugTool.onEndReconcilerTimer(internalInstance._debugID, 'unmountComponent');
|
|
87
|
+
ReactInstrumentation.debugTool.onUnmountComponent(internalInstance._debugID);
|
|
88
|
+
}
|
|
68
89
|
}
|
|
69
90
|
},
|
|
70
91
|
|
|
@@ -94,6 +115,13 @@ var ReactReconciler = {
|
|
|
94
115
|
return;
|
|
95
116
|
}
|
|
96
117
|
|
|
118
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
119
|
+
if (internalInstance._debugID !== 0) {
|
|
120
|
+
ReactInstrumentation.debugTool.onBeforeUpdateComponent(internalInstance._debugID, nextElement);
|
|
121
|
+
ReactInstrumentation.debugTool.onBeginReconcilerTimer(internalInstance._debugID, 'receiveComponent');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
97
125
|
var refsChanged = ReactRef.shouldUpdateRefs(prevElement, nextElement);
|
|
98
126
|
|
|
99
127
|
if (refsChanged) {
|
|
@@ -107,7 +135,10 @@ var ReactReconciler = {
|
|
|
107
135
|
}
|
|
108
136
|
|
|
109
137
|
if (process.env.NODE_ENV !== 'production') {
|
|
110
|
-
|
|
138
|
+
if (internalInstance._debugID !== 0) {
|
|
139
|
+
ReactInstrumentation.debugTool.onEndReconcilerTimer(internalInstance._debugID, 'receiveComponent');
|
|
140
|
+
ReactInstrumentation.debugTool.onUpdateComponent(internalInstance._debugID);
|
|
141
|
+
}
|
|
111
142
|
}
|
|
112
143
|
},
|
|
113
144
|
|
|
@@ -118,10 +149,25 @@ var ReactReconciler = {
|
|
|
118
149
|
* @param {ReactReconcileTransaction} transaction
|
|
119
150
|
* @internal
|
|
120
151
|
*/
|
|
121
|
-
performUpdateIfNecessary: function (internalInstance, transaction) {
|
|
152
|
+
performUpdateIfNecessary: function (internalInstance, transaction, updateBatchNumber) {
|
|
153
|
+
if (internalInstance._updateBatchNumber !== updateBatchNumber) {
|
|
154
|
+
// The component's enqueued batch number should always be the current
|
|
155
|
+
// batch or the following one.
|
|
156
|
+
!(internalInstance._updateBatchNumber == null || internalInstance._updateBatchNumber === updateBatchNumber + 1) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'performUpdateIfNecessary: Unexpected batch number (current %s, pending %s)', updateBatchNumber, internalInstance._updateBatchNumber) : _prodInvariant('121', updateBatchNumber, internalInstance._updateBatchNumber) : void 0;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
160
|
+
if (internalInstance._debugID !== 0) {
|
|
161
|
+
ReactInstrumentation.debugTool.onBeginReconcilerTimer(internalInstance._debugID, 'performUpdateIfNecessary');
|
|
162
|
+
ReactInstrumentation.debugTool.onBeforeUpdateComponent(internalInstance._debugID, internalInstance._currentElement);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
122
165
|
internalInstance.performUpdateIfNecessary(transaction);
|
|
123
166
|
if (process.env.NODE_ENV !== 'production') {
|
|
124
|
-
|
|
167
|
+
if (internalInstance._debugID !== 0) {
|
|
168
|
+
ReactInstrumentation.debugTool.onEndReconcilerTimer(internalInstance._debugID, 'performUpdateIfNecessary');
|
|
169
|
+
ReactInstrumentation.debugTool.onUpdateComponent(internalInstance._debugID);
|
|
170
|
+
}
|
|
125
171
|
}
|
|
126
172
|
}
|
|
127
173
|
|
|
@@ -10,10 +10,14 @@
|
|
|
10
10
|
*/
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
+
var _prodInvariant = require('./reactProdInvariant');
|
|
14
|
+
|
|
13
15
|
var ReactDOMContainerInfo = require('./ReactDOMContainerInfo');
|
|
14
16
|
var ReactDefaultBatchingStrategy = require('./ReactDefaultBatchingStrategy');
|
|
15
17
|
var ReactElement = require('./ReactElement');
|
|
18
|
+
var ReactInstrumentation = require('./ReactInstrumentation');
|
|
16
19
|
var ReactMarkupChecksum = require('./ReactMarkupChecksum');
|
|
20
|
+
var ReactReconciler = require('./ReactReconciler');
|
|
17
21
|
var ReactServerBatchingStrategy = require('./ReactServerBatchingStrategy');
|
|
18
22
|
var ReactServerRenderingTransaction = require('./ReactServerRenderingTransaction');
|
|
19
23
|
var ReactUpdates = require('./ReactUpdates');
|
|
@@ -34,8 +38,15 @@ function renderToStringImpl(element, makeStaticMarkup) {
|
|
|
34
38
|
transaction = ReactServerRenderingTransaction.getPooled(makeStaticMarkup);
|
|
35
39
|
|
|
36
40
|
return transaction.perform(function () {
|
|
41
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
42
|
+
ReactInstrumentation.debugTool.onBeginFlush();
|
|
43
|
+
}
|
|
37
44
|
var componentInstance = instantiateReactComponent(element);
|
|
38
|
-
var markup =
|
|
45
|
+
var markup = ReactReconciler.mountComponent(componentInstance, transaction, null, ReactDOMContainerInfo(), emptyObject);
|
|
46
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
47
|
+
ReactInstrumentation.debugTool.onUnmountComponent(componentInstance._debugID);
|
|
48
|
+
ReactInstrumentation.debugTool.onEndFlush();
|
|
49
|
+
}
|
|
39
50
|
if (!makeStaticMarkup) {
|
|
40
51
|
markup = ReactMarkupChecksum.addChecksumToMarkup(markup);
|
|
41
52
|
}
|
|
@@ -49,13 +60,23 @@ function renderToStringImpl(element, makeStaticMarkup) {
|
|
|
49
60
|
}
|
|
50
61
|
}
|
|
51
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Render a ReactElement to its initial HTML. This should only be used on the
|
|
65
|
+
* server.
|
|
66
|
+
* See https://facebook.github.io/react/docs/top-level-api.html#reactdomserver.rendertostring
|
|
67
|
+
*/
|
|
52
68
|
function renderToString(element) {
|
|
53
|
-
!ReactElement.isValidElement(element) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'renderToString(): You must pass a valid ReactElement.') :
|
|
69
|
+
!ReactElement.isValidElement(element) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'renderToString(): You must pass a valid ReactElement.') : _prodInvariant('46') : void 0;
|
|
54
70
|
return renderToStringImpl(element, false);
|
|
55
71
|
}
|
|
56
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Similar to renderToString, except this doesn't create extra DOM attributes
|
|
75
|
+
* such as data-react-id that React uses internally.
|
|
76
|
+
* See https://facebook.github.io/react/docs/top-level-api.html#reactdomserver.rendertostaticmarkup
|
|
77
|
+
*/
|
|
57
78
|
function renderToStaticMarkup(element) {
|
|
58
|
-
!ReactElement.isValidElement(element) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'renderToStaticMarkup(): You must pass a valid ReactElement.') :
|
|
79
|
+
!ReactElement.isValidElement(element) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'renderToStaticMarkup(): You must pass a valid ReactElement.') : _prodInvariant('47') : void 0;
|
|
59
80
|
return renderToStringImpl(element, true);
|
|
60
81
|
}
|
|
61
82
|
|
|
@@ -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,
|
|
24
|
-
return ReactReconciler.mountComponent(this._renderedComponent, transaction,
|
|
23
|
+
mountComponent: function (transaction, hostParent, hostContainerInfo, context) {
|
|
24
|
+
return ReactReconciler.mountComponent(this._renderedComponent, transaction, hostParent, hostContainerInfo, context);
|
|
25
25
|
},
|
|
26
26
|
receiveComponent: function () {},
|
|
27
|
-
|
|
28
|
-
return ReactReconciler.
|
|
27
|
+
getHostNode: function () {
|
|
28
|
+
return ReactReconciler.getHostNode(this._renderedComponent);
|
|
29
29
|
},
|
|
30
30
|
unmountComponent: function () {
|
|
31
31
|
ReactReconciler.unmountComponent(this._renderedComponent);
|
|
@@ -0,0 +1,126 @@
|
|
|
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);
|
|
100
|
+
|
|
101
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
102
|
+
// Mute future events from the top level wrapper.
|
|
103
|
+
// It is an implementation detail that devtools should not know about.
|
|
104
|
+
instance._debugID = 0;
|
|
105
|
+
|
|
106
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
107
|
+
ReactInstrumentation.debugTool.onBeginFlush();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// The initial render is synchronous but any updates that happen during
|
|
112
|
+
// rendering, in componentWillMount or componentDidMount, will be batched
|
|
113
|
+
// according to the current batching strategy.
|
|
114
|
+
|
|
115
|
+
ReactUpdates.batchedUpdates(batchedMountComponentIntoNode, instance);
|
|
116
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
117
|
+
// The instance here is TopLevelWrapper so we report mount for its child.
|
|
118
|
+
ReactInstrumentation.debugTool.onMountRootComponent(instance._renderedComponent._debugID);
|
|
119
|
+
ReactInstrumentation.debugTool.onEndFlush();
|
|
120
|
+
}
|
|
121
|
+
return new ReactTestInstance(instance);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
module.exports = ReactHostMount;
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Provides a `CallbackQueue` queue for collecting `onDOMReady` callbacks during
|
|
22
|
+
* the performing of the transaction.
|
|
23
|
+
*/
|
|
24
|
+
var ON_DOM_READY_QUEUEING = {
|
|
25
|
+
/**
|
|
26
|
+
* Initializes the internal `onDOMReady` queue.
|
|
27
|
+
*/
|
|
28
|
+
initialize: function () {
|
|
29
|
+
this.reactMountReady.reset();
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* After DOM is flushed, invoke all registered `onDOMReady` callbacks.
|
|
34
|
+
*/
|
|
35
|
+
close: function () {
|
|
36
|
+
this.reactMountReady.notifyAll();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Executed within the scope of the `Transaction` instance. Consider these as
|
|
42
|
+
* being member methods, but with an implied ordering while being isolated from
|
|
43
|
+
* each other.
|
|
44
|
+
*/
|
|
45
|
+
var TRANSACTION_WRAPPERS = [ON_DOM_READY_QUEUEING];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Currently:
|
|
49
|
+
* - The order that these are listed in the transaction is critical:
|
|
50
|
+
* - Suppresses events.
|
|
51
|
+
* - Restores selection range.
|
|
52
|
+
*
|
|
53
|
+
* Future:
|
|
54
|
+
* - Restore document/overflow scroll positions that were unintentionally
|
|
55
|
+
* modified via DOM insertions above the top viewport boundary.
|
|
56
|
+
* - Implement/integrate with customized constraint based layout system and keep
|
|
57
|
+
* track of which dimensions must be remeasured.
|
|
58
|
+
*
|
|
59
|
+
* @class ReactTestReconcileTransaction
|
|
60
|
+
*/
|
|
61
|
+
function ReactTestReconcileTransaction() {
|
|
62
|
+
this.reinitializeTransaction();
|
|
63
|
+
this.reactMountReady = CallbackQueue.getPooled(null);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
var Mixin = {
|
|
67
|
+
/**
|
|
68
|
+
* @see Transaction
|
|
69
|
+
* @abstract
|
|
70
|
+
* @final
|
|
71
|
+
* @return {array<object>} List of operation wrap procedures.
|
|
72
|
+
* TODO: convert to array<TransactionWrapper>
|
|
73
|
+
*/
|
|
74
|
+
getTransactionWrappers: function () {
|
|
75
|
+
return TRANSACTION_WRAPPERS;
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @return {object} The queue to collect `onDOMReady` callbacks with.
|
|
80
|
+
* TODO: convert to ReactMountReady
|
|
81
|
+
*/
|
|
82
|
+
getReactMountReady: function () {
|
|
83
|
+
return this.reactMountReady;
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* `PooledClass` looks for this, and will invoke this before allowing this
|
|
88
|
+
* instance to be reused.
|
|
89
|
+
*/
|
|
90
|
+
destructor: function () {
|
|
91
|
+
CallbackQueue.release(this.reactMountReady);
|
|
92
|
+
this.reactMountReady = null;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
_assign(ReactTestReconcileTransaction.prototype, Transaction.Mixin, ReactTestReconcileTransaction, Mixin);
|
|
97
|
+
|
|
98
|
+
PooledClass.addPoolingTo(ReactTestReconcileTransaction);
|
|
99
|
+
|
|
100
|
+
module.exports = ReactTestReconcileTransaction;
|