react 0.14.0-alpha3 → 0.14.0-beta1
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/README.md +5 -2
- package/addons.js +2 -2
- package/dist/JSXTransformer.js +69 -70
- package/dist/react-with-addons.js +2047 -2078
- package/dist/react-with-addons.min.js +6 -6
- package/dist/react.js +1861 -1904
- package/dist/react.min.js +5 -5
- package/lib/{AutoFocusMixin.js → AutoFocusUtils.js} +13 -3
- package/lib/ChangeEventPlugin.js +4 -2
- package/lib/DOMProperty.js +81 -116
- package/lib/DOMPropertyOperations.js +70 -25
- package/lib/EnterLeaveEventPlugin.js +3 -3
- package/lib/EventPluginHub.js +2 -2
- package/lib/EventPluginUtils.js +6 -6
- package/lib/HTMLDOMPropertyConfig.js +8 -1
- package/lib/LinkedValueUtils.js +45 -33
- package/lib/PooledClass.js +12 -0
- package/lib/React.js +1 -1
- package/lib/ReactCSSTransitionGroupChild.js +8 -0
- package/lib/ReactChildren.js +3 -3
- package/lib/ReactClass.js +29 -47
- package/lib/ReactComponent.js +11 -6
- package/lib/ReactComponentWithPureRenderMixin.js +2 -2
- package/lib/ReactCompositeComponent.js +45 -72
- package/lib/ReactDOM.js +1 -0
- package/lib/ReactDOMButton.js +15 -26
- package/lib/ReactDOMClient.js +9 -4
- package/lib/ReactDOMComponent.js +302 -24
- package/lib/ReactDOMIDOperations.js +14 -0
- package/lib/ReactDOMInput.js +78 -94
- package/lib/ReactDOMOption.js +19 -38
- package/lib/ReactDOMSelect.js +85 -95
- package/lib/ReactDOMTextarea.js +39 -52
- package/lib/ReactDefaultInjection.js +0 -47
- package/lib/ReactElement.js +18 -79
- package/lib/ReactElementValidator.js +29 -98
- package/lib/ReactErrorUtils.js +1 -1
- package/lib/ReactEventEmitterMixin.js +2 -3
- package/lib/ReactEventListener.js +43 -3
- package/lib/ReactFragment.js +12 -7
- package/lib/ReactInputSelection.js +4 -3
- package/lib/ReactInstanceHandles.js +3 -2
- package/lib/ReactMount.js +20 -40
- package/lib/ReactNativeComponent.js +0 -5
- package/lib/ReactNoopUpdateQueue.js +118 -0
- package/lib/ReactPropTypes.js +3 -3
- package/lib/ReactReconcileTransaction.js +2 -2
- package/lib/ReactReconciler.js +8 -10
- package/lib/ReactServerBatchingStrategy.js +23 -0
- package/lib/ReactServerRendering.js +13 -0
- package/lib/ReactServerRenderingTransaction.js +2 -2
- package/lib/ReactTestUtils.js +56 -33
- package/lib/ReactUpdateQueue.js +51 -26
- package/lib/ReactUpdates.js +0 -3
- package/lib/ReactWithAddons.js +0 -2
- package/lib/SelectEventPlugin.js +6 -7
- package/lib/SimpleEventPlugin.js +4 -4
- package/lib/SyntheticClipboardEvent.js +2 -2
- package/lib/SyntheticCompositionEvent.js +2 -2
- package/lib/SyntheticDragEvent.js +2 -2
- package/lib/SyntheticEvent.js +6 -5
- package/lib/SyntheticFocusEvent.js +2 -2
- package/lib/SyntheticInputEvent.js +2 -2
- package/lib/SyntheticKeyboardEvent.js +2 -2
- package/lib/SyntheticMouseEvent.js +2 -2
- package/lib/SyntheticTouchEvent.js +2 -2
- package/lib/SyntheticUIEvent.js +2 -2
- package/lib/SyntheticWheelEvent.js +2 -2
- package/lib/Transaction.js +10 -4
- package/lib/cloneWithProps.js +1 -1
- package/lib/deprecated.js +47 -0
- package/lib/findDOMNode.js +2 -3
- package/lib/forEachAccumulated.js +1 -1
- package/lib/getEventCharCode.js +1 -1
- package/lib/getEventModifierState.js +0 -1
- package/lib/getMarkupWrap.js +13 -35
- package/lib/instantiateReactComponent.js +13 -9
- package/lib/isTextInputElement.js +2 -1
- package/lib/joinClasses.js +1 -1
- package/lib/setInnerHTML.js +1 -1
- package/lib/traverseAllChildren.js +1 -1
- package/lib/warning.js +0 -4
- package/package.json +1 -1
- package/react.js +53 -1
- package/addons/CSSTransitionGroup.js +0 -1
- package/addons/LinkedStateMixin.js +0 -1
- package/addons/Perf.js +0 -1
- package/addons/PureRenderMixin.js +0 -1
- package/addons/TestUtils.js +0 -1
- package/addons/TransitionGroup.js +0 -1
- package/addons/batchedUpdates.js +0 -1
- package/addons/cloneWithProps.js +0 -1
- package/addons/createFragment.js +0 -1
- package/addons/renderSubtreeIntoContainer.js +0 -1
- package/addons/shallowCompare.js +0 -1
- package/addons/update.js +0 -1
- package/lib/LocalEventTrapMixin.js +0 -46
- package/lib/ReactContext.js +0 -32
- package/lib/ReactDOMForm.js +0 -47
- package/lib/ReactDOMIframe.js +0 -43
- package/lib/ReactDOMImg.js +0 -44
- package/lib/ReactLifeCycle.js +0 -35
- package/lib/createFullPageComponent.js +0 -51
package/lib/ReactPropTypes.js
CHANGED
|
@@ -137,7 +137,7 @@ function createArrayOfTypeChecker(typeChecker) {
|
|
|
137
137
|
return new Error('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
|
|
138
138
|
}
|
|
139
139
|
for (var i = 0; i < propValue.length; i++) {
|
|
140
|
-
var error = typeChecker(propValue, i, componentName, location,
|
|
140
|
+
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']');
|
|
141
141
|
if (error instanceof Error) {
|
|
142
142
|
return error;
|
|
143
143
|
}
|
|
@@ -202,7 +202,7 @@ function createObjectOfTypeChecker(typeChecker) {
|
|
|
202
202
|
}
|
|
203
203
|
for (var key in propValue) {
|
|
204
204
|
if (propValue.hasOwnProperty(key)) {
|
|
205
|
-
var error = typeChecker(propValue, key, componentName, location,
|
|
205
|
+
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key);
|
|
206
206
|
if (error instanceof Error) {
|
|
207
207
|
return error;
|
|
208
208
|
}
|
|
@@ -258,7 +258,7 @@ function createShapeTypeChecker(shapeTypes) {
|
|
|
258
258
|
if (!checker) {
|
|
259
259
|
continue;
|
|
260
260
|
}
|
|
261
|
-
var error = checker(propValue, key, componentName, location,
|
|
261
|
+
var error = checker(propValue, key, componentName, location, propFullName + '.' + key);
|
|
262
262
|
if (error) {
|
|
263
263
|
return error;
|
|
264
264
|
}
|
|
@@ -118,7 +118,7 @@ var Mixin = {
|
|
|
118
118
|
* @see Transaction
|
|
119
119
|
* @abstract
|
|
120
120
|
* @final
|
|
121
|
-
* @return {array<object>} List of operation wrap
|
|
121
|
+
* @return {array<object>} List of operation wrap procedures.
|
|
122
122
|
* TODO: convert to array<TransactionWrapper>
|
|
123
123
|
*/
|
|
124
124
|
getTransactionWrappers: function () {
|
|
@@ -134,7 +134,7 @@ var Mixin = {
|
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
136
|
* `PooledClass` looks for this, and will invoke this before allowing this
|
|
137
|
-
* instance to be
|
|
137
|
+
* instance to be reused.
|
|
138
138
|
*/
|
|
139
139
|
destructor: function () {
|
|
140
140
|
CallbackQueue.release(this.reactMountReady);
|
package/lib/ReactReconciler.js
CHANGED
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
14
|
var ReactRef = require("./ReactRef");
|
|
15
|
-
var ReactElementValidator = require("./ReactElementValidator");
|
|
16
15
|
|
|
17
16
|
/**
|
|
18
17
|
* Helper to call ReactRef.attachRefs with this composite component, split out
|
|
@@ -36,10 +35,9 @@ var ReactReconciler = {
|
|
|
36
35
|
*/
|
|
37
36
|
mountComponent: function (internalInstance, rootID, transaction, context) {
|
|
38
37
|
var markup = internalInstance.mountComponent(rootID, transaction, context);
|
|
39
|
-
if (
|
|
40
|
-
|
|
38
|
+
if (internalInstance._currentElement.ref != null) {
|
|
39
|
+
transaction.getReactMountReady().enqueue(attachRefs, internalInstance);
|
|
41
40
|
}
|
|
42
|
-
transaction.getReactMountReady().enqueue(attachRefs, internalInstance);
|
|
43
41
|
return markup;
|
|
44
42
|
},
|
|
45
43
|
|
|
@@ -65,8 +63,9 @@ var ReactReconciler = {
|
|
|
65
63
|
*/
|
|
66
64
|
receiveComponent: function (internalInstance, nextElement, transaction, context) {
|
|
67
65
|
var prevElement = internalInstance._currentElement;
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
if (nextElement === prevElement && nextElement._owner != null
|
|
67
|
+
// TODO: Shouldn't we need to do this: `&& context === internalInstance._context`
|
|
68
|
+
) {
|
|
70
69
|
// Since elements are immutable after the owner is rendered,
|
|
71
70
|
// we can do a cheap identity compare here to determine if this is a
|
|
72
71
|
// superfluous reconcile. It's possible for state to be mutable but such
|
|
@@ -74,11 +73,10 @@ var ReactReconciler = {
|
|
|
74
73
|
// the element. We explicitly check for the existence of an owner since
|
|
75
74
|
// it's possible for an element created outside a composite to be
|
|
76
75
|
// deeply mutated and reused.
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
76
|
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
// TODO: Bailing out early is just a perf optimization right?
|
|
78
|
+
// TODO: Removing the return statement should affect correctness?
|
|
79
|
+
return;
|
|
82
80
|
}
|
|
83
81
|
|
|
84
82
|
var refsChanged = ReactRef.shouldUpdateRefs(prevElement, nextElement);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2014-2015, 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 ReactServerBatchingStrategy
|
|
10
|
+
* @typechecks
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
var ReactServerBatchingStrategy = {
|
|
16
|
+
isBatchingUpdates: false,
|
|
17
|
+
batchedUpdates: function (callback) {}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
module.exports = ReactServerBatchingStrategy;
|
|
21
|
+
|
|
22
|
+
// Don't do anything here. During the server rendering we don't want to
|
|
23
|
+
// schedule any updates. We will simply ignore them.
|
|
@@ -11,10 +11,13 @@
|
|
|
11
11
|
*/
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
+
var ReactDefaultBatchingStrategy = require("./ReactDefaultBatchingStrategy");
|
|
14
15
|
var ReactElement = require("./ReactElement");
|
|
15
16
|
var ReactInstanceHandles = require("./ReactInstanceHandles");
|
|
16
17
|
var ReactMarkupChecksum = require("./ReactMarkupChecksum");
|
|
18
|
+
var ReactServerBatchingStrategy = require("./ReactServerBatchingStrategy");
|
|
17
19
|
var ReactServerRenderingTransaction = require("./ReactServerRenderingTransaction");
|
|
20
|
+
var ReactUpdates = require("./ReactUpdates");
|
|
18
21
|
|
|
19
22
|
var emptyObject = require("./emptyObject");
|
|
20
23
|
var instantiateReactComponent = require("./instantiateReactComponent");
|
|
@@ -29,6 +32,8 @@ function renderToString(element) {
|
|
|
29
32
|
|
|
30
33
|
var transaction;
|
|
31
34
|
try {
|
|
35
|
+
ReactUpdates.injection.injectBatchingStrategy(ReactServerBatchingStrategy);
|
|
36
|
+
|
|
32
37
|
var id = ReactInstanceHandles.createReactRootID();
|
|
33
38
|
transaction = ReactServerRenderingTransaction.getPooled(false);
|
|
34
39
|
|
|
@@ -39,6 +44,9 @@ function renderToString(element) {
|
|
|
39
44
|
}, null);
|
|
40
45
|
} finally {
|
|
41
46
|
ReactServerRenderingTransaction.release(transaction);
|
|
47
|
+
// Revert to the DOM batching strategy since these two renderers
|
|
48
|
+
// currently share these stateful modules.
|
|
49
|
+
ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy);
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
52
|
|
|
@@ -52,6 +60,8 @@ function renderToStaticMarkup(element) {
|
|
|
52
60
|
|
|
53
61
|
var transaction;
|
|
54
62
|
try {
|
|
63
|
+
ReactUpdates.injection.injectBatchingStrategy(ReactServerBatchingStrategy);
|
|
64
|
+
|
|
55
65
|
var id = ReactInstanceHandles.createReactRootID();
|
|
56
66
|
transaction = ReactServerRenderingTransaction.getPooled(true);
|
|
57
67
|
|
|
@@ -61,6 +71,9 @@ function renderToStaticMarkup(element) {
|
|
|
61
71
|
}, null);
|
|
62
72
|
} finally {
|
|
63
73
|
ReactServerRenderingTransaction.release(transaction);
|
|
74
|
+
// Revert to the DOM batching strategy since these two renderers
|
|
75
|
+
// currently share these stateful modules.
|
|
76
|
+
ReactUpdates.injection.injectBatchingStrategy(ReactDefaultBatchingStrategy);
|
|
64
77
|
}
|
|
65
78
|
}
|
|
66
79
|
|
|
@@ -56,7 +56,7 @@ var Mixin = {
|
|
|
56
56
|
* @see Transaction
|
|
57
57
|
* @abstract
|
|
58
58
|
* @final
|
|
59
|
-
* @return {array} Empty list of operation wrap
|
|
59
|
+
* @return {array} Empty list of operation wrap procedures.
|
|
60
60
|
*/
|
|
61
61
|
getTransactionWrappers: function () {
|
|
62
62
|
return TRANSACTION_WRAPPERS;
|
|
@@ -71,7 +71,7 @@ var Mixin = {
|
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* `PooledClass` looks for this, and will invoke this before allowing this
|
|
74
|
-
* instance to be
|
|
74
|
+
* instance to be reused.
|
|
75
75
|
*/
|
|
76
76
|
destructor: function () {
|
|
77
77
|
CallbackQueue.release(this.reactMountReady);
|
package/lib/ReactTestUtils.js
CHANGED
|
@@ -28,6 +28,7 @@ var SyntheticEvent = require("./SyntheticEvent");
|
|
|
28
28
|
var assign = require("./Object.assign");
|
|
29
29
|
var emptyObject = require("./emptyObject");
|
|
30
30
|
var findDOMNode = require("./findDOMNode");
|
|
31
|
+
var invariant = require("./invariant");
|
|
31
32
|
|
|
32
33
|
var topLevelTypes = EventConstants.topLevelTypes;
|
|
33
34
|
|
|
@@ -37,6 +38,27 @@ function Event(suffix) {}
|
|
|
37
38
|
* @class ReactTestUtils
|
|
38
39
|
*/
|
|
39
40
|
|
|
41
|
+
function findAllInRenderedTreeInternal(inst, test) {
|
|
42
|
+
if (!inst || !inst.getPublicInstance) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
var publicInst = inst.getPublicInstance();
|
|
46
|
+
var ret = test(publicInst) ? [publicInst] : [];
|
|
47
|
+
if (ReactTestUtils.isDOMComponent(publicInst)) {
|
|
48
|
+
var renderedChildren = inst._renderedChildren;
|
|
49
|
+
var key;
|
|
50
|
+
for (key in renderedChildren) {
|
|
51
|
+
if (!renderedChildren.hasOwnProperty(key)) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
ret = ret.concat(findAllInRenderedTreeInternal(renderedChildren[key], test));
|
|
55
|
+
}
|
|
56
|
+
} else if (ReactTestUtils.isCompositeComponent(publicInst)) {
|
|
57
|
+
ret = ret.concat(findAllInRenderedTreeInternal(inst._renderedComponent, test));
|
|
58
|
+
}
|
|
59
|
+
return ret;
|
|
60
|
+
}
|
|
61
|
+
|
|
40
62
|
/**
|
|
41
63
|
* Todo: Support the entire DOM.scry query syntax. For now, these simple
|
|
42
64
|
* utilities will suffice for testing purposes.
|
|
@@ -64,7 +86,7 @@ var ReactTestUtils = {
|
|
|
64
86
|
isDOMComponent: function (inst) {
|
|
65
87
|
// TODO: Fix this heuristic. It's just here because composites can currently
|
|
66
88
|
// pretend to be DOM components.
|
|
67
|
-
return !!(inst && inst.
|
|
89
|
+
return !!(inst && inst.nodeType === 1 && inst.tagName);
|
|
68
90
|
},
|
|
69
91
|
|
|
70
92
|
isDOMComponentElement: function (inst) {
|
|
@@ -72,11 +94,22 @@ var ReactTestUtils = {
|
|
|
72
94
|
},
|
|
73
95
|
|
|
74
96
|
isCompositeComponent: function (inst) {
|
|
97
|
+
if (ReactTestUtils.isDOMComponent(inst)) {
|
|
98
|
+
// Accessing inst.setState warns; just return false as that'll be what
|
|
99
|
+
// this returns when we have DOM nodes as refs directly
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
75
102
|
return typeof inst.render === 'function' && typeof inst.setState === 'function';
|
|
76
103
|
},
|
|
77
104
|
|
|
78
105
|
isCompositeComponentWithType: function (inst, type) {
|
|
79
|
-
|
|
106
|
+
if (!ReactTestUtils.isCompositeComponent(inst)) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
var internalInstance = ReactInstanceMap.get(inst);
|
|
110
|
+
var constructor = internalInstance._currentElement.type;
|
|
111
|
+
|
|
112
|
+
return constructor === type;
|
|
80
113
|
},
|
|
81
114
|
|
|
82
115
|
isCompositeComponentElement: function (inst) {
|
|
@@ -90,7 +123,10 @@ var ReactTestUtils = {
|
|
|
90
123
|
},
|
|
91
124
|
|
|
92
125
|
isCompositeComponentElementWithType: function (inst, type) {
|
|
93
|
-
|
|
126
|
+
var internalInstance = ReactInstanceMap.get(inst);
|
|
127
|
+
var constructor = internalInstance._currentElement.type;
|
|
128
|
+
|
|
129
|
+
return !!(ReactTestUtils.isCompositeComponentElement(inst) && constructor === type);
|
|
94
130
|
},
|
|
95
131
|
|
|
96
132
|
getRenderedChildOfCompositeComponent: function (inst) {
|
|
@@ -105,35 +141,22 @@ var ReactTestUtils = {
|
|
|
105
141
|
if (!inst) {
|
|
106
142
|
return [];
|
|
107
143
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
var internalInstance = ReactInstanceMap.get(inst);
|
|
111
|
-
var renderedChildren = internalInstance._renderedComponent._renderedChildren;
|
|
112
|
-
var key;
|
|
113
|
-
for (key in renderedChildren) {
|
|
114
|
-
if (!renderedChildren.hasOwnProperty(key)) {
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
if (!renderedChildren[key].getPublicInstance) {
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
ret = ret.concat(ReactTestUtils.findAllInRenderedTree(renderedChildren[key].getPublicInstance(), test));
|
|
121
|
-
}
|
|
122
|
-
} else if (ReactTestUtils.isCompositeComponent(inst)) {
|
|
123
|
-
ret = ret.concat(ReactTestUtils.findAllInRenderedTree(ReactTestUtils.getRenderedChildOfCompositeComponent(inst), test));
|
|
124
|
-
}
|
|
125
|
-
return ret;
|
|
144
|
+
!ReactTestUtils.isCompositeComponent(inst) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'findAllInRenderedTree(...): instance must be a composite component') : invariant(false) : undefined;
|
|
145
|
+
return findAllInRenderedTreeInternal(ReactInstanceMap.get(inst), test);
|
|
126
146
|
},
|
|
127
147
|
|
|
128
148
|
/**
|
|
129
149
|
* Finds all instance of components in the rendered tree that are DOM
|
|
130
150
|
* components with the class name matching `className`.
|
|
131
|
-
* @return an array of all the matches.
|
|
151
|
+
* @return {array} an array of all the matches.
|
|
132
152
|
*/
|
|
133
153
|
scryRenderedDOMComponentsWithClass: function (root, className) {
|
|
134
154
|
return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
|
135
|
-
|
|
136
|
-
|
|
155
|
+
if (ReactTestUtils.isDOMComponent(inst)) {
|
|
156
|
+
var instClassName = React.findDOMNode(inst).className;
|
|
157
|
+
return instClassName && ('' + instClassName).split(/\s+/).indexOf(className) !== -1;
|
|
158
|
+
}
|
|
159
|
+
return false;
|
|
137
160
|
});
|
|
138
161
|
},
|
|
139
162
|
|
|
@@ -154,7 +177,7 @@ var ReactTestUtils = {
|
|
|
154
177
|
/**
|
|
155
178
|
* Finds all instance of components in the rendered tree that are DOM
|
|
156
179
|
* components with the tag name matching `tagName`.
|
|
157
|
-
* @return an array of all the matches.
|
|
180
|
+
* @return {array} an array of all the matches.
|
|
158
181
|
*/
|
|
159
182
|
scryRenderedDOMComponentsWithTag: function (root, tagName) {
|
|
160
183
|
return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
|
@@ -178,7 +201,7 @@ var ReactTestUtils = {
|
|
|
178
201
|
|
|
179
202
|
/**
|
|
180
203
|
* Finds all instances of components with type equal to `componentType`.
|
|
181
|
-
* @return an array of all the matches.
|
|
204
|
+
* @return {array} an array of all the matches.
|
|
182
205
|
*/
|
|
183
206
|
scryRenderedComponentsWithType: function (root, componentType) {
|
|
184
207
|
return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
|
@@ -195,7 +218,7 @@ var ReactTestUtils = {
|
|
|
195
218
|
findRenderedComponentWithType: function (root, componentType) {
|
|
196
219
|
var all = ReactTestUtils.scryRenderedComponentsWithType(root, componentType);
|
|
197
220
|
if (all.length !== 1) {
|
|
198
|
-
throw new Error('Did not find exactly one match for componentType:' + componentType);
|
|
221
|
+
throw new Error('Did not find exactly one match for componentType:' + componentType + ' (found ' + all.length + ')');
|
|
199
222
|
}
|
|
200
223
|
return all[0];
|
|
201
224
|
},
|
|
@@ -226,7 +249,7 @@ var ReactTestUtils = {
|
|
|
226
249
|
/**
|
|
227
250
|
* Simulates a top level event being dispatched from a raw event that occured
|
|
228
251
|
* on an `Element` node.
|
|
229
|
-
* @param
|
|
252
|
+
* @param {Object} topLevelType A type from `EventConstants.topLevelTypes`
|
|
230
253
|
* @param {!Element} node The dom to simulate an event occurring on.
|
|
231
254
|
* @param {?Event} fakeNativeEvent Fake native event to use in SyntheticEvent.
|
|
232
255
|
*/
|
|
@@ -238,8 +261,8 @@ var ReactTestUtils = {
|
|
|
238
261
|
/**
|
|
239
262
|
* Simulates a top level event being dispatched from a raw event that occured
|
|
240
263
|
* on the `ReactDOMComponent` `comp`.
|
|
241
|
-
* @param
|
|
242
|
-
* @param
|
|
264
|
+
* @param {Object} topLevelType A type from `EventConstants.topLevelTypes`.
|
|
265
|
+
* @param {!ReactDOMComponent} comp
|
|
243
266
|
* @param {?Event} fakeNativeEvent Fake native event to use in SyntheticEvent.
|
|
244
267
|
*/
|
|
245
268
|
simulateNativeEventOnDOMComponent: function (topLevelType, comp, fakeNativeEvent) {
|
|
@@ -350,7 +373,7 @@ function makeSimulator(eventType) {
|
|
|
350
373
|
fakeNativeEvent.target = node;
|
|
351
374
|
// We don't use SyntheticEvent.getPooled in order to not have to worry about
|
|
352
375
|
// properly destroying any properties assigned from `eventData` upon release
|
|
353
|
-
var event = new SyntheticEvent(dispatchConfig, ReactMount.getID(node), fakeNativeEvent);
|
|
376
|
+
var event = new SyntheticEvent(dispatchConfig, ReactMount.getID(node), fakeNativeEvent, node);
|
|
354
377
|
assign(event, eventData);
|
|
355
378
|
|
|
356
379
|
if (dispatchConfig.phasedRegistrationNames) {
|
|
@@ -372,7 +395,7 @@ function buildSimulators() {
|
|
|
372
395
|
var eventType;
|
|
373
396
|
for (eventType in ReactBrowserEventEmitter.eventNameDispatchConfigs) {
|
|
374
397
|
/**
|
|
375
|
-
* @param {!Element
|
|
398
|
+
* @param {!Element|ReactDOMComponent} domComponentOrNode
|
|
376
399
|
* @param {?object} eventData Fake event data to use in SyntheticEvent.
|
|
377
400
|
*/
|
|
378
401
|
ReactTestUtils.Simulate[eventType] = makeSimulator(eventType);
|
|
@@ -427,7 +450,7 @@ for (eventType in topLevelTypes) {
|
|
|
427
450
|
// Event type is stored as 'topClick' - we transform that to 'click'
|
|
428
451
|
var convenienceName = eventType.indexOf('top') === 0 ? eventType.charAt(3).toLowerCase() + eventType.substr(4) : eventType;
|
|
429
452
|
/**
|
|
430
|
-
* @param {!Element
|
|
453
|
+
* @param {!Element|ReactDOMComponent} domComponentOrNode
|
|
431
454
|
* @param {?Event} nativeEventData Fake native event to use in SyntheticEvent.
|
|
432
455
|
*/
|
|
433
456
|
ReactTestUtils.SimulateNative[convenienceName] = makeNativeSimulator(eventType);
|
package/lib/ReactUpdateQueue.js
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
var ReactLifeCycle = require("./ReactLifeCycle");
|
|
15
14
|
var ReactCurrentOwner = require("./ReactCurrentOwner");
|
|
16
15
|
var ReactElement = require("./ReactElement");
|
|
17
16
|
var ReactInstanceMap = require("./ReactInstanceMap");
|
|
@@ -22,17 +21,13 @@ var invariant = require("./invariant");
|
|
|
22
21
|
var warning = require("./warning");
|
|
23
22
|
|
|
24
23
|
function enqueueUpdate(internalInstance) {
|
|
25
|
-
|
|
26
|
-
// If we're in a componentWillMount handler, don't enqueue a rerender
|
|
27
|
-
// because ReactUpdates assumes we're in a browser context (which is
|
|
28
|
-
// wrong for server rendering) and we're about to do a render anyway.
|
|
29
|
-
// See bug in #1740.
|
|
30
|
-
ReactUpdates.enqueueUpdate(internalInstance);
|
|
31
|
-
}
|
|
24
|
+
ReactUpdates.enqueueUpdate(internalInstance);
|
|
32
25
|
}
|
|
33
26
|
|
|
34
27
|
function getInternalInstanceReadyForUpdate(publicInstance, callerName) {
|
|
35
|
-
|
|
28
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
29
|
+
'production' !== process.env.NODE_ENV ? warning(ReactCurrentOwner.current == null, '%s(...): Cannot update during an existing state transition ' + '(such as within `render`). Render methods should be a pure function ' + 'of props and state.', callerName) : undefined;
|
|
30
|
+
}
|
|
36
31
|
|
|
37
32
|
var internalInstance = ReactInstanceMap.get(publicInstance);
|
|
38
33
|
if (!internalInstance) {
|
|
@@ -40,15 +35,11 @@ function getInternalInstanceReadyForUpdate(publicInstance, callerName) {
|
|
|
40
35
|
// Only warn when we have a callerName. Otherwise we should be silent.
|
|
41
36
|
// We're probably calling from enqueueCallback. We don't want to warn
|
|
42
37
|
// there because we already warned for the corresponding lifecycle method.
|
|
43
|
-
'production' !== process.env.NODE_ENV ? warning(!callerName, '%s(...): Can only update a mounted or mounting component. ' + 'This usually means you called %s() on an unmounted ' + '
|
|
38
|
+
'production' !== process.env.NODE_ENV ? warning(!callerName, '%s(...): Can only update a mounted or mounting component. ' + 'This usually means you called %s() on an unmounted component. ' + 'This is a no-op. Please check the code for the %s component.', callerName, callerName, publicInstance.constructor.displayName) : undefined;
|
|
44
39
|
}
|
|
45
40
|
return null;
|
|
46
41
|
}
|
|
47
42
|
|
|
48
|
-
if (internalInstance === ReactLifeCycle.currentlyUnmountingInstance) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
43
|
return internalInstance;
|
|
53
44
|
}
|
|
54
45
|
|
|
@@ -58,6 +49,32 @@ function getInternalInstanceReadyForUpdate(publicInstance, callerName) {
|
|
|
58
49
|
*/
|
|
59
50
|
var ReactUpdateQueue = {
|
|
60
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Checks whether or not this composite component is mounted.
|
|
54
|
+
* @param {ReactClass} publicInstance The instance we want to test.
|
|
55
|
+
* @return {boolean} True if mounted, false otherwise.
|
|
56
|
+
* @protected
|
|
57
|
+
* @final
|
|
58
|
+
*/
|
|
59
|
+
isMounted: function (publicInstance) {
|
|
60
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
61
|
+
var owner = ReactCurrentOwner.current;
|
|
62
|
+
if (owner !== null) {
|
|
63
|
+
'production' !== process.env.NODE_ENV ? warning(owner._warnedAboutRefsInRender, '%s is accessing isMounted inside its render() function. ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', owner.getName() || 'A component') : undefined;
|
|
64
|
+
owner._warnedAboutRefsInRender = true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
var internalInstance = ReactInstanceMap.get(publicInstance);
|
|
68
|
+
if (internalInstance) {
|
|
69
|
+
// During componentWillMount and render this will still be null but after
|
|
70
|
+
// that will always render to something. At least for now. So we can use
|
|
71
|
+
// this hack.
|
|
72
|
+
return !!internalInstance._renderedComponent;
|
|
73
|
+
} else {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
|
|
61
78
|
/**
|
|
62
79
|
* Enqueue a callback that will be executed after all the pending updates
|
|
63
80
|
* have processed.
|
|
@@ -75,7 +92,7 @@ var ReactUpdateQueue = {
|
|
|
75
92
|
// behavior we have in other enqueue* methods.
|
|
76
93
|
// We also need to ignore callbacks in componentWillMount. See
|
|
77
94
|
// enqueueUpdates.
|
|
78
|
-
if (!internalInstance
|
|
95
|
+
if (!internalInstance) {
|
|
79
96
|
return null;
|
|
80
97
|
}
|
|
81
98
|
|
|
@@ -108,7 +125,7 @@ var ReactUpdateQueue = {
|
|
|
108
125
|
* You may want to call this when you know that some deeper aspect of the
|
|
109
126
|
* component's state has changed but `setState` was not called.
|
|
110
127
|
*
|
|
111
|
-
* This will not invoke `
|
|
128
|
+
* This will not invoke `shouldComponentUpdate`, but it will invoke
|
|
112
129
|
* `componentWillUpdate` and `componentDidUpdate`.
|
|
113
130
|
*
|
|
114
131
|
* @param {ReactClass} publicInstance The instance that should rerender.
|
|
@@ -182,20 +199,24 @@ var ReactUpdateQueue = {
|
|
|
182
199
|
*/
|
|
183
200
|
enqueueSetProps: function (publicInstance, partialProps) {
|
|
184
201
|
var internalInstance = getInternalInstanceReadyForUpdate(publicInstance, 'setProps');
|
|
185
|
-
|
|
186
202
|
if (!internalInstance) {
|
|
187
203
|
return;
|
|
188
204
|
}
|
|
205
|
+
ReactUpdateQueue.enqueueSetPropsInternal(internalInstance, partialProps);
|
|
206
|
+
},
|
|
189
207
|
|
|
190
|
-
|
|
208
|
+
enqueueSetPropsInternal: function (internalInstance, partialProps) {
|
|
209
|
+
var topLevelWrapper = internalInstance._topLevelWrapper;
|
|
210
|
+
!topLevelWrapper ? 'production' !== process.env.NODE_ENV ? invariant(false, 'setProps(...): You called `setProps` on a ' + 'component with a parent. This is an anti-pattern since props will ' + 'get reactively updated when rendered. Instead, change the owner\'s ' + '`render` method to pass the correct value as props to the component ' + 'where it is created.') : invariant(false) : undefined;
|
|
191
211
|
|
|
192
212
|
// Merge with the pending element if it exists, otherwise with existing
|
|
193
213
|
// element props.
|
|
194
|
-
var
|
|
214
|
+
var wrapElement = topLevelWrapper._pendingElement || topLevelWrapper._currentElement;
|
|
215
|
+
var element = wrapElement.props;
|
|
195
216
|
var props = assign({}, element.props, partialProps);
|
|
196
|
-
|
|
217
|
+
topLevelWrapper._pendingElement = ReactElement.cloneAndReplaceProps(wrapElement, ReactElement.cloneAndReplaceProps(element, props));
|
|
197
218
|
|
|
198
|
-
enqueueUpdate(
|
|
219
|
+
enqueueUpdate(topLevelWrapper);
|
|
199
220
|
},
|
|
200
221
|
|
|
201
222
|
/**
|
|
@@ -207,19 +228,23 @@ var ReactUpdateQueue = {
|
|
|
207
228
|
*/
|
|
208
229
|
enqueueReplaceProps: function (publicInstance, props) {
|
|
209
230
|
var internalInstance = getInternalInstanceReadyForUpdate(publicInstance, 'replaceProps');
|
|
210
|
-
|
|
211
231
|
if (!internalInstance) {
|
|
212
232
|
return;
|
|
213
233
|
}
|
|
234
|
+
ReactUpdateQueue.enqueueReplacePropsInternal(internalInstance, props);
|
|
235
|
+
},
|
|
214
236
|
|
|
215
|
-
|
|
237
|
+
enqueueReplacePropsInternal: function (internalInstance, props) {
|
|
238
|
+
var topLevelWrapper = internalInstance._topLevelWrapper;
|
|
239
|
+
!topLevelWrapper ? 'production' !== process.env.NODE_ENV ? invariant(false, 'replaceProps(...): You called `replaceProps` on a ' + 'component with a parent. This is an anti-pattern since props will ' + 'get reactively updated when rendered. Instead, change the owner\'s ' + '`render` method to pass the correct value as props to the component ' + 'where it is created.') : invariant(false) : undefined;
|
|
216
240
|
|
|
217
241
|
// Merge with the pending element if it exists, otherwise with existing
|
|
218
242
|
// element props.
|
|
219
|
-
var
|
|
220
|
-
|
|
243
|
+
var wrapElement = topLevelWrapper._pendingElement || topLevelWrapper._currentElement;
|
|
244
|
+
var element = wrapElement.props;
|
|
245
|
+
topLevelWrapper._pendingElement = ReactElement.cloneAndReplaceProps(wrapElement, ReactElement.cloneAndReplaceProps(element, props));
|
|
221
246
|
|
|
222
|
-
enqueueUpdate(
|
|
247
|
+
enqueueUpdate(topLevelWrapper);
|
|
223
248
|
},
|
|
224
249
|
|
|
225
250
|
enqueueElementInternal: function (internalInstance, newElement) {
|