react 0.13.2 → 0.14.0-alpha3
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 +1 -1
- package/addons.js +7 -0
- package/addons/CSSTransitionGroup.js +1 -0
- package/addons/LinkedStateMixin.js +1 -0
- package/addons/Perf.js +1 -0
- package/addons/PureRenderMixin.js +1 -0
- package/addons/TestUtils.js +1 -0
- package/addons/TransitionGroup.js +1 -0
- package/addons/batchedUpdates.js +1 -0
- package/addons/cloneWithProps.js +1 -0
- package/addons/createFragment.js +1 -0
- package/addons/renderSubtreeIntoContainer.js +1 -0
- package/addons/shallowCompare.js +1 -0
- package/addons/update.js +1 -0
- package/dist/JSXTransformer.js +3355 -1685
- package/dist/react-with-addons.js +3320 -5133
- package/dist/react-with-addons.min.js +6 -7
- package/dist/react.js +2962 -4548
- package/dist/react.min.js +5 -5
- package/lib/AutoFocusMixin.js +4 -3
- package/lib/BeforeInputEventPlugin.js +30 -118
- package/lib/CSSCore.js +12 -23
- package/lib/CSSProperty.js +4 -3
- package/lib/CSSPropertyOperations.js +14 -30
- package/lib/CallbackQueue.js +7 -10
- package/lib/ChangeEventPlugin.js +24 -88
- package/lib/ClientReactRootIndex.js +2 -2
- package/lib/DOMChildrenOperations.js +13 -33
- package/lib/DOMProperty.js +41 -67
- package/lib/DOMPropertyOperations.js +30 -51
- package/lib/Danger.js +19 -62
- package/lib/DefaultEventPluginOrder.js +2 -12
- package/lib/EnterLeaveEventPlugin.js +11 -33
- package/lib/EventConstants.js +2 -2
- package/lib/EventListener.js +11 -13
- package/lib/EventPluginHub.js +44 -47
- package/lib/EventPluginRegistry.js +18 -74
- package/lib/EventPluginUtils.js +27 -38
- package/lib/EventPropagators.js +23 -26
- package/lib/ExecutionEnvironment.js +4 -8
- package/lib/FallbackCompositionState.js +3 -3
- package/lib/HTMLDOMPropertyConfig.js +7 -19
- package/lib/LinkedStateMixin.js +3 -6
- package/lib/LinkedValueUtils.js +34 -64
- package/lib/LocalEventTrapMixin.js +9 -16
- package/lib/Object.assign.js +1 -1
- package/lib/PooledClass.js +8 -11
- package/lib/React.js +9 -129
- package/lib/ReactBrowserComponentMixin.js +9 -2
- package/lib/ReactBrowserEventEmitter.js +26 -82
- package/lib/ReactCSSTransitionGroup.js +13 -24
- package/lib/ReactCSSTransitionGroupChild.js +18 -28
- package/lib/ReactChildReconciler.js +11 -19
- package/lib/ReactChildren.js +21 -28
- package/lib/ReactClass.js +81 -234
- package/lib/ReactComponent.js +17 -33
- package/lib/ReactComponentBrowserEnvironment.js +4 -8
- package/lib/ReactComponentEnvironment.js +6 -12
- package/lib/ReactComponentWithPureRenderMixin.js +4 -5
- package/lib/ReactCompositeComponent.js +87 -311
- package/lib/ReactContext.js +2 -44
- package/lib/ReactCurrentOwner.js +1 -3
- package/lib/ReactDOM.js +4 -2
- package/lib/ReactDOMButton.js +3 -4
- package/lib/ReactDOMClient.js +85 -0
- package/lib/ReactDOMComponent.js +182 -146
- package/lib/ReactDOMForm.js +3 -3
- package/lib/ReactDOMIDOperations.js +11 -22
- package/lib/ReactDOMIframe.js +3 -3
- package/lib/ReactDOMImg.js +3 -3
- package/lib/ReactDOMInput.js +22 -35
- package/lib/ReactDOMOption.js +67 -10
- package/lib/ReactDOMSelect.js +50 -28
- package/lib/ReactDOMSelection.js +5 -20
- package/lib/ReactDOMServer.js +24 -0
- package/lib/ReactDOMTextComponent.js +17 -18
- package/lib/ReactDOMTextarea.js +15 -27
- package/lib/ReactDefaultBatchingStrategy.js +9 -13
- package/lib/ReactDefaultInjection.js +31 -40
- package/lib/ReactDefaultPerf.js +36 -69
- package/lib/ReactDefaultPerfAnalysis.js +8 -14
- package/lib/ReactElement.js +24 -57
- package/lib/ReactElementValidator.js +38 -105
- package/lib/ReactEmptyComponent.js +7 -11
- package/lib/ReactErrorUtils.js +2 -2
- package/lib/ReactEventEmitterMixin.js +3 -12
- package/lib/ReactEventListener.js +16 -38
- package/lib/ReactFragment.js +23 -54
- package/lib/ReactInjection.js +1 -1
- package/lib/ReactInputSelection.js +11 -21
- package/lib/ReactInstanceHandles.js +27 -57
- package/lib/ReactInstanceMap.js +5 -5
- package/lib/ReactIsomorphic.js +70 -0
- package/lib/ReactLifeCycle.js +1 -1
- package/lib/ReactLink.js +2 -4
- package/lib/ReactMarkupChecksum.js +5 -10
- package/lib/ReactMount.js +137 -260
- package/lib/ReactMultiChild.js +19 -45
- package/lib/ReactMultiChildUpdateTypes.js +1 -1
- package/lib/ReactNativeComponent.js +7 -11
- package/lib/ReactOwner.js +7 -24
- package/lib/ReactPerf.js +8 -12
- package/lib/ReactPropTransferer.js +4 -4
- package/lib/ReactPropTypeLocationNames.js +2 -2
- package/lib/ReactPropTypeLocations.js +1 -1
- package/lib/ReactPropTypes.js +41 -61
- package/lib/ReactReconcileTransaction.js +9 -34
- package/lib/ReactReconciler.js +9 -19
- package/lib/ReactRef.js +5 -8
- package/lib/ReactRootIndex.js +2 -2
- package/lib/ReactServerRendering.js +7 -15
- package/lib/ReactServerRenderingTransaction.js +7 -32
- package/lib/ReactStateSetters.js +6 -6
- package/lib/ReactTestUtils.js +93 -165
- package/lib/ReactTransitionChildMapping.js +5 -7
- package/lib/ReactTransitionEvents.js +5 -5
- package/lib/ReactTransitionGroup.js +30 -52
- package/lib/ReactUpdateQueue.js +27 -90
- package/lib/ReactUpdates.js +27 -79
- package/lib/ReactWithAddons.js +7 -6
- package/lib/SVGDOMPropertyConfig.js +41 -4
- package/lib/SelectEventPlugin.js +28 -29
- package/lib/ServerReactRootIndex.js +2 -2
- package/lib/SimpleEventPlugin.js +136 -128
- package/lib/SyntheticClipboardEvent.js +3 -7
- package/lib/SyntheticCompositionEvent.js +3 -9
- package/lib/SyntheticDragEvent.js +1 -1
- package/lib/SyntheticEvent.js +8 -10
- package/lib/SyntheticFocusEvent.js +1 -1
- package/lib/SyntheticInputEvent.js +3 -9
- package/lib/SyntheticKeyboardEvent.js +4 -4
- package/lib/SyntheticMouseEvent.js +8 -14
- package/lib/SyntheticTouchEvent.js +1 -1
- package/lib/SyntheticUIEvent.js +3 -3
- package/lib/SyntheticWheelEvent.js +11 -15
- package/lib/Transaction.js +12 -24
- package/lib/ViewportMetrics.js +2 -2
- package/lib/accumulateInto.js +2 -5
- package/lib/adler32.js +2 -4
- package/lib/camelize.js +4 -2
- package/lib/camelizeStyleName.js +2 -2
- package/lib/cloneWithProps.js +5 -11
- package/lib/containsNode.js +29 -16
- package/lib/createArrayFromMixed.js +17 -16
- package/lib/createFullPageComponent.js +4 -11
- package/lib/createNodesFromMarkup.js +6 -8
- package/lib/dangerousStyleValue.js +2 -3
- package/lib/emptyFunction.js +10 -4
- package/lib/emptyObject.js +1 -1
- package/lib/escapeTextContentForBrowser.js +1 -1
- package/lib/findDOMNode.js +5 -24
- package/lib/flattenChildren.js +4 -10
- package/lib/focusNode.js +2 -3
- package/lib/forEachAccumulated.js +2 -2
- package/lib/getActiveElement.js +4 -2
- 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 +2 -4
- package/lib/getMarkupWrap.js +7 -5
- package/lib/getNodeForCharacterOffset.js +1 -1
- package/lib/getTextContentAccessor.js +2 -4
- package/lib/getUnboundedScrollPosition.js +1 -1
- package/lib/hyphenate.js +3 -1
- package/lib/hyphenateStyleName.js +2 -2
- package/lib/instantiateReactComponent.js +14 -38
- package/lib/invariant.js +8 -12
- package/lib/isEventSupported.js +7 -10
- package/lib/isNode.js +4 -6
- package/lib/isTextInputElement.js +2 -4
- package/lib/isTextNode.js +3 -1
- package/lib/joinClasses.js +2 -2
- package/lib/keyMirror.js +3 -6
- package/lib/keyOf.js +4 -3
- package/lib/mapObject.js +1 -1
- package/lib/memoizeStringOnly.js +2 -2
- package/lib/onlyChild.js +2 -5
- package/lib/performance.js +2 -5
- package/lib/performanceNow.js +3 -1
- package/lib/quoteAttributeValueForBrowser.js +1 -1
- package/lib/renderSubtreeIntoContainer.js +16 -0
- package/lib/setInnerHTML.js +11 -8
- package/lib/setTextContent.js +3 -3
- package/lib/shallowCompare.js +24 -0
- package/lib/shallowEqual.js +17 -11
- package/lib/shouldUpdateReactComponent.js +3 -64
- package/lib/toArray.js +8 -19
- package/lib/traverseAllChildren.js +22 -89
- package/lib/update.js +25 -85
- package/lib/validateDOMNesting.js +363 -0
- package/lib/warning.js +17 -15
- package/package.json +3 -3
- package/lib/MobileSafariClickEventPlugin.js +0 -56
- package/lib/ReactPutListenerQueue.js +0 -54
- package/lib/cx.js +0 -52
- package/lib/getReactRootElementInContainer.js +0 -33
|
@@ -16,7 +16,6 @@ var CallbackQueue = require("./CallbackQueue");
|
|
|
16
16
|
var PooledClass = require("./PooledClass");
|
|
17
17
|
var ReactBrowserEventEmitter = require("./ReactBrowserEventEmitter");
|
|
18
18
|
var ReactInputSelection = require("./ReactInputSelection");
|
|
19
|
-
var ReactPutListenerQueue = require("./ReactPutListenerQueue");
|
|
20
19
|
var Transaction = require("./Transaction");
|
|
21
20
|
|
|
22
21
|
var assign = require("./Object.assign");
|
|
@@ -46,7 +45,7 @@ var EVENT_SUPPRESSION = {
|
|
|
46
45
|
* @return {boolean} The enabled status of `ReactBrowserEventEmitter` before
|
|
47
46
|
* the reconciliation.
|
|
48
47
|
*/
|
|
49
|
-
initialize: function() {
|
|
48
|
+
initialize: function () {
|
|
50
49
|
var currentlyEnabled = ReactBrowserEventEmitter.isEnabled();
|
|
51
50
|
ReactBrowserEventEmitter.setEnabled(false);
|
|
52
51
|
return currentlyEnabled;
|
|
@@ -57,7 +56,7 @@ var EVENT_SUPPRESSION = {
|
|
|
57
56
|
* `ReactBrowserEventEmitter` before the reconciliation occured. `close`
|
|
58
57
|
* restores the previous value.
|
|
59
58
|
*/
|
|
60
|
-
close: function(previouslyEnabled) {
|
|
59
|
+
close: function (previouslyEnabled) {
|
|
61
60
|
ReactBrowserEventEmitter.setEnabled(previouslyEnabled);
|
|
62
61
|
}
|
|
63
62
|
};
|
|
@@ -70,39 +69,24 @@ var ON_DOM_READY_QUEUEING = {
|
|
|
70
69
|
/**
|
|
71
70
|
* Initializes the internal `onDOMReady` queue.
|
|
72
71
|
*/
|
|
73
|
-
initialize: function() {
|
|
72
|
+
initialize: function () {
|
|
74
73
|
this.reactMountReady.reset();
|
|
75
74
|
},
|
|
76
75
|
|
|
77
76
|
/**
|
|
78
77
|
* After DOM is flushed, invoke all registered `onDOMReady` callbacks.
|
|
79
78
|
*/
|
|
80
|
-
close: function() {
|
|
79
|
+
close: function () {
|
|
81
80
|
this.reactMountReady.notifyAll();
|
|
82
81
|
}
|
|
83
82
|
};
|
|
84
83
|
|
|
85
|
-
var PUT_LISTENER_QUEUEING = {
|
|
86
|
-
initialize: function() {
|
|
87
|
-
this.putListenerQueue.reset();
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
close: function() {
|
|
91
|
-
this.putListenerQueue.putListeners();
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
84
|
/**
|
|
96
85
|
* Executed within the scope of the `Transaction` instance. Consider these as
|
|
97
86
|
* being member methods, but with an implied ordering while being isolated from
|
|
98
87
|
* each other.
|
|
99
88
|
*/
|
|
100
|
-
var TRANSACTION_WRAPPERS = [
|
|
101
|
-
PUT_LISTENER_QUEUEING,
|
|
102
|
-
SELECTION_RESTORATION,
|
|
103
|
-
EVENT_SUPPRESSION,
|
|
104
|
-
ON_DOM_READY_QUEUEING
|
|
105
|
-
];
|
|
89
|
+
var TRANSACTION_WRAPPERS = [SELECTION_RESTORATION, EVENT_SUPPRESSION, ON_DOM_READY_QUEUEING];
|
|
106
90
|
|
|
107
91
|
/**
|
|
108
92
|
* Currently:
|
|
@@ -127,7 +111,6 @@ function ReactReconcileTransaction() {
|
|
|
127
111
|
// `ReactTextComponent` checks it in `mountComponent`.`
|
|
128
112
|
this.renderToStaticMarkup = false;
|
|
129
113
|
this.reactMountReady = CallbackQueue.getPooled(null);
|
|
130
|
-
this.putListenerQueue = ReactPutListenerQueue.getPooled();
|
|
131
114
|
}
|
|
132
115
|
|
|
133
116
|
var Mixin = {
|
|
@@ -138,37 +121,29 @@ var Mixin = {
|
|
|
138
121
|
* @return {array<object>} List of operation wrap proceedures.
|
|
139
122
|
* TODO: convert to array<TransactionWrapper>
|
|
140
123
|
*/
|
|
141
|
-
getTransactionWrappers: function() {
|
|
124
|
+
getTransactionWrappers: function () {
|
|
142
125
|
return TRANSACTION_WRAPPERS;
|
|
143
126
|
},
|
|
144
127
|
|
|
145
128
|
/**
|
|
146
129
|
* @return {object} The queue to collect `onDOMReady` callbacks with.
|
|
147
130
|
*/
|
|
148
|
-
getReactMountReady: function() {
|
|
131
|
+
getReactMountReady: function () {
|
|
149
132
|
return this.reactMountReady;
|
|
150
133
|
},
|
|
151
134
|
|
|
152
|
-
getPutListenerQueue: function() {
|
|
153
|
-
return this.putListenerQueue;
|
|
154
|
-
},
|
|
155
|
-
|
|
156
135
|
/**
|
|
157
136
|
* `PooledClass` looks for this, and will invoke this before allowing this
|
|
158
137
|
* instance to be resused.
|
|
159
138
|
*/
|
|
160
|
-
destructor: function() {
|
|
139
|
+
destructor: function () {
|
|
161
140
|
CallbackQueue.release(this.reactMountReady);
|
|
162
141
|
this.reactMountReady = null;
|
|
163
|
-
|
|
164
|
-
ReactPutListenerQueue.release(this.putListenerQueue);
|
|
165
|
-
this.putListenerQueue = null;
|
|
166
142
|
}
|
|
167
143
|
};
|
|
168
144
|
|
|
169
|
-
|
|
170
145
|
assign(ReactReconcileTransaction.prototype, Transaction.Mixin, Mixin);
|
|
171
146
|
|
|
172
147
|
PooledClass.addPoolingTo(ReactReconcileTransaction);
|
|
173
148
|
|
|
174
|
-
module.exports = ReactReconcileTransaction;
|
|
149
|
+
module.exports = ReactReconcileTransaction;
|
package/lib/ReactReconciler.js
CHANGED
|
@@ -34,12 +34,10 @@ var ReactReconciler = {
|
|
|
34
34
|
* @final
|
|
35
35
|
* @internal
|
|
36
36
|
*/
|
|
37
|
-
mountComponent: function(internalInstance, rootID, transaction, context) {
|
|
37
|
+
mountComponent: function (internalInstance, rootID, transaction, context) {
|
|
38
38
|
var markup = internalInstance.mountComponent(rootID, transaction, context);
|
|
39
|
-
if (
|
|
40
|
-
ReactElementValidator.checkAndWarnForMutatedProps(
|
|
41
|
-
internalInstance._currentElement
|
|
42
|
-
);
|
|
39
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
40
|
+
ReactElementValidator.checkAndWarnForMutatedProps(internalInstance._currentElement);
|
|
43
41
|
}
|
|
44
42
|
transaction.getReactMountReady().enqueue(attachRefs, internalInstance);
|
|
45
43
|
return markup;
|
|
@@ -51,7 +49,7 @@ var ReactReconciler = {
|
|
|
51
49
|
* @final
|
|
52
50
|
* @internal
|
|
53
51
|
*/
|
|
54
|
-
unmountComponent: function(internalInstance) {
|
|
52
|
+
unmountComponent: function (internalInstance) {
|
|
55
53
|
ReactRef.detachRefs(internalInstance, internalInstance._currentElement);
|
|
56
54
|
internalInstance.unmountComponent();
|
|
57
55
|
},
|
|
@@ -65,9 +63,7 @@ var ReactReconciler = {
|
|
|
65
63
|
* @param {object} context
|
|
66
64
|
* @internal
|
|
67
65
|
*/
|
|
68
|
-
receiveComponent: function(
|
|
69
|
-
internalInstance, nextElement, transaction, context
|
|
70
|
-
) {
|
|
66
|
+
receiveComponent: function (internalInstance, nextElement, transaction, context) {
|
|
71
67
|
var prevElement = internalInstance._currentElement;
|
|
72
68
|
|
|
73
69
|
if (nextElement === prevElement && nextElement._owner != null) {
|
|
@@ -81,14 +77,11 @@ var ReactReconciler = {
|
|
|
81
77
|
return;
|
|
82
78
|
}
|
|
83
79
|
|
|
84
|
-
if (
|
|
80
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
85
81
|
ReactElementValidator.checkAndWarnForMutatedProps(nextElement);
|
|
86
82
|
}
|
|
87
83
|
|
|
88
|
-
var refsChanged = ReactRef.shouldUpdateRefs(
|
|
89
|
-
prevElement,
|
|
90
|
-
nextElement
|
|
91
|
-
);
|
|
84
|
+
var refsChanged = ReactRef.shouldUpdateRefs(prevElement, nextElement);
|
|
92
85
|
|
|
93
86
|
if (refsChanged) {
|
|
94
87
|
ReactRef.detachRefs(internalInstance, prevElement);
|
|
@@ -108,13 +101,10 @@ var ReactReconciler = {
|
|
|
108
101
|
* @param {ReactReconcileTransaction} transaction
|
|
109
102
|
* @internal
|
|
110
103
|
*/
|
|
111
|
-
performUpdateIfNecessary: function(
|
|
112
|
-
internalInstance,
|
|
113
|
-
transaction
|
|
114
|
-
) {
|
|
104
|
+
performUpdateIfNecessary: function (internalInstance, transaction) {
|
|
115
105
|
internalInstance.performUpdateIfNecessary(transaction);
|
|
116
106
|
}
|
|
117
107
|
|
|
118
108
|
};
|
|
119
109
|
|
|
120
|
-
module.exports = ReactReconciler;
|
|
110
|
+
module.exports = ReactReconciler;
|
package/lib/ReactRef.js
CHANGED
|
@@ -33,14 +33,14 @@ function detachRef(ref, component, owner) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
ReactRef.attachRefs = function(instance, element) {
|
|
36
|
+
ReactRef.attachRefs = function (instance, element) {
|
|
37
37
|
var ref = element.ref;
|
|
38
38
|
if (ref != null) {
|
|
39
39
|
attachRef(ref, instance, element._owner);
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
ReactRef.shouldUpdateRefs = function(prevElement, nextElement) {
|
|
43
|
+
ReactRef.shouldUpdateRefs = function (prevElement, nextElement) {
|
|
44
44
|
// If either the owner or a `ref` has changed, make sure the newest owner
|
|
45
45
|
// has stored a reference to `this`, and the previous owner (if different)
|
|
46
46
|
// has forgotten the reference to `this`. We use the element instead
|
|
@@ -53,17 +53,14 @@ ReactRef.shouldUpdateRefs = function(prevElement, nextElement) {
|
|
|
53
53
|
// is made. It probably belongs where the key checking and
|
|
54
54
|
// instantiateReactComponent is done.
|
|
55
55
|
|
|
56
|
-
return
|
|
57
|
-
nextElement._owner !== prevElement._owner ||
|
|
58
|
-
nextElement.ref !== prevElement.ref
|
|
59
|
-
);
|
|
56
|
+
return nextElement._owner !== prevElement._owner || nextElement.ref !== prevElement.ref;
|
|
60
57
|
};
|
|
61
58
|
|
|
62
|
-
ReactRef.detachRefs = function(instance, element) {
|
|
59
|
+
ReactRef.detachRefs = function (instance, element) {
|
|
63
60
|
var ref = element.ref;
|
|
64
61
|
if (ref != null) {
|
|
65
62
|
detachRef(ref, instance, element._owner);
|
|
66
63
|
}
|
|
67
64
|
};
|
|
68
65
|
|
|
69
|
-
module.exports = ReactRef;
|
|
66
|
+
module.exports = ReactRef;
|
package/lib/ReactRootIndex.js
CHANGED
|
@@ -16,7 +16,7 @@ var ReactRootIndexInjection = {
|
|
|
16
16
|
/**
|
|
17
17
|
* @param {function} _createReactRootIndex
|
|
18
18
|
*/
|
|
19
|
-
injectCreateReactRootIndex: function(_createReactRootIndex) {
|
|
19
|
+
injectCreateReactRootIndex: function (_createReactRootIndex) {
|
|
20
20
|
ReactRootIndex.createReactRootIndex = _createReactRootIndex;
|
|
21
21
|
}
|
|
22
22
|
};
|
|
@@ -26,4 +26,4 @@ var ReactRootIndex = {
|
|
|
26
26
|
injection: ReactRootIndexInjection
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
module.exports = ReactRootIndex;
|
|
29
|
+
module.exports = ReactRootIndex;
|
|
@@ -14,8 +14,7 @@
|
|
|
14
14
|
var ReactElement = require("./ReactElement");
|
|
15
15
|
var ReactInstanceHandles = require("./ReactInstanceHandles");
|
|
16
16
|
var ReactMarkupChecksum = require("./ReactMarkupChecksum");
|
|
17
|
-
var ReactServerRenderingTransaction =
|
|
18
|
-
require("./ReactServerRenderingTransaction");
|
|
17
|
+
var ReactServerRenderingTransaction = require("./ReactServerRenderingTransaction");
|
|
19
18
|
|
|
20
19
|
var emptyObject = require("./emptyObject");
|
|
21
20
|
var instantiateReactComponent = require("./instantiateReactComponent");
|
|
@@ -26,20 +25,16 @@ var invariant = require("./invariant");
|
|
|
26
25
|
* @return {string} the HTML markup
|
|
27
26
|
*/
|
|
28
27
|
function renderToString(element) {
|
|
29
|
-
(
|
|
30
|
-
ReactElement.isValidElement(element),
|
|
31
|
-
'renderToString(): You must pass a valid ReactElement.'
|
|
32
|
-
) : invariant(ReactElement.isValidElement(element)));
|
|
28
|
+
!ReactElement.isValidElement(element) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'renderToString(): You must pass a valid ReactElement.') : invariant(false) : undefined;
|
|
33
29
|
|
|
34
30
|
var transaction;
|
|
35
31
|
try {
|
|
36
32
|
var id = ReactInstanceHandles.createReactRootID();
|
|
37
33
|
transaction = ReactServerRenderingTransaction.getPooled(false);
|
|
38
34
|
|
|
39
|
-
return transaction.perform(function() {
|
|
35
|
+
return transaction.perform(function () {
|
|
40
36
|
var componentInstance = instantiateReactComponent(element, null);
|
|
41
|
-
var markup =
|
|
42
|
-
componentInstance.mountComponent(id, transaction, emptyObject);
|
|
37
|
+
var markup = componentInstance.mountComponent(id, transaction, emptyObject);
|
|
43
38
|
return ReactMarkupChecksum.addChecksumToMarkup(markup);
|
|
44
39
|
}, null);
|
|
45
40
|
} finally {
|
|
@@ -53,17 +48,14 @@ function renderToString(element) {
|
|
|
53
48
|
* (for generating static pages)
|
|
54
49
|
*/
|
|
55
50
|
function renderToStaticMarkup(element) {
|
|
56
|
-
(
|
|
57
|
-
ReactElement.isValidElement(element),
|
|
58
|
-
'renderToStaticMarkup(): You must pass a valid ReactElement.'
|
|
59
|
-
) : invariant(ReactElement.isValidElement(element)));
|
|
51
|
+
!ReactElement.isValidElement(element) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'renderToStaticMarkup(): You must pass a valid ReactElement.') : invariant(false) : undefined;
|
|
60
52
|
|
|
61
53
|
var transaction;
|
|
62
54
|
try {
|
|
63
55
|
var id = ReactInstanceHandles.createReactRootID();
|
|
64
56
|
transaction = ReactServerRenderingTransaction.getPooled(true);
|
|
65
57
|
|
|
66
|
-
return transaction.perform(function() {
|
|
58
|
+
return transaction.perform(function () {
|
|
67
59
|
var componentInstance = instantiateReactComponent(element, null);
|
|
68
60
|
return componentInstance.mountComponent(id, transaction, emptyObject);
|
|
69
61
|
}, null);
|
|
@@ -75,4 +67,4 @@ function renderToStaticMarkup(element) {
|
|
|
75
67
|
module.exports = {
|
|
76
68
|
renderToString: renderToString,
|
|
77
69
|
renderToStaticMarkup: renderToStaticMarkup
|
|
78
|
-
};
|
|
70
|
+
};
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
|
|
15
15
|
var PooledClass = require("./PooledClass");
|
|
16
16
|
var CallbackQueue = require("./CallbackQueue");
|
|
17
|
-
var ReactPutListenerQueue = require("./ReactPutListenerQueue");
|
|
18
17
|
var Transaction = require("./Transaction");
|
|
19
18
|
|
|
20
19
|
var assign = require("./Object.assign");
|
|
@@ -28,30 +27,19 @@ var ON_DOM_READY_QUEUEING = {
|
|
|
28
27
|
/**
|
|
29
28
|
* Initializes the internal `onDOMReady` queue.
|
|
30
29
|
*/
|
|
31
|
-
initialize: function() {
|
|
30
|
+
initialize: function () {
|
|
32
31
|
this.reactMountReady.reset();
|
|
33
32
|
},
|
|
34
33
|
|
|
35
34
|
close: emptyFunction
|
|
36
35
|
};
|
|
37
36
|
|
|
38
|
-
var PUT_LISTENER_QUEUEING = {
|
|
39
|
-
initialize: function() {
|
|
40
|
-
this.putListenerQueue.reset();
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
close: emptyFunction
|
|
44
|
-
};
|
|
45
|
-
|
|
46
37
|
/**
|
|
47
38
|
* Executed within the scope of the `Transaction` instance. Consider these as
|
|
48
39
|
* being member methods, but with an implied ordering while being isolated from
|
|
49
40
|
* each other.
|
|
50
41
|
*/
|
|
51
|
-
var TRANSACTION_WRAPPERS = [
|
|
52
|
-
PUT_LISTENER_QUEUEING,
|
|
53
|
-
ON_DOM_READY_QUEUEING
|
|
54
|
-
];
|
|
42
|
+
var TRANSACTION_WRAPPERS = [ON_DOM_READY_QUEUEING];
|
|
55
43
|
|
|
56
44
|
/**
|
|
57
45
|
* @class ReactServerRenderingTransaction
|
|
@@ -61,7 +49,6 @@ function ReactServerRenderingTransaction(renderToStaticMarkup) {
|
|
|
61
49
|
this.reinitializeTransaction();
|
|
62
50
|
this.renderToStaticMarkup = renderToStaticMarkup;
|
|
63
51
|
this.reactMountReady = CallbackQueue.getPooled(null);
|
|
64
|
-
this.putListenerQueue = ReactPutListenerQueue.getPooled();
|
|
65
52
|
}
|
|
66
53
|
|
|
67
54
|
var Mixin = {
|
|
@@ -71,41 +58,29 @@ var Mixin = {
|
|
|
71
58
|
* @final
|
|
72
59
|
* @return {array} Empty list of operation wrap proceedures.
|
|
73
60
|
*/
|
|
74
|
-
getTransactionWrappers: function() {
|
|
61
|
+
getTransactionWrappers: function () {
|
|
75
62
|
return TRANSACTION_WRAPPERS;
|
|
76
63
|
},
|
|
77
64
|
|
|
78
65
|
/**
|
|
79
66
|
* @return {object} The queue to collect `onDOMReady` callbacks with.
|
|
80
67
|
*/
|
|
81
|
-
getReactMountReady: function() {
|
|
68
|
+
getReactMountReady: function () {
|
|
82
69
|
return this.reactMountReady;
|
|
83
70
|
},
|
|
84
71
|
|
|
85
|
-
getPutListenerQueue: function() {
|
|
86
|
-
return this.putListenerQueue;
|
|
87
|
-
},
|
|
88
|
-
|
|
89
72
|
/**
|
|
90
73
|
* `PooledClass` looks for this, and will invoke this before allowing this
|
|
91
74
|
* instance to be resused.
|
|
92
75
|
*/
|
|
93
|
-
destructor: function() {
|
|
76
|
+
destructor: function () {
|
|
94
77
|
CallbackQueue.release(this.reactMountReady);
|
|
95
78
|
this.reactMountReady = null;
|
|
96
|
-
|
|
97
|
-
ReactPutListenerQueue.release(this.putListenerQueue);
|
|
98
|
-
this.putListenerQueue = null;
|
|
99
79
|
}
|
|
100
80
|
};
|
|
101
81
|
|
|
102
|
-
|
|
103
|
-
assign(
|
|
104
|
-
ReactServerRenderingTransaction.prototype,
|
|
105
|
-
Transaction.Mixin,
|
|
106
|
-
Mixin
|
|
107
|
-
);
|
|
82
|
+
assign(ReactServerRenderingTransaction.prototype, Transaction.Mixin, Mixin);
|
|
108
83
|
|
|
109
84
|
PooledClass.addPoolingTo(ReactServerRenderingTransaction);
|
|
110
85
|
|
|
111
|
-
module.exports = ReactServerRenderingTransaction;
|
|
86
|
+
module.exports = ReactServerRenderingTransaction;
|
package/lib/ReactStateSetters.js
CHANGED
|
@@ -22,8 +22,8 @@ var ReactStateSetters = {
|
|
|
22
22
|
* @return {function} callback that when invoked uses funcReturningState to
|
|
23
23
|
* determined the object literal to setState.
|
|
24
24
|
*/
|
|
25
|
-
createStateSetter: function(component, funcReturningState) {
|
|
26
|
-
return function(a, b, c, d, e, f) {
|
|
25
|
+
createStateSetter: function (component, funcReturningState) {
|
|
26
|
+
return function (a, b, c, d, e, f) {
|
|
27
27
|
var partialState = funcReturningState.call(component, a, b, c, d, e, f);
|
|
28
28
|
if (partialState) {
|
|
29
29
|
component.setState(partialState);
|
|
@@ -42,7 +42,7 @@ var ReactStateSetters = {
|
|
|
42
42
|
* @return {function} callback of 1 argument which calls setState() with
|
|
43
43
|
* the provided keyName and callback argument.
|
|
44
44
|
*/
|
|
45
|
-
createStateKeySetter: function(component, key) {
|
|
45
|
+
createStateKeySetter: function (component, key) {
|
|
46
46
|
// Memoize the setters.
|
|
47
47
|
var cache = component.__keySetters || (component.__keySetters = {});
|
|
48
48
|
return cache[key] || (cache[key] = createStateKeySetter(component, key));
|
|
@@ -77,7 +77,7 @@ ReactStateSetters.Mixin = {
|
|
|
77
77
|
* @return {function} callback that when invoked uses funcReturningState to
|
|
78
78
|
* determined the object literal to setState.
|
|
79
79
|
*/
|
|
80
|
-
createStateSetter: function(funcReturningState) {
|
|
80
|
+
createStateSetter: function (funcReturningState) {
|
|
81
81
|
return ReactStateSetters.createStateSetter(this, funcReturningState);
|
|
82
82
|
},
|
|
83
83
|
|
|
@@ -96,9 +96,9 @@ ReactStateSetters.Mixin = {
|
|
|
96
96
|
* @return {function} callback of 1 argument which calls setState() with
|
|
97
97
|
* the provided keyName and callback argument.
|
|
98
98
|
*/
|
|
99
|
-
createStateKeySetter: function(key) {
|
|
99
|
+
createStateKeySetter: function (key) {
|
|
100
100
|
return ReactStateSetters.createStateKeySetter(this, key);
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
-
module.exports = ReactStateSetters;
|
|
104
|
+
module.exports = ReactStateSetters;
|
package/lib/ReactTestUtils.js
CHANGED
|
@@ -26,6 +26,8 @@ var ReactUpdates = require("./ReactUpdates");
|
|
|
26
26
|
var SyntheticEvent = require("./SyntheticEvent");
|
|
27
27
|
|
|
28
28
|
var assign = require("./Object.assign");
|
|
29
|
+
var emptyObject = require("./emptyObject");
|
|
30
|
+
var findDOMNode = require("./findDOMNode");
|
|
29
31
|
|
|
30
32
|
var topLevelTypes = EventConstants.topLevelTypes;
|
|
31
33
|
|
|
@@ -41,7 +43,7 @@ function Event(suffix) {}
|
|
|
41
43
|
* @lends ReactTestUtils
|
|
42
44
|
*/
|
|
43
45
|
var ReactTestUtils = {
|
|
44
|
-
renderIntoDocument: function(instance) {
|
|
46
|
+
renderIntoDocument: function (instance) {
|
|
45
47
|
var div = document.createElement('div');
|
|
46
48
|
// None of our tests actually require attaching the container to the
|
|
47
49
|
// DOM, and doing so creates a mess that we rely on test isolation to
|
|
@@ -51,58 +53,47 @@ var ReactTestUtils = {
|
|
|
51
53
|
return React.render(instance, div);
|
|
52
54
|
},
|
|
53
55
|
|
|
54
|
-
isElement: function(element) {
|
|
56
|
+
isElement: function (element) {
|
|
55
57
|
return ReactElement.isValidElement(element);
|
|
56
58
|
},
|
|
57
59
|
|
|
58
|
-
isElementOfType: function(inst, convenienceConstructor) {
|
|
59
|
-
return (
|
|
60
|
-
ReactElement.isValidElement(inst) &&
|
|
61
|
-
inst.type === convenienceConstructor
|
|
62
|
-
);
|
|
60
|
+
isElementOfType: function (inst, convenienceConstructor) {
|
|
61
|
+
return ReactElement.isValidElement(inst) && inst.type === convenienceConstructor;
|
|
63
62
|
},
|
|
64
63
|
|
|
65
|
-
isDOMComponent: function(inst) {
|
|
64
|
+
isDOMComponent: function (inst) {
|
|
66
65
|
// TODO: Fix this heuristic. It's just here because composites can currently
|
|
67
66
|
// pretend to be DOM components.
|
|
68
67
|
return !!(inst && inst.tagName && inst.getDOMNode);
|
|
69
68
|
},
|
|
70
69
|
|
|
71
|
-
isDOMComponentElement: function(inst) {
|
|
72
|
-
return !!(inst &&
|
|
73
|
-
ReactElement.isValidElement(inst) &&
|
|
74
|
-
!!inst.tagName);
|
|
70
|
+
isDOMComponentElement: function (inst) {
|
|
71
|
+
return !!(inst && ReactElement.isValidElement(inst) && !!inst.tagName);
|
|
75
72
|
},
|
|
76
73
|
|
|
77
|
-
isCompositeComponent: function(inst) {
|
|
78
|
-
return typeof inst.render === 'function' &&
|
|
79
|
-
typeof inst.setState === 'function';
|
|
74
|
+
isCompositeComponent: function (inst) {
|
|
75
|
+
return typeof inst.render === 'function' && typeof inst.setState === 'function';
|
|
80
76
|
},
|
|
81
77
|
|
|
82
|
-
isCompositeComponentWithType: function(inst, type) {
|
|
83
|
-
return !!(ReactTestUtils.isCompositeComponent(inst) &&
|
|
84
|
-
(inst.constructor === type));
|
|
78
|
+
isCompositeComponentWithType: function (inst, type) {
|
|
79
|
+
return !!(ReactTestUtils.isCompositeComponent(inst) && inst.constructor === type);
|
|
85
80
|
},
|
|
86
81
|
|
|
87
|
-
isCompositeComponentElement: function(inst) {
|
|
82
|
+
isCompositeComponentElement: function (inst) {
|
|
88
83
|
if (!ReactElement.isValidElement(inst)) {
|
|
89
84
|
return false;
|
|
90
85
|
}
|
|
91
86
|
// We check the prototype of the type that will get mounted, not the
|
|
92
87
|
// instance itself. This is a future proof way of duck typing.
|
|
93
88
|
var prototype = inst.type.prototype;
|
|
94
|
-
return
|
|
95
|
-
typeof prototype.render === 'function' &&
|
|
96
|
-
typeof prototype.setState === 'function'
|
|
97
|
-
);
|
|
89
|
+
return typeof prototype.render === 'function' && typeof prototype.setState === 'function';
|
|
98
90
|
},
|
|
99
91
|
|
|
100
|
-
isCompositeComponentElementWithType: function(inst, type) {
|
|
101
|
-
return !!(ReactTestUtils.isCompositeComponentElement(inst) &&
|
|
102
|
-
(inst.constructor === type));
|
|
92
|
+
isCompositeComponentElementWithType: function (inst, type) {
|
|
93
|
+
return !!(ReactTestUtils.isCompositeComponentElement(inst) && inst.constructor === type);
|
|
103
94
|
},
|
|
104
95
|
|
|
105
|
-
getRenderedChildOfCompositeComponent: function(inst) {
|
|
96
|
+
getRenderedChildOfCompositeComponent: function (inst) {
|
|
106
97
|
if (!ReactTestUtils.isCompositeComponent(inst)) {
|
|
107
98
|
return null;
|
|
108
99
|
}
|
|
@@ -110,16 +101,14 @@ var ReactTestUtils = {
|
|
|
110
101
|
return internalInstance._renderedComponent.getPublicInstance();
|
|
111
102
|
},
|
|
112
103
|
|
|
113
|
-
findAllInRenderedTree: function(inst, test) {
|
|
104
|
+
findAllInRenderedTree: function (inst, test) {
|
|
114
105
|
if (!inst) {
|
|
115
106
|
return [];
|
|
116
107
|
}
|
|
117
108
|
var ret = test(inst) ? [inst] : [];
|
|
118
109
|
if (ReactTestUtils.isDOMComponent(inst)) {
|
|
119
110
|
var internalInstance = ReactInstanceMap.get(inst);
|
|
120
|
-
var renderedChildren = internalInstance
|
|
121
|
-
._renderedComponent
|
|
122
|
-
._renderedChildren;
|
|
111
|
+
var renderedChildren = internalInstance._renderedComponent._renderedChildren;
|
|
123
112
|
var key;
|
|
124
113
|
for (key in renderedChildren) {
|
|
125
114
|
if (!renderedChildren.hasOwnProperty(key)) {
|
|
@@ -128,20 +117,10 @@ var ReactTestUtils = {
|
|
|
128
117
|
if (!renderedChildren[key].getPublicInstance) {
|
|
129
118
|
continue;
|
|
130
119
|
}
|
|
131
|
-
ret = ret.concat(
|
|
132
|
-
ReactTestUtils.findAllInRenderedTree(
|
|
133
|
-
renderedChildren[key].getPublicInstance(),
|
|
134
|
-
test
|
|
135
|
-
)
|
|
136
|
-
);
|
|
120
|
+
ret = ret.concat(ReactTestUtils.findAllInRenderedTree(renderedChildren[key].getPublicInstance(), test));
|
|
137
121
|
}
|
|
138
122
|
} else if (ReactTestUtils.isCompositeComponent(inst)) {
|
|
139
|
-
ret = ret.concat(
|
|
140
|
-
ReactTestUtils.findAllInRenderedTree(
|
|
141
|
-
ReactTestUtils.getRenderedChildOfCompositeComponent(inst),
|
|
142
|
-
test
|
|
143
|
-
)
|
|
144
|
-
);
|
|
123
|
+
ret = ret.concat(ReactTestUtils.findAllInRenderedTree(ReactTestUtils.getRenderedChildOfCompositeComponent(inst), test));
|
|
145
124
|
}
|
|
146
125
|
return ret;
|
|
147
126
|
},
|
|
@@ -151,12 +130,10 @@ var ReactTestUtils = {
|
|
|
151
130
|
* components with the class name matching `className`.
|
|
152
131
|
* @return an array of all the matches.
|
|
153
132
|
*/
|
|
154
|
-
scryRenderedDOMComponentsWithClass: function(root, className) {
|
|
155
|
-
return ReactTestUtils.findAllInRenderedTree(root, function(inst) {
|
|
133
|
+
scryRenderedDOMComponentsWithClass: function (root, className) {
|
|
134
|
+
return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
|
156
135
|
var instClassName = inst.props.className;
|
|
157
|
-
return ReactTestUtils.isDOMComponent(inst) && (
|
|
158
|
-
(instClassName && (' ' + instClassName + ' ').indexOf(' ' + className + ' ') !== -1)
|
|
159
|
-
);
|
|
136
|
+
return ReactTestUtils.isDOMComponent(inst) && (instClassName && (' ' + instClassName + ' ').indexOf(' ' + className + ' ') !== -1);
|
|
160
137
|
});
|
|
161
138
|
},
|
|
162
139
|
|
|
@@ -166,27 +143,22 @@ var ReactTestUtils = {
|
|
|
166
143
|
* number of matches besides one.
|
|
167
144
|
* @return {!ReactDOMComponent} The one match.
|
|
168
145
|
*/
|
|
169
|
-
findRenderedDOMComponentWithClass: function(root, className) {
|
|
170
|
-
var all =
|
|
171
|
-
ReactTestUtils.scryRenderedDOMComponentsWithClass(root, className);
|
|
146
|
+
findRenderedDOMComponentWithClass: function (root, className) {
|
|
147
|
+
var all = ReactTestUtils.scryRenderedDOMComponentsWithClass(root, className);
|
|
172
148
|
if (all.length !== 1) {
|
|
173
|
-
throw new Error('Did not find exactly one match ' +
|
|
174
|
-
'(found: ' + all.length + ') for class:' + className
|
|
175
|
-
);
|
|
149
|
+
throw new Error('Did not find exactly one match ' + '(found: ' + all.length + ') for class:' + className);
|
|
176
150
|
}
|
|
177
151
|
return all[0];
|
|
178
152
|
},
|
|
179
153
|
|
|
180
|
-
|
|
181
154
|
/**
|
|
182
155
|
* Finds all instance of components in the rendered tree that are DOM
|
|
183
156
|
* components with the tag name matching `tagName`.
|
|
184
157
|
* @return an array of all the matches.
|
|
185
158
|
*/
|
|
186
|
-
scryRenderedDOMComponentsWithTag: function(root, tagName) {
|
|
187
|
-
return ReactTestUtils.findAllInRenderedTree(root, function(inst) {
|
|
188
|
-
return ReactTestUtils.isDOMComponent(inst) &&
|
|
189
|
-
inst.tagName === tagName.toUpperCase();
|
|
159
|
+
scryRenderedDOMComponentsWithTag: function (root, tagName) {
|
|
160
|
+
return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
|
161
|
+
return ReactTestUtils.isDOMComponent(inst) && inst.tagName === tagName.toUpperCase();
|
|
190
162
|
});
|
|
191
163
|
},
|
|
192
164
|
|
|
@@ -196,7 +168,7 @@ var ReactTestUtils = {
|
|
|
196
168
|
* number of matches besides one.
|
|
197
169
|
* @return {!ReactDOMComponent} The one match.
|
|
198
170
|
*/
|
|
199
|
-
findRenderedDOMComponentWithTag: function(root, tagName) {
|
|
171
|
+
findRenderedDOMComponentWithTag: function (root, tagName) {
|
|
200
172
|
var all = ReactTestUtils.scryRenderedDOMComponentsWithTag(root, tagName);
|
|
201
173
|
if (all.length !== 1) {
|
|
202
174
|
throw new Error('Did not find exactly one match for tag:' + tagName);
|
|
@@ -204,17 +176,13 @@ var ReactTestUtils = {
|
|
|
204
176
|
return all[0];
|
|
205
177
|
},
|
|
206
178
|
|
|
207
|
-
|
|
208
179
|
/**
|
|
209
180
|
* Finds all instances of components with type equal to `componentType`.
|
|
210
181
|
* @return an array of all the matches.
|
|
211
182
|
*/
|
|
212
|
-
scryRenderedComponentsWithType: function(root, componentType) {
|
|
213
|
-
return ReactTestUtils.findAllInRenderedTree(root, function(inst) {
|
|
214
|
-
return ReactTestUtils.isCompositeComponentWithType(
|
|
215
|
-
inst,
|
|
216
|
-
componentType
|
|
217
|
-
);
|
|
183
|
+
scryRenderedComponentsWithType: function (root, componentType) {
|
|
184
|
+
return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
|
185
|
+
return ReactTestUtils.isCompositeComponentWithType(inst, componentType);
|
|
218
186
|
});
|
|
219
187
|
},
|
|
220
188
|
|
|
@@ -224,15 +192,10 @@ var ReactTestUtils = {
|
|
|
224
192
|
* number of matches besides one.
|
|
225
193
|
* @return {!ReactComponent} The one match.
|
|
226
194
|
*/
|
|
227
|
-
findRenderedComponentWithType: function(root, componentType) {
|
|
228
|
-
var all = ReactTestUtils.scryRenderedComponentsWithType(
|
|
229
|
-
root,
|
|
230
|
-
componentType
|
|
231
|
-
);
|
|
195
|
+
findRenderedComponentWithType: function (root, componentType) {
|
|
196
|
+
var all = ReactTestUtils.scryRenderedComponentsWithType(root, componentType);
|
|
232
197
|
if (all.length !== 1) {
|
|
233
|
-
throw new Error(
|
|
234
|
-
'Did not find exactly one match for componentType:' + componentType
|
|
235
|
-
);
|
|
198
|
+
throw new Error('Did not find exactly one match for componentType:' + componentType);
|
|
236
199
|
}
|
|
237
200
|
return all[0];
|
|
238
201
|
},
|
|
@@ -250,15 +213,11 @@ var ReactTestUtils = {
|
|
|
250
213
|
* module.mockTagName if provided)
|
|
251
214
|
* @return {object} the ReactTestUtils object (for chaining)
|
|
252
215
|
*/
|
|
253
|
-
mockComponent: function(module, mockTagName) {
|
|
254
|
-
mockTagName = mockTagName || module.mockTagName ||
|
|
255
|
-
|
|
256
|
-
module.prototype.render.mockImplementation(function() {
|
|
257
|
-
return React.createElement(
|
|
258
|
-
mockTagName,
|
|
259
|
-
null,
|
|
260
|
-
this.props.children
|
|
261
|
-
);
|
|
216
|
+
mockComponent: function (module, mockTagName) {
|
|
217
|
+
mockTagName = mockTagName || module.mockTagName || 'div';
|
|
218
|
+
|
|
219
|
+
module.prototype.render.mockImplementation(function () {
|
|
220
|
+
return React.createElement(mockTagName, null, this.props.children);
|
|
262
221
|
});
|
|
263
222
|
|
|
264
223
|
return this;
|
|
@@ -271,12 +230,9 @@ var ReactTestUtils = {
|
|
|
271
230
|
* @param {!Element} node The dom to simulate an event occurring on.
|
|
272
231
|
* @param {?Event} fakeNativeEvent Fake native event to use in SyntheticEvent.
|
|
273
232
|
*/
|
|
274
|
-
simulateNativeEventOnNode: function(topLevelType, node, fakeNativeEvent) {
|
|
233
|
+
simulateNativeEventOnNode: function (topLevelType, node, fakeNativeEvent) {
|
|
275
234
|
fakeNativeEvent.target = node;
|
|
276
|
-
ReactBrowserEventEmitter.ReactEventListener.dispatchEvent(
|
|
277
|
-
topLevelType,
|
|
278
|
-
fakeNativeEvent
|
|
279
|
-
);
|
|
235
|
+
ReactBrowserEventEmitter.ReactEventListener.dispatchEvent(topLevelType, fakeNativeEvent);
|
|
280
236
|
},
|
|
281
237
|
|
|
282
238
|
/**
|
|
@@ -286,26 +242,17 @@ var ReactTestUtils = {
|
|
|
286
242
|
* @param comp {!ReactDOMComponent}
|
|
287
243
|
* @param {?Event} fakeNativeEvent Fake native event to use in SyntheticEvent.
|
|
288
244
|
*/
|
|
289
|
-
simulateNativeEventOnDOMComponent: function(
|
|
290
|
-
|
|
291
|
-
comp,
|
|
292
|
-
fakeNativeEvent) {
|
|
293
|
-
ReactTestUtils.simulateNativeEventOnNode(
|
|
294
|
-
topLevelType,
|
|
295
|
-
comp.getDOMNode(),
|
|
296
|
-
fakeNativeEvent
|
|
297
|
-
);
|
|
245
|
+
simulateNativeEventOnDOMComponent: function (topLevelType, comp, fakeNativeEvent) {
|
|
246
|
+
ReactTestUtils.simulateNativeEventOnNode(topLevelType, findDOMNode(comp), fakeNativeEvent);
|
|
298
247
|
},
|
|
299
248
|
|
|
300
|
-
nativeTouchData: function(x, y) {
|
|
249
|
+
nativeTouchData: function (x, y) {
|
|
301
250
|
return {
|
|
302
|
-
touches: [
|
|
303
|
-
{pageX: x, pageY: y}
|
|
304
|
-
]
|
|
251
|
+
touches: [{ pageX: x, pageY: y }]
|
|
305
252
|
};
|
|
306
253
|
},
|
|
307
254
|
|
|
308
|
-
createRenderer: function() {
|
|
255
|
+
createRenderer: function () {
|
|
309
256
|
return new ReactShallowRenderer();
|
|
310
257
|
},
|
|
311
258
|
|
|
@@ -316,69 +263,57 @@ var ReactTestUtils = {
|
|
|
316
263
|
/**
|
|
317
264
|
* @class ReactShallowRenderer
|
|
318
265
|
*/
|
|
319
|
-
var ReactShallowRenderer = function() {
|
|
266
|
+
var ReactShallowRenderer = function () {
|
|
320
267
|
this._instance = null;
|
|
321
268
|
};
|
|
322
269
|
|
|
323
|
-
ReactShallowRenderer.prototype.getRenderOutput = function() {
|
|
324
|
-
return
|
|
325
|
-
(this._instance && this._instance._renderedComponent &&
|
|
326
|
-
this._instance._renderedComponent._renderedOutput)
|
|
327
|
-
|| null
|
|
328
|
-
);
|
|
270
|
+
ReactShallowRenderer.prototype.getRenderOutput = function () {
|
|
271
|
+
return this._instance && this._instance._renderedComponent && this._instance._renderedComponent._renderedOutput || null;
|
|
329
272
|
};
|
|
330
273
|
|
|
331
|
-
var NoopInternalComponent = function(element) {
|
|
274
|
+
var NoopInternalComponent = function (element) {
|
|
332
275
|
this._renderedOutput = element;
|
|
333
|
-
this._currentElement = element === null || element === false ?
|
|
334
|
-
ReactEmptyComponent.emptyElement :
|
|
335
|
-
element;
|
|
276
|
+
this._currentElement = element === null || element === false ? ReactEmptyComponent.emptyElement : element;
|
|
336
277
|
};
|
|
337
278
|
|
|
338
279
|
NoopInternalComponent.prototype = {
|
|
339
280
|
|
|
340
|
-
mountComponent: function() {
|
|
341
|
-
},
|
|
281
|
+
mountComponent: function () {},
|
|
342
282
|
|
|
343
|
-
receiveComponent: function(element) {
|
|
283
|
+
receiveComponent: function (element) {
|
|
344
284
|
this._renderedOutput = element;
|
|
345
|
-
this._currentElement = element === null || element === false ?
|
|
346
|
-
ReactEmptyComponent.emptyElement :
|
|
347
|
-
element;
|
|
285
|
+
this._currentElement = element === null || element === false ? ReactEmptyComponent.emptyElement : element;
|
|
348
286
|
},
|
|
349
287
|
|
|
350
|
-
unmountComponent: function() {
|
|
351
|
-
}
|
|
288
|
+
unmountComponent: function () {}
|
|
352
289
|
|
|
353
290
|
};
|
|
354
291
|
|
|
355
|
-
var ShallowComponentWrapper = function() {
|
|
356
|
-
assign(
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
_renderValidatedComponent:
|
|
364
|
-
ReactCompositeComponent.Mixin.
|
|
365
|
-
_renderValidatedComponentWithoutOwnerOrContext
|
|
366
|
-
}
|
|
367
|
-
);
|
|
292
|
+
var ShallowComponentWrapper = function () {};
|
|
293
|
+
assign(ShallowComponentWrapper.prototype, ReactCompositeComponent.Mixin, {
|
|
294
|
+
_instantiateReactComponent: function (element) {
|
|
295
|
+
return new NoopInternalComponent(element);
|
|
296
|
+
},
|
|
297
|
+
_replaceNodeWithMarkupByID: function () {},
|
|
298
|
+
_renderValidatedComponent: ReactCompositeComponent.Mixin._renderValidatedComponentWithoutOwnerOrContext
|
|
299
|
+
});
|
|
368
300
|
|
|
369
|
-
ReactShallowRenderer.prototype.render = function(element, context) {
|
|
301
|
+
ReactShallowRenderer.prototype.render = function (element, context) {
|
|
302
|
+
if (!context) {
|
|
303
|
+
context = emptyObject;
|
|
304
|
+
}
|
|
370
305
|
var transaction = ReactUpdates.ReactReconcileTransaction.getPooled();
|
|
371
306
|
this._render(element, transaction, context);
|
|
372
307
|
ReactUpdates.ReactReconcileTransaction.release(transaction);
|
|
373
308
|
};
|
|
374
309
|
|
|
375
|
-
ReactShallowRenderer.prototype.unmount = function() {
|
|
310
|
+
ReactShallowRenderer.prototype.unmount = function () {
|
|
376
311
|
if (this._instance) {
|
|
377
312
|
this._instance.unmountComponent();
|
|
378
313
|
}
|
|
379
314
|
};
|
|
380
315
|
|
|
381
|
-
ReactShallowRenderer.prototype._render = function(element, transaction, context) {
|
|
316
|
+
ReactShallowRenderer.prototype._render = function (element, transaction, context) {
|
|
382
317
|
if (!this._instance) {
|
|
383
318
|
var rootID = ReactInstanceHandles.createReactRootID();
|
|
384
319
|
var instance = new ShallowComponentWrapper(element.type);
|
|
@@ -401,27 +336,30 @@ ReactShallowRenderer.prototype._render = function(element, transaction, context)
|
|
|
401
336
|
* - ... (All keys from event plugin `eventTypes` objects)
|
|
402
337
|
*/
|
|
403
338
|
function makeSimulator(eventType) {
|
|
404
|
-
return function(domComponentOrNode, eventData) {
|
|
339
|
+
return function (domComponentOrNode, eventData) {
|
|
405
340
|
var node;
|
|
406
341
|
if (ReactTestUtils.isDOMComponent(domComponentOrNode)) {
|
|
407
|
-
node = domComponentOrNode
|
|
342
|
+
node = findDOMNode(domComponentOrNode);
|
|
408
343
|
} else if (domComponentOrNode.tagName) {
|
|
409
344
|
node = domComponentOrNode;
|
|
410
345
|
}
|
|
411
346
|
|
|
347
|
+
var dispatchConfig = ReactBrowserEventEmitter.eventNameDispatchConfigs[eventType];
|
|
348
|
+
|
|
412
349
|
var fakeNativeEvent = new Event();
|
|
413
350
|
fakeNativeEvent.target = node;
|
|
414
351
|
// We don't use SyntheticEvent.getPooled in order to not have to worry about
|
|
415
352
|
// properly destroying any properties assigned from `eventData` upon release
|
|
416
|
-
var event = new SyntheticEvent(
|
|
417
|
-
ReactBrowserEventEmitter.eventNameDispatchConfigs[eventType],
|
|
418
|
-
ReactMount.getID(node),
|
|
419
|
-
fakeNativeEvent
|
|
420
|
-
);
|
|
353
|
+
var event = new SyntheticEvent(dispatchConfig, ReactMount.getID(node), fakeNativeEvent);
|
|
421
354
|
assign(event, eventData);
|
|
422
|
-
EventPropagators.accumulateTwoPhaseDispatches(event);
|
|
423
355
|
|
|
424
|
-
|
|
356
|
+
if (dispatchConfig.phasedRegistrationNames) {
|
|
357
|
+
EventPropagators.accumulateTwoPhaseDispatches(event);
|
|
358
|
+
} else {
|
|
359
|
+
EventPropagators.accumulateDirectDispatches(event);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
ReactUpdates.batchedUpdates(function () {
|
|
425
363
|
EventPluginHub.enqueueEvents(event);
|
|
426
364
|
EventPluginHub.processEventQueue();
|
|
427
365
|
});
|
|
@@ -443,12 +381,12 @@ function buildSimulators() {
|
|
|
443
381
|
|
|
444
382
|
// Rebuild ReactTestUtils.Simulate whenever event plugins are injected
|
|
445
383
|
var oldInjectEventPluginOrder = EventPluginHub.injection.injectEventPluginOrder;
|
|
446
|
-
EventPluginHub.injection.injectEventPluginOrder = function() {
|
|
384
|
+
EventPluginHub.injection.injectEventPluginOrder = function () {
|
|
447
385
|
oldInjectEventPluginOrder.apply(this, arguments);
|
|
448
386
|
buildSimulators();
|
|
449
387
|
};
|
|
450
388
|
var oldInjectEventPlugins = EventPluginHub.injection.injectEventPluginsByName;
|
|
451
|
-
EventPluginHub.injection.injectEventPluginsByName = function() {
|
|
389
|
+
EventPluginHub.injection.injectEventPluginsByName = function () {
|
|
452
390
|
oldInjectEventPlugins.apply(this, arguments);
|
|
453
391
|
buildSimulators();
|
|
454
392
|
};
|
|
@@ -472,22 +410,14 @@ buildSimulators();
|
|
|
472
410
|
*/
|
|
473
411
|
|
|
474
412
|
function makeNativeSimulator(eventType) {
|
|
475
|
-
return function(domComponentOrNode, nativeEventData) {
|
|
413
|
+
return function (domComponentOrNode, nativeEventData) {
|
|
476
414
|
var fakeNativeEvent = new Event(eventType);
|
|
477
415
|
assign(fakeNativeEvent, nativeEventData);
|
|
478
416
|
if (ReactTestUtils.isDOMComponent(domComponentOrNode)) {
|
|
479
|
-
ReactTestUtils.simulateNativeEventOnDOMComponent(
|
|
480
|
-
eventType,
|
|
481
|
-
domComponentOrNode,
|
|
482
|
-
fakeNativeEvent
|
|
483
|
-
);
|
|
417
|
+
ReactTestUtils.simulateNativeEventOnDOMComponent(eventType, domComponentOrNode, fakeNativeEvent);
|
|
484
418
|
} else if (!!domComponentOrNode.tagName) {
|
|
485
419
|
// Will allow on actual dom nodes.
|
|
486
|
-
ReactTestUtils.simulateNativeEventOnNode(
|
|
487
|
-
eventType,
|
|
488
|
-
domComponentOrNode,
|
|
489
|
-
fakeNativeEvent
|
|
490
|
-
);
|
|
420
|
+
ReactTestUtils.simulateNativeEventOnNode(eventType, domComponentOrNode, fakeNativeEvent);
|
|
491
421
|
}
|
|
492
422
|
};
|
|
493
423
|
}
|
|
@@ -495,14 +425,12 @@ function makeNativeSimulator(eventType) {
|
|
|
495
425
|
var eventType;
|
|
496
426
|
for (eventType in topLevelTypes) {
|
|
497
427
|
// Event type is stored as 'topClick' - we transform that to 'click'
|
|
498
|
-
var convenienceName = eventType.indexOf('top') === 0 ?
|
|
499
|
-
eventType.charAt(3).toLowerCase() + eventType.substr(4) : eventType;
|
|
428
|
+
var convenienceName = eventType.indexOf('top') === 0 ? eventType.charAt(3).toLowerCase() + eventType.substr(4) : eventType;
|
|
500
429
|
/**
|
|
501
430
|
* @param {!Element || ReactDOMComponent} domComponentOrNode
|
|
502
431
|
* @param {?Event} nativeEventData Fake native event to use in SyntheticEvent.
|
|
503
432
|
*/
|
|
504
|
-
ReactTestUtils.SimulateNative[convenienceName] =
|
|
505
|
-
makeNativeSimulator(eventType);
|
|
433
|
+
ReactTestUtils.SimulateNative[convenienceName] = makeNativeSimulator(eventType);
|
|
506
434
|
}
|
|
507
435
|
|
|
508
|
-
module.exports = ReactTestUtils;
|
|
436
|
+
module.exports = ReactTestUtils;
|