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.
- package/dist/JSXTransformer.js +2345 -910
- package/dist/react-with-addons.js +5273 -4111
- package/dist/react-with-addons.min.js +5 -6
- package/dist/react.js +4840 -3940
- package/dist/react.min.js +5 -6
- package/lib/AutoFocusMixin.js +1 -1
- package/lib/BeforeInputEventPlugin.js +389 -112
- package/lib/CSSProperty.js +6 -3
- package/lib/CSSPropertyOperations.js +21 -1
- package/lib/CallbackQueue.js +2 -2
- package/lib/ChangeEventPlugin.js +3 -3
- package/lib/ClientReactRootIndex.js +1 -1
- package/lib/DOMChildrenOperations.js +6 -4
- package/lib/DOMProperty.js +1 -1
- package/lib/DOMPropertyOperations.js +1 -1
- package/lib/Danger.js +7 -6
- package/lib/DefaultEventPluginOrder.js +1 -2
- package/lib/EnterLeaveEventPlugin.js +1 -1
- package/lib/EventConstants.js +1 -1
- package/lib/EventPluginHub.js +9 -7
- package/lib/EventPluginRegistry.js +1 -1
- package/lib/EventPluginUtils.js +1 -1
- package/lib/EventPropagators.js +1 -1
- package/lib/ExecutionEnvironment.js +2 -3
- package/lib/FallbackCompositionState.js +89 -0
- package/lib/HTMLDOMPropertyConfig.js +19 -7
- package/lib/LinkedStateMixin.js +1 -1
- package/lib/LinkedValueUtils.js +3 -3
- package/lib/LocalEventTrapMixin.js +1 -1
- package/lib/MobileSafariClickEventPlugin.js +1 -1
- package/lib/Object.assign.js +3 -1
- package/lib/PooledClass.js +1 -1
- package/lib/React.js +17 -50
- package/lib/ReactBrowserComponentMixin.js +3 -13
- package/lib/ReactBrowserEventEmitter.js +4 -6
- package/lib/ReactCSSTransitionGroup.js +4 -1
- package/lib/ReactCSSTransitionGroupChild.js +12 -2
- package/lib/ReactChildReconciler.js +121 -0
- package/lib/ReactChildren.js +10 -8
- package/lib/ReactClass.js +874 -0
- package/lib/ReactComponent.js +45 -286
- package/lib/ReactComponentBase.js +126 -0
- package/lib/ReactComponentBrowserEnvironment.js +10 -83
- package/lib/ReactComponentEnvironment.js +57 -0
- package/lib/ReactComponentWithPureRenderMixin.js +1 -1
- package/lib/ReactCompositeComponent.js +700 -1045
- package/lib/ReactContext.js +6 -2
- package/lib/ReactCurrentOwner.js +1 -1
- package/lib/ReactDOM.js +3 -8
- package/lib/ReactDOMButton.js +5 -6
- package/lib/ReactDOMComponent.js +120 -77
- package/lib/ReactDOMForm.js +5 -6
- package/lib/ReactDOMIDOperations.js +56 -74
- package/lib/ReactDOMImg.js +4 -6
- package/lib/ReactDOMInput.js +5 -6
- package/lib/ReactDOMOption.js +5 -6
- package/lib/ReactDOMSelect.js +57 -65
- package/lib/ReactDOMSelection.js +6 -2
- package/lib/ReactDOMTextComponent.js +124 -0
- package/lib/ReactDOMTextarea.js +5 -6
- package/lib/ReactDefaultBatchingStrategy.js +1 -1
- package/lib/ReactDefaultInjection.js +14 -8
- package/lib/ReactDefaultPerf.js +8 -7
- package/lib/ReactDefaultPerfAnalysis.js +1 -1
- package/lib/ReactElement.js +22 -15
- package/lib/ReactElementValidator.js +192 -53
- package/lib/ReactEmptyComponent.js +29 -11
- package/lib/ReactEventEmitterMixin.js +1 -1
- package/lib/ReactEventListener.js +3 -3
- package/lib/ReactInjection.js +7 -5
- package/lib/ReactInputSelection.js +3 -4
- package/lib/ReactInstanceHandles.js +3 -2
- package/lib/ReactInstanceMap.js +47 -0
- package/lib/ReactLink.js +1 -1
- package/lib/ReactMarkupChecksum.js +1 -1
- package/lib/ReactMount.js +202 -66
- package/lib/ReactMultiChild.js +44 -45
- package/lib/ReactMultiChildUpdateTypes.js +1 -1
- package/lib/ReactNativeComponent.js +47 -10
- package/lib/ReactOwner.js +4 -48
- package/lib/ReactPerf.js +21 -1
- package/lib/ReactPropTransferer.js +2 -57
- package/lib/ReactPropTypeLocationNames.js +1 -1
- package/lib/ReactPropTypeLocations.js +1 -1
- package/lib/ReactPropTypes.js +14 -22
- package/lib/ReactPutListenerQueue.js +1 -1
- package/lib/ReactReconcileTransaction.js +1 -1
- package/lib/ReactRef.js +96 -0
- package/lib/ReactRootIndex.js +1 -1
- package/lib/ReactServerRendering.js +5 -3
- package/lib/ReactServerRenderingTransaction.js +1 -1
- package/lib/ReactStateSetters.js +1 -1
- package/lib/ReactTestUtils.js +83 -26
- package/lib/ReactTransitionChildMapping.js +1 -1
- package/lib/ReactTransitionEvents.js +1 -1
- package/lib/ReactTransitionGroup.js +48 -7
- package/lib/ReactUpdates.js +46 -45
- package/lib/ReactWithAddons.js +1 -1
- package/lib/SVGDOMPropertyConfig.js +1 -1
- package/lib/SelectEventPlugin.js +3 -3
- package/lib/ServerReactRootIndex.js +1 -1
- package/lib/SimpleEventPlugin.js +1 -1
- package/lib/SyntheticClipboardEvent.js +1 -2
- package/lib/SyntheticCompositionEvent.js +1 -2
- package/lib/SyntheticDragEvent.js +1 -1
- package/lib/SyntheticEvent.js +11 -3
- package/lib/SyntheticFocusEvent.js +1 -1
- package/lib/SyntheticInputEvent.js +1 -2
- package/lib/SyntheticKeyboardEvent.js +1 -1
- package/lib/SyntheticMouseEvent.js +2 -4
- package/lib/SyntheticTouchEvent.js +1 -1
- package/lib/SyntheticUIEvent.js +1 -1
- package/lib/SyntheticWheelEvent.js +1 -1
- package/lib/Transaction.js +3 -3
- package/lib/ViewportMetrics.js +2 -5
- package/lib/accumulate.js +47 -0
- package/lib/accumulateInto.js +1 -1
- package/lib/adler32.js +1 -1
- package/lib/cloneWithProps.js +3 -3
- package/lib/copyProperties.js +2 -0
- package/lib/createFullPageComponent.js +3 -3
- package/lib/dangerousStyleValue.js +1 -1
- package/lib/escapeTextForBrowser.js +6 -6
- package/lib/findDOMNode.js +51 -0
- package/lib/flattenChildren.js +11 -22
- package/lib/forEachAccumulated.js +1 -1
- package/lib/getEventCharCode.js +1 -1
- package/lib/getEventKey.js +1 -1
- package/lib/getEventModifierState.js +1 -1
- package/lib/getEventTarget.js +1 -1
- package/lib/getIteratorFn.js +42 -0
- package/lib/getNodeForCharacterOffset.js +2 -2
- package/lib/getReactRootElementInContainer.js +1 -1
- package/lib/getTextContentAccessor.js +1 -1
- package/lib/instantiateReactComponent.js +89 -66
- package/lib/isEventSupported.js +1 -1
- package/lib/isNode.js +3 -4
- package/lib/isTextInputElement.js +2 -3
- package/lib/joinClasses.js +1 -1
- package/lib/keyMirror.js +1 -1
- package/lib/memoizeStringOnly.js +4 -5
- package/lib/onlyChild.js +1 -1
- package/lib/setInnerHTML.js +12 -1
- package/lib/shallowEqual.js +1 -1
- package/lib/shouldUpdateReactComponent.js +48 -6
- package/lib/traverseAllChildren.js +111 -55
- package/lib/update.js +1 -1
- package/lib/warning.js +9 -2
- package/package.json +1 -1
- package/lib/CompositionEventPlugin.js +0 -257
- package/lib/ReactLegacyElement.js +0 -243
- package/lib/ReactTextComponent.js +0 -104
- package/lib/deprecated.js +0 -47
package/lib/ReactPropTypes.js
CHANGED
|
@@ -9,12 +9,11 @@
|
|
|
9
9
|
* @providesModule ReactPropTypes
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var ReactElement = require("./ReactElement");
|
|
15
15
|
var ReactPropTypeLocationNames = require("./ReactPropTypeLocationNames");
|
|
16
16
|
|
|
17
|
-
var deprecated = require("./deprecated");
|
|
18
17
|
var emptyFunction = require("./emptyFunction");
|
|
19
18
|
|
|
20
19
|
/**
|
|
@@ -85,22 +84,7 @@ var ReactPropTypes = {
|
|
|
85
84
|
objectOf: createObjectOfTypeChecker,
|
|
86
85
|
oneOf: createEnumTypeChecker,
|
|
87
86
|
oneOfType: createUnionTypeChecker,
|
|
88
|
-
shape: createShapeTypeChecker
|
|
89
|
-
|
|
90
|
-
component: deprecated(
|
|
91
|
-
'React.PropTypes',
|
|
92
|
-
'component',
|
|
93
|
-
'element',
|
|
94
|
-
this,
|
|
95
|
-
elementTypeChecker
|
|
96
|
-
),
|
|
97
|
-
renderable: deprecated(
|
|
98
|
-
'React.PropTypes',
|
|
99
|
-
'renderable',
|
|
100
|
-
'node',
|
|
101
|
-
this,
|
|
102
|
-
nodeTypeChecker
|
|
103
|
-
)
|
|
87
|
+
shape: createShapeTypeChecker
|
|
104
88
|
};
|
|
105
89
|
|
|
106
90
|
function createChainableTypeChecker(validate) {
|
|
@@ -114,6 +98,7 @@ function createChainableTypeChecker(validate) {
|
|
|
114
98
|
("`" + componentName + "`.")
|
|
115
99
|
);
|
|
116
100
|
}
|
|
101
|
+
return null;
|
|
117
102
|
} else {
|
|
118
103
|
return validate(props, propName, componentName, location);
|
|
119
104
|
}
|
|
@@ -141,12 +126,13 @@ function createPrimitiveTypeChecker(expectedType) {
|
|
|
141
126
|
("supplied to `" + componentName + "`, expected `" + expectedType + "`.")
|
|
142
127
|
);
|
|
143
128
|
}
|
|
129
|
+
return null;
|
|
144
130
|
}
|
|
145
131
|
return createChainableTypeChecker(validate);
|
|
146
132
|
}
|
|
147
133
|
|
|
148
134
|
function createAnyTypeChecker() {
|
|
149
|
-
return createChainableTypeChecker(emptyFunction.thatReturns());
|
|
135
|
+
return createChainableTypeChecker(emptyFunction.thatReturns(null));
|
|
150
136
|
}
|
|
151
137
|
|
|
152
138
|
function createArrayOfTypeChecker(typeChecker) {
|
|
@@ -166,6 +152,7 @@ function createArrayOfTypeChecker(typeChecker) {
|
|
|
166
152
|
return error;
|
|
167
153
|
}
|
|
168
154
|
}
|
|
155
|
+
return null;
|
|
169
156
|
}
|
|
170
157
|
return createChainableTypeChecker(validate);
|
|
171
158
|
}
|
|
@@ -179,6 +166,7 @@ function createElementTypeChecker() {
|
|
|
179
166
|
("`" + componentName + "`, expected a ReactElement.")
|
|
180
167
|
);
|
|
181
168
|
}
|
|
169
|
+
return null;
|
|
182
170
|
}
|
|
183
171
|
return createChainableTypeChecker(validate);
|
|
184
172
|
}
|
|
@@ -193,6 +181,7 @@ function createInstanceTypeChecker(expectedClass) {
|
|
|
193
181
|
("`" + componentName + "`, expected instance of `" + expectedClassName + "`.")
|
|
194
182
|
);
|
|
195
183
|
}
|
|
184
|
+
return null;
|
|
196
185
|
}
|
|
197
186
|
return createChainableTypeChecker(validate);
|
|
198
187
|
}
|
|
@@ -202,7 +191,7 @@ function createEnumTypeChecker(expectedValues) {
|
|
|
202
191
|
var propValue = props[propName];
|
|
203
192
|
for (var i = 0; i < expectedValues.length; i++) {
|
|
204
193
|
if (propValue === expectedValues[i]) {
|
|
205
|
-
return;
|
|
194
|
+
return null;
|
|
206
195
|
}
|
|
207
196
|
}
|
|
208
197
|
|
|
@@ -235,6 +224,7 @@ function createObjectOfTypeChecker(typeChecker) {
|
|
|
235
224
|
}
|
|
236
225
|
}
|
|
237
226
|
}
|
|
227
|
+
return null;
|
|
238
228
|
}
|
|
239
229
|
return createChainableTypeChecker(validate);
|
|
240
230
|
}
|
|
@@ -244,7 +234,7 @@ function createUnionTypeChecker(arrayOfTypeCheckers) {
|
|
|
244
234
|
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
|
245
235
|
var checker = arrayOfTypeCheckers[i];
|
|
246
236
|
if (checker(props, propName, componentName, location) == null) {
|
|
247
|
-
return;
|
|
237
|
+
return null;
|
|
248
238
|
}
|
|
249
239
|
}
|
|
250
240
|
|
|
@@ -266,6 +256,7 @@ function createNodeChecker() {
|
|
|
266
256
|
("`" + componentName + "`, expected a ReactNode.")
|
|
267
257
|
);
|
|
268
258
|
}
|
|
259
|
+
return null;
|
|
269
260
|
}
|
|
270
261
|
return createChainableTypeChecker(validate);
|
|
271
262
|
}
|
|
@@ -291,12 +282,13 @@ function createShapeTypeChecker(shapeTypes) {
|
|
|
291
282
|
return error;
|
|
292
283
|
}
|
|
293
284
|
}
|
|
285
|
+
return null;
|
|
294
286
|
}
|
|
295
287
|
return createChainableTypeChecker(validate, 'expected `object`');
|
|
296
288
|
}
|
|
297
289
|
|
|
298
290
|
function isNode(propValue) {
|
|
299
|
-
switch(typeof propValue) {
|
|
291
|
+
switch (typeof propValue) {
|
|
300
292
|
case 'number':
|
|
301
293
|
case 'string':
|
|
302
294
|
return true;
|
package/lib/ReactRef.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
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 ReactRef
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var ReactUpdates = require("./ReactUpdates");
|
|
15
|
+
|
|
16
|
+
var accumulate = require("./accumulate");
|
|
17
|
+
var assign = require("./Object.assign");
|
|
18
|
+
var forEachAccumulated = require("./forEachAccumulated");
|
|
19
|
+
var invariant = require("./invariant");
|
|
20
|
+
|
|
21
|
+
function ReactRef() {
|
|
22
|
+
this._value = null;
|
|
23
|
+
this._successCallbacks = null;
|
|
24
|
+
this._failureCallbacks = null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Call the enqueued success or failure callbacks for a ref, as appropriate.
|
|
29
|
+
*/
|
|
30
|
+
function dispatchCallbacks() {
|
|
31
|
+
/*jshint validthis:true */
|
|
32
|
+
var successCallbacks = this._successCallbacks;
|
|
33
|
+
var failureCallbacks = this._failureCallbacks;
|
|
34
|
+
this._successCallbacks = null;
|
|
35
|
+
this._failureCallbacks = null;
|
|
36
|
+
|
|
37
|
+
if (this._value) {
|
|
38
|
+
forEachAccumulated(successCallbacks, callSuccess, this);
|
|
39
|
+
} else {
|
|
40
|
+
forEachAccumulated(failureCallbacks, callFailure);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Call a single success callback, passing the ref's value.
|
|
46
|
+
*/
|
|
47
|
+
function callSuccess(cb) {
|
|
48
|
+
/*jshint validthis:true */
|
|
49
|
+
cb(this._value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Call a single failure callback, passing no arguments.
|
|
54
|
+
*/
|
|
55
|
+
function callFailure(cb) {
|
|
56
|
+
cb();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
assign(ReactRef.prototype, {
|
|
60
|
+
/**
|
|
61
|
+
* Get the value of a ref asynchronously. Accepts a success callback and an
|
|
62
|
+
* optional failure callback. If the ref has been rendered, the success
|
|
63
|
+
* callback will be called with the component instance; otherwise, the failure
|
|
64
|
+
* callback will be executed.
|
|
65
|
+
*
|
|
66
|
+
* @param {function} success Callback in case of success
|
|
67
|
+
* @param {?function} failure Callback in case of failure
|
|
68
|
+
*/
|
|
69
|
+
then: function(success, failure) {
|
|
70
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
71
|
+
typeof success === 'function',
|
|
72
|
+
'ReactRef.then(...): Must provide a success callback.'
|
|
73
|
+
) : invariant(typeof success === 'function'));
|
|
74
|
+
if (this._successCallbacks == null) {
|
|
75
|
+
ReactUpdates.asap(dispatchCallbacks, this);
|
|
76
|
+
}
|
|
77
|
+
this._successCallbacks = accumulate(this._successCallbacks, success);
|
|
78
|
+
if (failure) {
|
|
79
|
+
this._failureCallbacks = accumulate(this._failureCallbacks, failure);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
ReactRef.attachRef = function(ref, value) {
|
|
85
|
+
ref._value = value.getPublicInstance();
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
ReactRef.detachRef = function(ref, value) {
|
|
89
|
+
// Check that `component` is still the current ref because we do not want to
|
|
90
|
+
// detach the ref if another component stole it.
|
|
91
|
+
if (ref._value === value) {
|
|
92
|
+
ref._value = null;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
module.exports = ReactRef;
|
package/lib/ReactRootIndex.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @typechecks static-only
|
|
10
10
|
* @providesModule ReactServerRendering
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var ReactElement = require("./ReactElement");
|
|
15
15
|
var ReactInstanceHandles = require("./ReactInstanceHandles");
|
|
@@ -17,6 +17,7 @@ var ReactMarkupChecksum = require("./ReactMarkupChecksum");
|
|
|
17
17
|
var ReactServerRenderingTransaction =
|
|
18
18
|
require("./ReactServerRenderingTransaction");
|
|
19
19
|
|
|
20
|
+
var emptyObject = require("./emptyObject");
|
|
20
21
|
var instantiateReactComponent = require("./instantiateReactComponent");
|
|
21
22
|
var invariant = require("./invariant");
|
|
22
23
|
|
|
@@ -37,7 +38,8 @@ function renderToString(element) {
|
|
|
37
38
|
|
|
38
39
|
return transaction.perform(function() {
|
|
39
40
|
var componentInstance = instantiateReactComponent(element, null);
|
|
40
|
-
var markup =
|
|
41
|
+
var markup =
|
|
42
|
+
componentInstance.mountComponent(id, transaction, emptyObject);
|
|
41
43
|
return ReactMarkupChecksum.addChecksumToMarkup(markup);
|
|
42
44
|
}, null);
|
|
43
45
|
} finally {
|
|
@@ -63,7 +65,7 @@ function renderToStaticMarkup(element) {
|
|
|
63
65
|
|
|
64
66
|
return transaction.perform(function() {
|
|
65
67
|
var componentInstance = instantiateReactComponent(element, null);
|
|
66
|
-
return componentInstance.mountComponent(id, transaction,
|
|
68
|
+
return componentInstance.mountComponent(id, transaction, emptyObject);
|
|
67
69
|
}, null);
|
|
68
70
|
} finally {
|
|
69
71
|
ReactServerRenderingTransaction.release(transaction);
|
package/lib/ReactStateSetters.js
CHANGED
package/lib/ReactTestUtils.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @providesModule ReactTestUtils
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
14
|
var EventConstants = require("./EventConstants");
|
|
15
15
|
var EventPluginHub = require("./EventPluginHub");
|
|
@@ -17,8 +17,10 @@ var EventPropagators = require("./EventPropagators");
|
|
|
17
17
|
var React = require("./React");
|
|
18
18
|
var ReactElement = require("./ReactElement");
|
|
19
19
|
var ReactBrowserEventEmitter = require("./ReactBrowserEventEmitter");
|
|
20
|
+
var ReactCompositeComponent = require("./ReactCompositeComponent");
|
|
21
|
+
var ReactInstanceHandles = require("./ReactInstanceHandles");
|
|
22
|
+
var ReactInstanceMap = require("./ReactInstanceMap");
|
|
20
23
|
var ReactMount = require("./ReactMount");
|
|
21
|
-
var ReactTextComponent = require("./ReactTextComponent");
|
|
22
24
|
var ReactUpdates = require("./ReactUpdates");
|
|
23
25
|
var SyntheticEvent = require("./SyntheticEvent");
|
|
24
26
|
|
|
@@ -55,12 +57,14 @@ var ReactTestUtils = {
|
|
|
55
57
|
isElementOfType: function(inst, convenienceConstructor) {
|
|
56
58
|
return (
|
|
57
59
|
ReactElement.isValidElement(inst) &&
|
|
58
|
-
inst.type === convenienceConstructor
|
|
60
|
+
inst.type === convenienceConstructor
|
|
59
61
|
);
|
|
60
62
|
},
|
|
61
63
|
|
|
62
64
|
isDOMComponent: function(inst) {
|
|
63
|
-
|
|
65
|
+
// TODO: Fix this heuristic. It's just here because composites can currently
|
|
66
|
+
// pretend to be DOM components.
|
|
67
|
+
return !!(inst && inst.getDOMNode && inst.tagName);
|
|
64
68
|
},
|
|
65
69
|
|
|
66
70
|
isDOMComponentElement: function(inst) {
|
|
@@ -76,7 +80,7 @@ var ReactTestUtils = {
|
|
|
76
80
|
|
|
77
81
|
isCompositeComponentWithType: function(inst, type) {
|
|
78
82
|
return !!(ReactTestUtils.isCompositeComponent(inst) &&
|
|
79
|
-
(inst.constructor === type
|
|
83
|
+
(inst.constructor === type));
|
|
80
84
|
},
|
|
81
85
|
|
|
82
86
|
isCompositeComponentElement: function(inst) {
|
|
@@ -97,8 +101,12 @@ var ReactTestUtils = {
|
|
|
97
101
|
(inst.constructor === type));
|
|
98
102
|
},
|
|
99
103
|
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
getRenderedChildOfCompositeComponent: function(inst) {
|
|
105
|
+
if (!ReactTestUtils.isCompositeComponent(inst)) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
var internalInstance = ReactInstanceMap.get(inst);
|
|
109
|
+
return internalInstance._renderedComponent.getPublicInstance();
|
|
102
110
|
},
|
|
103
111
|
|
|
104
112
|
findAllInRenderedTree: function(inst, test) {
|
|
@@ -107,19 +115,31 @@ var ReactTestUtils = {
|
|
|
107
115
|
}
|
|
108
116
|
var ret = test(inst) ? [inst] : [];
|
|
109
117
|
if (ReactTestUtils.isDOMComponent(inst)) {
|
|
110
|
-
var
|
|
118
|
+
var internalInstance = ReactInstanceMap.get(inst);
|
|
119
|
+
var renderedChildren = internalInstance
|
|
120
|
+
._renderedComponent
|
|
121
|
+
._renderedChildren;
|
|
111
122
|
var key;
|
|
112
123
|
for (key in renderedChildren) {
|
|
113
124
|
if (!renderedChildren.hasOwnProperty(key)) {
|
|
114
125
|
continue;
|
|
115
126
|
}
|
|
127
|
+
if (!renderedChildren[key].getPublicInstance) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
116
130
|
ret = ret.concat(
|
|
117
|
-
ReactTestUtils.findAllInRenderedTree(
|
|
131
|
+
ReactTestUtils.findAllInRenderedTree(
|
|
132
|
+
renderedChildren[key].getPublicInstance(),
|
|
133
|
+
test
|
|
134
|
+
)
|
|
118
135
|
);
|
|
119
136
|
}
|
|
120
137
|
} else if (ReactTestUtils.isCompositeComponent(inst)) {
|
|
121
138
|
ret = ret.concat(
|
|
122
|
-
ReactTestUtils.findAllInRenderedTree(
|
|
139
|
+
ReactTestUtils.findAllInRenderedTree(
|
|
140
|
+
ReactTestUtils.getRenderedChildOfCompositeComponent(inst),
|
|
141
|
+
test
|
|
142
|
+
)
|
|
123
143
|
);
|
|
124
144
|
}
|
|
125
145
|
return ret;
|
|
@@ -134,8 +154,7 @@ var ReactTestUtils = {
|
|
|
134
154
|
return ReactTestUtils.findAllInRenderedTree(root, function(inst) {
|
|
135
155
|
var instClassName = inst.props.className;
|
|
136
156
|
return ReactTestUtils.isDOMComponent(inst) && (
|
|
137
|
-
instClassName &&
|
|
138
|
-
(' ' + instClassName + ' ').indexOf(' ' + className + ' ') !== -1
|
|
157
|
+
(instClassName && (' ' + instClassName + ' ').indexOf(' ' + className + ' ') !== -1)
|
|
139
158
|
);
|
|
140
159
|
});
|
|
141
160
|
},
|
|
@@ -150,7 +169,9 @@ var ReactTestUtils = {
|
|
|
150
169
|
var all =
|
|
151
170
|
ReactTestUtils.scryRenderedDOMComponentsWithClass(root, className);
|
|
152
171
|
if (all.length !== 1) {
|
|
153
|
-
throw new Error('Did not find exactly one match
|
|
172
|
+
throw new Error('Did not find exactly one match '+
|
|
173
|
+
'(found: ' + all.length + ') for class:' + className
|
|
174
|
+
);
|
|
154
175
|
}
|
|
155
176
|
return all[0];
|
|
156
177
|
},
|
|
@@ -231,21 +252,14 @@ var ReactTestUtils = {
|
|
|
231
252
|
mockComponent: function(module, mockTagName) {
|
|
232
253
|
mockTagName = mockTagName || module.mockTagName || "div";
|
|
233
254
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
);
|
|
241
|
-
}
|
|
255
|
+
module.prototype.render.mockImplementation(function() {
|
|
256
|
+
return React.createElement(
|
|
257
|
+
mockTagName,
|
|
258
|
+
null,
|
|
259
|
+
this.props.children
|
|
260
|
+
);
|
|
242
261
|
});
|
|
243
262
|
|
|
244
|
-
module.mockImplementation(ConvenienceConstructor);
|
|
245
|
-
|
|
246
|
-
module.type = ConvenienceConstructor.type;
|
|
247
|
-
module.isReactLegacyFactory = true;
|
|
248
|
-
|
|
249
263
|
return this;
|
|
250
264
|
},
|
|
251
265
|
|
|
@@ -290,10 +304,53 @@ var ReactTestUtils = {
|
|
|
290
304
|
};
|
|
291
305
|
},
|
|
292
306
|
|
|
307
|
+
createRenderer: function() {
|
|
308
|
+
return new ReactShallowRenderer();
|
|
309
|
+
},
|
|
310
|
+
|
|
293
311
|
Simulate: null,
|
|
294
312
|
SimulateNative: {}
|
|
295
313
|
};
|
|
296
314
|
|
|
315
|
+
/**
|
|
316
|
+
* @class ReactShallowRenderer
|
|
317
|
+
*/
|
|
318
|
+
var ReactShallowRenderer = function() {
|
|
319
|
+
this._instance = null;
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
ReactShallowRenderer.prototype.getRenderOutput = function() {
|
|
323
|
+
return (this._instance && this._instance._renderedComponent) || null;
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
var ShallowComponentWrapper = function(inst) {
|
|
327
|
+
this._instance = inst;
|
|
328
|
+
};
|
|
329
|
+
assign(
|
|
330
|
+
ShallowComponentWrapper.prototype,
|
|
331
|
+
ReactCompositeComponent.ShallowMixin
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
ReactShallowRenderer.prototype.render = function(element, context) {
|
|
335
|
+
var transaction = ReactUpdates.ReactReconcileTransaction.getPooled();
|
|
336
|
+
this._render(element, transaction, context);
|
|
337
|
+
ReactUpdates.ReactReconcileTransaction.release(transaction);
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
ReactShallowRenderer.prototype._render = function(element, transaction, context) {
|
|
341
|
+
if (!this._instance) {
|
|
342
|
+
var rootID = ReactInstanceHandles.createReactRootID();
|
|
343
|
+
var instance = new ShallowComponentWrapper(new element.type(element.props));
|
|
344
|
+
instance.construct(element);
|
|
345
|
+
|
|
346
|
+
instance.mountComponent(rootID, transaction, context);
|
|
347
|
+
|
|
348
|
+
this._instance = instance;
|
|
349
|
+
} else {
|
|
350
|
+
this._instance.receiveComponent(element, transaction, context);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
|
|
297
354
|
/**
|
|
298
355
|
* Exports:
|
|
299
356
|
*
|