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
package/lib/ReactComponent.js
CHANGED
|
@@ -49,22 +49,10 @@ function ReactComponent(props, context) {
|
|
|
49
49
|
* @final
|
|
50
50
|
* @protected
|
|
51
51
|
*/
|
|
52
|
-
ReactComponent.prototype.setState = function(partialState, callback) {
|
|
53
|
-
(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
partialState == null,
|
|
57
|
-
'setState(...): takes an object of state variables to update or a ' +
|
|
58
|
-
'function which returns an object of state variables.'
|
|
59
|
-
) : invariant(typeof partialState === 'object' ||
|
|
60
|
-
typeof partialState === 'function' ||
|
|
61
|
-
partialState == null));
|
|
62
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
63
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
64
|
-
partialState != null,
|
|
65
|
-
'setState(...): You passed an undefined or null state object; ' +
|
|
66
|
-
'instead, use forceUpdate().'
|
|
67
|
-
) : null);
|
|
52
|
+
ReactComponent.prototype.setState = function (partialState, callback) {
|
|
53
|
+
!(typeof partialState === 'object' || typeof partialState === 'function' || partialState == null) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'setState(...): takes an object of state variables to update or a ' + 'function which returns an object of state variables.') : invariant(false) : undefined;
|
|
54
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
55
|
+
'production' !== process.env.NODE_ENV ? warning(partialState != null, 'setState(...): You passed an undefined or null state object; ' + 'instead, use forceUpdate().') : undefined;
|
|
68
56
|
}
|
|
69
57
|
ReactUpdateQueue.enqueueSetState(this, partialState);
|
|
70
58
|
if (callback) {
|
|
@@ -86,7 +74,7 @@ ReactComponent.prototype.setState = function(partialState, callback) {
|
|
|
86
74
|
* @final
|
|
87
75
|
* @protected
|
|
88
76
|
*/
|
|
89
|
-
ReactComponent.prototype.forceUpdate = function(callback) {
|
|
77
|
+
ReactComponent.prototype.forceUpdate = function (callback) {
|
|
90
78
|
ReactUpdateQueue.enqueueForceUpdate(this);
|
|
91
79
|
if (callback) {
|
|
92
80
|
ReactUpdateQueue.enqueueCallback(this, callback);
|
|
@@ -98,29 +86,23 @@ ReactComponent.prototype.forceUpdate = function(callback) {
|
|
|
98
86
|
* we would like to deprecate them, we're not going to move them over to this
|
|
99
87
|
* modern base class. Instead, we define a getter that warns if it's accessed.
|
|
100
88
|
*/
|
|
101
|
-
if (
|
|
89
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
102
90
|
var deprecatedAPIs = {
|
|
103
|
-
getDOMNode: 'getDOMNode',
|
|
104
|
-
isMounted: 'isMounted',
|
|
105
|
-
replaceProps: 'replaceProps',
|
|
106
|
-
replaceState: 'replaceState',
|
|
107
|
-
setProps: 'setProps'
|
|
91
|
+
getDOMNode: ['getDOMNode', 'Use React.findDOMNode(component) instead.'],
|
|
92
|
+
isMounted: ['isMounted', 'Instead, make sure to clean up subscriptions and pending requests in ' + 'componentWillUnmount to prevent memory leaks.'],
|
|
93
|
+
replaceProps: ['replaceProps', 'Instead, call React.render again at the top level.'],
|
|
94
|
+
replaceState: ['replaceState', 'Refactor your code to use setState instead (see ' + 'https://github.com/facebook/react/issues/3236).'],
|
|
95
|
+
setProps: ['setProps', 'Instead, call React.render again at the top level.']
|
|
108
96
|
};
|
|
109
|
-
var defineDeprecationWarning = function(methodName,
|
|
97
|
+
var defineDeprecationWarning = function (methodName, info) {
|
|
110
98
|
try {
|
|
111
99
|
Object.defineProperty(ReactComponent.prototype, methodName, {
|
|
112
|
-
get: function() {
|
|
113
|
-
|
|
114
|
-
false,
|
|
115
|
-
'%s(...) is deprecated in plain JavaScript React classes.',
|
|
116
|
-
displayName
|
|
117
|
-
) : null);
|
|
100
|
+
get: function () {
|
|
101
|
+
'production' !== process.env.NODE_ENV ? warning(false, '%s(...) is deprecated in plain JavaScript React classes. %s', info[0], info[1]) : undefined;
|
|
118
102
|
return undefined;
|
|
119
103
|
}
|
|
120
104
|
});
|
|
121
|
-
} catch (x) {
|
|
122
|
-
// IE will fail on defineProperty (es5-shim/sham too)
|
|
123
|
-
}
|
|
105
|
+
} catch (x) {}
|
|
124
106
|
};
|
|
125
107
|
for (var fnName in deprecatedAPIs) {
|
|
126
108
|
if (deprecatedAPIs.hasOwnProperty(fnName)) {
|
|
@@ -130,3 +112,5 @@ if ("production" !== process.env.NODE_ENV) {
|
|
|
130
112
|
}
|
|
131
113
|
|
|
132
114
|
module.exports = ReactComponent;
|
|
115
|
+
|
|
116
|
+
// IE will fail on defineProperty (es5-shim/sham too)
|
|
@@ -9,8 +9,6 @@
|
|
|
9
9
|
* @providesModule ReactComponentBrowserEnvironment
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
/*jslint evil: true */
|
|
13
|
-
|
|
14
12
|
'use strict';
|
|
15
13
|
|
|
16
14
|
var ReactDOMIDOperations = require("./ReactDOMIDOperations");
|
|
@@ -23,11 +21,9 @@ var ReactMount = require("./ReactMount");
|
|
|
23
21
|
*/
|
|
24
22
|
var ReactComponentBrowserEnvironment = {
|
|
25
23
|
|
|
26
|
-
processChildrenUpdates:
|
|
27
|
-
ReactDOMIDOperations.dangerouslyProcessChildrenUpdates,
|
|
24
|
+
processChildrenUpdates: ReactDOMIDOperations.dangerouslyProcessChildrenUpdates,
|
|
28
25
|
|
|
29
|
-
replaceNodeWithMarkupByID:
|
|
30
|
-
ReactDOMIDOperations.dangerouslyReplaceNodeWithMarkupByID,
|
|
26
|
+
replaceNodeWithMarkupByID: ReactDOMIDOperations.dangerouslyReplaceNodeWithMarkupByID,
|
|
31
27
|
|
|
32
28
|
/**
|
|
33
29
|
* If a particular environment requires that some resources be cleaned up,
|
|
@@ -36,10 +32,10 @@ var ReactComponentBrowserEnvironment = {
|
|
|
36
32
|
*
|
|
37
33
|
* @private
|
|
38
34
|
*/
|
|
39
|
-
unmountIDFromEnvironment: function(rootNodeID) {
|
|
35
|
+
unmountIDFromEnvironment: function (rootNodeID) {
|
|
40
36
|
ReactMount.purgeID(rootNodeID);
|
|
41
37
|
}
|
|
42
38
|
|
|
43
39
|
};
|
|
44
40
|
|
|
45
|
-
module.exports = ReactComponentBrowserEnvironment;
|
|
41
|
+
module.exports = ReactComponentBrowserEnvironment;
|
|
@@ -37,21 +37,15 @@ var ReactComponentEnvironment = {
|
|
|
37
37
|
processChildrenUpdates: null,
|
|
38
38
|
|
|
39
39
|
injection: {
|
|
40
|
-
injectEnvironment: function(environment) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
ReactComponentEnvironment.unmountIDFromEnvironment =
|
|
46
|
-
environment.unmountIDFromEnvironment;
|
|
47
|
-
ReactComponentEnvironment.replaceNodeWithMarkupByID =
|
|
48
|
-
environment.replaceNodeWithMarkupByID;
|
|
49
|
-
ReactComponentEnvironment.processChildrenUpdates =
|
|
50
|
-
environment.processChildrenUpdates;
|
|
40
|
+
injectEnvironment: function (environment) {
|
|
41
|
+
!!injected ? 'production' !== process.env.NODE_ENV ? invariant(false, 'ReactCompositeComponent: injectEnvironment() can only be called once.') : invariant(false) : undefined;
|
|
42
|
+
ReactComponentEnvironment.unmountIDFromEnvironment = environment.unmountIDFromEnvironment;
|
|
43
|
+
ReactComponentEnvironment.replaceNodeWithMarkupByID = environment.replaceNodeWithMarkupByID;
|
|
44
|
+
ReactComponentEnvironment.processChildrenUpdates = environment.processChildrenUpdates;
|
|
51
45
|
injected = true;
|
|
52
46
|
}
|
|
53
47
|
}
|
|
54
48
|
|
|
55
49
|
};
|
|
56
50
|
|
|
57
|
-
module.exports = ReactComponentEnvironment;
|
|
51
|
+
module.exports = ReactComponentEnvironment;
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var shallowCompare = require("./shallowCompare");
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* If your React component's render function is "pure", e.g. it will render the
|
|
@@ -38,10 +38,9 @@ var shallowEqual = require("./shallowEqual");
|
|
|
38
38
|
* use `forceUpdate()` when you know deep data structures have changed.
|
|
39
39
|
*/
|
|
40
40
|
var ReactComponentWithPureRenderMixin = {
|
|
41
|
-
shouldComponentUpdate: function(nextProps, nextState) {
|
|
42
|
-
return
|
|
43
|
-
!shallowEqual(this.state, nextState);
|
|
41
|
+
shouldComponentUpdate: function (nextProps, nextState) {
|
|
42
|
+
return shallowCompare(this, nextProps, nextState);
|
|
44
43
|
}
|
|
45
44
|
};
|
|
46
45
|
|
|
47
|
-
module.exports = ReactComponentWithPureRenderMixin;
|
|
46
|
+
module.exports = ReactComponentWithPureRenderMixin;
|
|
@@ -89,7 +89,7 @@ var ReactCompositeComponentMixin = {
|
|
|
89
89
|
* @final
|
|
90
90
|
* @internal
|
|
91
91
|
*/
|
|
92
|
-
construct: function(element) {
|
|
92
|
+
construct: function (element) {
|
|
93
93
|
this._currentElement = element;
|
|
94
94
|
this._rootNodeID = null;
|
|
95
95
|
this._instance = null;
|
|
@@ -119,32 +119,23 @@ var ReactCompositeComponentMixin = {
|
|
|
119
119
|
* @final
|
|
120
120
|
* @internal
|
|
121
121
|
*/
|
|
122
|
-
mountComponent: function(rootID, transaction, context) {
|
|
122
|
+
mountComponent: function (rootID, transaction, context) {
|
|
123
123
|
this._context = context;
|
|
124
124
|
this._mountOrder = nextMountID++;
|
|
125
125
|
this._rootNodeID = rootID;
|
|
126
126
|
|
|
127
127
|
var publicProps = this._processProps(this._currentElement.props);
|
|
128
|
-
var publicContext = this._processContext(
|
|
128
|
+
var publicContext = this._processContext(context);
|
|
129
129
|
|
|
130
|
-
var Component = ReactNativeComponent.getComponentClassForElement(
|
|
131
|
-
this._currentElement
|
|
132
|
-
);
|
|
130
|
+
var Component = ReactNativeComponent.getComponentClassForElement(this._currentElement);
|
|
133
131
|
|
|
134
132
|
// Initialize the public class
|
|
135
133
|
var inst = new Component(publicProps, publicContext);
|
|
136
134
|
|
|
137
|
-
if (
|
|
135
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
138
136
|
// This will throw later in _renderValidatedComponent, but add an early
|
|
139
137
|
// warning now to help debugging
|
|
140
|
-
|
|
141
|
-
inst.render != null,
|
|
142
|
-
'%s(...): No `render` method found on the returned component ' +
|
|
143
|
-
'instance: you may have forgotten to define `render` in your ' +
|
|
144
|
-
'component or you may have accidentally tried to render an element ' +
|
|
145
|
-
'whose type is a function that isn\'t a React component.',
|
|
146
|
-
Component.displayName || Component.name || 'Component'
|
|
147
|
-
) : null);
|
|
138
|
+
'production' !== process.env.NODE_ENV ? warning(inst.render != null, '%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render` in your ' + 'component or you may have accidentally tried to render an element ' + 'whose type is a function that isn\'t a React component.', Component.displayName || Component.name || 'Component') : undefined;
|
|
148
139
|
}
|
|
149
140
|
|
|
150
141
|
// These should be set up in the constructor, but as a convenience for
|
|
@@ -158,61 +149,22 @@ var ReactCompositeComponentMixin = {
|
|
|
158
149
|
// Store a reference from the instance back to the internal representation
|
|
159
150
|
ReactInstanceMap.set(inst, this);
|
|
160
151
|
|
|
161
|
-
if (
|
|
162
|
-
this._warnIfContextsDiffer(this._currentElement._context, context);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
152
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
166
153
|
// Since plain JS classes are defined without any special initialization
|
|
167
154
|
// logic, we can not catch common errors early. Therefore, we have to
|
|
168
155
|
// catch them here, at initialization time, instead.
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
'Did you mean to define a state property instead?',
|
|
175
|
-
this.getName() || 'a component'
|
|
176
|
-
) : null);
|
|
177
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
178
|
-
!inst.getDefaultProps ||
|
|
179
|
-
inst.getDefaultProps.isReactClassApproved,
|
|
180
|
-
'getDefaultProps was defined on %s, a plain JavaScript class. ' +
|
|
181
|
-
'This is only supported for classes created using React.createClass. ' +
|
|
182
|
-
'Use a static property to define defaultProps instead.',
|
|
183
|
-
this.getName() || 'a component'
|
|
184
|
-
) : null);
|
|
185
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
186
|
-
!inst.propTypes,
|
|
187
|
-
'propTypes was defined as an instance property on %s. Use a static ' +
|
|
188
|
-
'property to define propTypes instead.',
|
|
189
|
-
this.getName() || 'a component'
|
|
190
|
-
) : null);
|
|
191
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
192
|
-
!inst.contextTypes,
|
|
193
|
-
'contextTypes was defined as an instance property on %s. Use a ' +
|
|
194
|
-
'static property to define contextTypes instead.',
|
|
195
|
-
this.getName() || 'a component'
|
|
196
|
-
) : null);
|
|
197
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
198
|
-
typeof inst.componentShouldUpdate !== 'function',
|
|
199
|
-
'%s has a method called ' +
|
|
200
|
-
'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' +
|
|
201
|
-
'The name is phrased as a question because the function is ' +
|
|
202
|
-
'expected to return a value.',
|
|
203
|
-
(this.getName() || 'A component')
|
|
204
|
-
) : null);
|
|
156
|
+
'production' !== process.env.NODE_ENV ? warning(!inst.getInitialState || inst.getInitialState.isReactClassApproved, 'getInitialState was defined on %s, a plain JavaScript class. ' + 'This is only supported for classes created using React.createClass. ' + 'Did you mean to define a state property instead?', this.getName() || 'a component') : undefined;
|
|
157
|
+
'production' !== process.env.NODE_ENV ? warning(!inst.getDefaultProps || inst.getDefaultProps.isReactClassApproved, 'getDefaultProps was defined on %s, a plain JavaScript class. ' + 'This is only supported for classes created using React.createClass. ' + 'Use a static property to define defaultProps instead.', this.getName() || 'a component') : undefined;
|
|
158
|
+
'production' !== process.env.NODE_ENV ? warning(!inst.propTypes, 'propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', this.getName() || 'a component') : undefined;
|
|
159
|
+
'production' !== process.env.NODE_ENV ? warning(!inst.contextTypes, 'contextTypes was defined as an instance property on %s. Use a ' + 'static property to define contextTypes instead.', this.getName() || 'a component') : undefined;
|
|
160
|
+
'production' !== process.env.NODE_ENV ? warning(typeof inst.componentShouldUpdate !== 'function', '%s has a method called ' + 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' + 'The name is phrased as a question because the function is ' + 'expected to return a value.', this.getName() || 'A component') : undefined;
|
|
205
161
|
}
|
|
206
162
|
|
|
207
163
|
var initialState = inst.state;
|
|
208
164
|
if (initialState === undefined) {
|
|
209
165
|
inst.state = initialState = null;
|
|
210
166
|
}
|
|
211
|
-
(
|
|
212
|
-
typeof initialState === 'object' && !Array.isArray(initialState),
|
|
213
|
-
'%s.state: must be set to an object or null',
|
|
214
|
-
this.getName() || 'ReactCompositeComponent'
|
|
215
|
-
) : invariant(typeof initialState === 'object' && !Array.isArray(initialState)));
|
|
167
|
+
!(typeof initialState === 'object' && !Array.isArray(initialState)) ? 'production' !== process.env.NODE_ENV ? invariant(false, '%s.state: must be set to an object or null', this.getName() || 'ReactCompositeComponent') : invariant(false) : undefined;
|
|
216
168
|
|
|
217
169
|
this._pendingStateQueue = null;
|
|
218
170
|
this._pendingReplaceState = false;
|
|
@@ -237,17 +189,10 @@ var ReactCompositeComponentMixin = {
|
|
|
237
189
|
ReactLifeCycle.currentlyMountingInstance = previouslyMounting;
|
|
238
190
|
}
|
|
239
191
|
|
|
240
|
-
this._renderedComponent = this._instantiateReactComponent(
|
|
241
|
-
renderedElement,
|
|
242
|
-
this._currentElement.type // The wrapping type
|
|
192
|
+
this._renderedComponent = this._instantiateReactComponent(renderedElement, this._currentElement.type // The wrapping type
|
|
243
193
|
);
|
|
244
194
|
|
|
245
|
-
var markup = ReactReconciler.mountComponent(
|
|
246
|
-
this._renderedComponent,
|
|
247
|
-
rootID,
|
|
248
|
-
transaction,
|
|
249
|
-
this._processChildContext(context)
|
|
250
|
-
);
|
|
195
|
+
var markup = ReactReconciler.mountComponent(this._renderedComponent, rootID, transaction, this._processChildContext(context));
|
|
251
196
|
if (inst.componentDidMount) {
|
|
252
197
|
transaction.getReactMountReady().enqueue(inst.componentDidMount, inst);
|
|
253
198
|
}
|
|
@@ -261,7 +206,7 @@ var ReactCompositeComponentMixin = {
|
|
|
261
206
|
* @final
|
|
262
207
|
* @internal
|
|
263
208
|
*/
|
|
264
|
-
unmountComponent: function() {
|
|
209
|
+
unmountComponent: function () {
|
|
265
210
|
var inst = this._instance;
|
|
266
211
|
|
|
267
212
|
if (inst.componentWillUnmount) {
|
|
@@ -309,14 +254,11 @@ var ReactCompositeComponentMixin = {
|
|
|
309
254
|
* @final
|
|
310
255
|
* @internal
|
|
311
256
|
*/
|
|
312
|
-
_setPropsInternal: function(partialProps, callback) {
|
|
257
|
+
_setPropsInternal: function (partialProps, callback) {
|
|
313
258
|
// This is a deoptimized path. We optimize for always having an element.
|
|
314
259
|
// This creates an extra internal element.
|
|
315
260
|
var element = this._pendingElement || this._currentElement;
|
|
316
|
-
this._pendingElement = ReactElement.cloneAndReplaceProps(
|
|
317
|
-
element,
|
|
318
|
-
assign({}, element.props, partialProps)
|
|
319
|
-
);
|
|
261
|
+
this._pendingElement = ReactElement.cloneAndReplaceProps(element, assign({}, element.props, partialProps));
|
|
320
262
|
ReactUpdates.enqueueUpdate(this, callback);
|
|
321
263
|
},
|
|
322
264
|
|
|
@@ -328,14 +270,10 @@ var ReactCompositeComponentMixin = {
|
|
|
328
270
|
* @return {?object}
|
|
329
271
|
* @private
|
|
330
272
|
*/
|
|
331
|
-
_maskContext: function(context) {
|
|
273
|
+
_maskContext: function (context) {
|
|
332
274
|
var maskedContext = null;
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
if (typeof this._currentElement.type === 'string') {
|
|
336
|
-
return emptyObject;
|
|
337
|
-
}
|
|
338
|
-
var contextTypes = this._currentElement.type.contextTypes;
|
|
275
|
+
var Component = ReactNativeComponent.getComponentClassForElement(this._currentElement);
|
|
276
|
+
var contextTypes = Component.contextTypes;
|
|
339
277
|
if (!contextTypes) {
|
|
340
278
|
return emptyObject;
|
|
341
279
|
}
|
|
@@ -354,18 +292,12 @@ var ReactCompositeComponentMixin = {
|
|
|
354
292
|
* @return {?object}
|
|
355
293
|
* @private
|
|
356
294
|
*/
|
|
357
|
-
_processContext: function(context) {
|
|
295
|
+
_processContext: function (context) {
|
|
358
296
|
var maskedContext = this._maskContext(context);
|
|
359
|
-
if (
|
|
360
|
-
var Component = ReactNativeComponent.getComponentClassForElement(
|
|
361
|
-
this._currentElement
|
|
362
|
-
);
|
|
297
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
298
|
+
var Component = ReactNativeComponent.getComponentClassForElement(this._currentElement);
|
|
363
299
|
if (Component.contextTypes) {
|
|
364
|
-
this._checkPropTypes(
|
|
365
|
-
Component.contextTypes,
|
|
366
|
-
maskedContext,
|
|
367
|
-
ReactPropTypeLocations.context
|
|
368
|
-
);
|
|
300
|
+
this._checkPropTypes(Component.contextTypes, maskedContext, ReactPropTypeLocations.context);
|
|
369
301
|
}
|
|
370
302
|
}
|
|
371
303
|
return maskedContext;
|
|
@@ -376,30 +308,16 @@ var ReactCompositeComponentMixin = {
|
|
|
376
308
|
* @return {object}
|
|
377
309
|
* @private
|
|
378
310
|
*/
|
|
379
|
-
_processChildContext: function(currentContext) {
|
|
311
|
+
_processChildContext: function (currentContext) {
|
|
380
312
|
var inst = this._instance;
|
|
381
313
|
var childContext = inst.getChildContext && inst.getChildContext();
|
|
382
314
|
if (childContext) {
|
|
383
|
-
(
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
'use getChildContext().',
|
|
387
|
-
this.getName() || 'ReactCompositeComponent'
|
|
388
|
-
) : invariant(typeof inst.constructor.childContextTypes === 'object'));
|
|
389
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
390
|
-
this._checkPropTypes(
|
|
391
|
-
inst.constructor.childContextTypes,
|
|
392
|
-
childContext,
|
|
393
|
-
ReactPropTypeLocations.childContext
|
|
394
|
-
);
|
|
315
|
+
!(typeof inst.constructor.childContextTypes === 'object') ? 'production' !== process.env.NODE_ENV ? invariant(false, '%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', this.getName() || 'ReactCompositeComponent') : invariant(false) : undefined;
|
|
316
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
317
|
+
this._checkPropTypes(inst.constructor.childContextTypes, childContext, ReactPropTypeLocations.childContext);
|
|
395
318
|
}
|
|
396
319
|
for (var name in childContext) {
|
|
397
|
-
(
|
|
398
|
-
name in inst.constructor.childContextTypes,
|
|
399
|
-
'%s.getChildContext(): key "%s" is not defined in childContextTypes.',
|
|
400
|
-
this.getName() || 'ReactCompositeComponent',
|
|
401
|
-
name
|
|
402
|
-
) : invariant(name in inst.constructor.childContextTypes));
|
|
320
|
+
!(name in inst.constructor.childContextTypes) ? 'production' !== process.env.NODE_ENV ? invariant(false, '%s.getChildContext(): key "%s" is not defined in childContextTypes.', this.getName() || 'ReactCompositeComponent', name) : invariant(false) : undefined;
|
|
403
321
|
}
|
|
404
322
|
return assign({}, currentContext, childContext);
|
|
405
323
|
}
|
|
@@ -415,17 +333,11 @@ var ReactCompositeComponentMixin = {
|
|
|
415
333
|
* @return {object}
|
|
416
334
|
* @private
|
|
417
335
|
*/
|
|
418
|
-
_processProps: function(newProps) {
|
|
419
|
-
if (
|
|
420
|
-
var Component = ReactNativeComponent.getComponentClassForElement(
|
|
421
|
-
this._currentElement
|
|
422
|
-
);
|
|
336
|
+
_processProps: function (newProps) {
|
|
337
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
338
|
+
var Component = ReactNativeComponent.getComponentClassForElement(this._currentElement);
|
|
423
339
|
if (Component.propTypes) {
|
|
424
|
-
this._checkPropTypes(
|
|
425
|
-
Component.propTypes,
|
|
426
|
-
newProps,
|
|
427
|
-
ReactPropTypeLocations.prop
|
|
428
|
-
);
|
|
340
|
+
this._checkPropTypes(Component.propTypes, newProps, ReactPropTypeLocations.prop);
|
|
429
341
|
}
|
|
430
342
|
}
|
|
431
343
|
return newProps;
|
|
@@ -439,7 +351,7 @@ var ReactCompositeComponentMixin = {
|
|
|
439
351
|
* @param {string} location e.g. "prop", "context", "child context"
|
|
440
352
|
* @private
|
|
441
353
|
*/
|
|
442
|
-
_checkPropTypes: function(propTypes, props, location) {
|
|
354
|
+
_checkPropTypes: function (propTypes, props, location) {
|
|
443
355
|
// TODO: Stop validating prop types here and only use the element
|
|
444
356
|
// validation.
|
|
445
357
|
var componentName = this.getName();
|
|
@@ -449,14 +361,7 @@ var ReactCompositeComponentMixin = {
|
|
|
449
361
|
try {
|
|
450
362
|
// This is intentionally an invariant that gets caught. It's the same
|
|
451
363
|
// behavior as without this statement except with a better message.
|
|
452
|
-
(
|
|
453
|
-
typeof propTypes[propName] === 'function',
|
|
454
|
-
'%s: %s type `%s` is invalid; it must be a function, usually ' +
|
|
455
|
-
'from React.PropTypes.',
|
|
456
|
-
componentName || 'React class',
|
|
457
|
-
ReactPropTypeLocationNames[location],
|
|
458
|
-
propName
|
|
459
|
-
) : invariant(typeof propTypes[propName] === 'function'));
|
|
364
|
+
!(typeof propTypes[propName] === 'function') ? 'production' !== process.env.NODE_ENV ? invariant(false, '%s: %s type `%s` is invalid; it must be a function, usually ' + 'from React.PropTypes.', componentName || 'React class', ReactPropTypeLocationNames[location], propName) : invariant(false) : undefined;
|
|
460
365
|
error = propTypes[propName](props, propName, componentName, location);
|
|
461
366
|
} catch (ex) {
|
|
462
367
|
error = ex;
|
|
@@ -469,38 +374,22 @@ var ReactCompositeComponentMixin = {
|
|
|
469
374
|
|
|
470
375
|
if (location === ReactPropTypeLocations.prop) {
|
|
471
376
|
// Preface gives us something to blacklist in warning module
|
|
472
|
-
|
|
473
|
-
false,
|
|
474
|
-
'Failed Composite propType: %s%s',
|
|
475
|
-
error.message,
|
|
476
|
-
addendum
|
|
477
|
-
) : null);
|
|
377
|
+
'production' !== process.env.NODE_ENV ? warning(false, 'Failed Composite propType: %s%s', error.message, addendum) : undefined;
|
|
478
378
|
} else {
|
|
479
|
-
|
|
480
|
-
false,
|
|
481
|
-
'Failed Context Types: %s%s',
|
|
482
|
-
error.message,
|
|
483
|
-
addendum
|
|
484
|
-
) : null);
|
|
379
|
+
'production' !== process.env.NODE_ENV ? warning(false, 'Failed Context Types: %s%s', error.message, addendum) : undefined;
|
|
485
380
|
}
|
|
486
381
|
}
|
|
487
382
|
}
|
|
488
383
|
}
|
|
489
384
|
},
|
|
490
385
|
|
|
491
|
-
receiveComponent: function(nextElement, transaction, nextContext) {
|
|
386
|
+
receiveComponent: function (nextElement, transaction, nextContext) {
|
|
492
387
|
var prevElement = this._currentElement;
|
|
493
388
|
var prevContext = this._context;
|
|
494
389
|
|
|
495
390
|
this._pendingElement = null;
|
|
496
391
|
|
|
497
|
-
this.updateComponent(
|
|
498
|
-
transaction,
|
|
499
|
-
prevElement,
|
|
500
|
-
nextElement,
|
|
501
|
-
prevContext,
|
|
502
|
-
nextContext
|
|
503
|
-
);
|
|
392
|
+
this.updateComponent(transaction, prevElement, nextElement, prevContext, nextContext);
|
|
504
393
|
},
|
|
505
394
|
|
|
506
395
|
/**
|
|
@@ -510,54 +399,17 @@ var ReactCompositeComponentMixin = {
|
|
|
510
399
|
* @param {ReactReconcileTransaction} transaction
|
|
511
400
|
* @internal
|
|
512
401
|
*/
|
|
513
|
-
performUpdateIfNecessary: function(transaction) {
|
|
402
|
+
performUpdateIfNecessary: function (transaction) {
|
|
514
403
|
if (this._pendingElement != null) {
|
|
515
|
-
ReactReconciler.receiveComponent(
|
|
516
|
-
this,
|
|
517
|
-
this._pendingElement || this._currentElement,
|
|
518
|
-
transaction,
|
|
519
|
-
this._context
|
|
520
|
-
);
|
|
404
|
+
ReactReconciler.receiveComponent(this, this._pendingElement || this._currentElement, transaction, this._context);
|
|
521
405
|
}
|
|
522
406
|
|
|
523
407
|
if (this._pendingStateQueue !== null || this._pendingForceUpdate) {
|
|
524
|
-
if (
|
|
525
|
-
ReactElementValidator.checkAndWarnForMutatedProps(
|
|
526
|
-
this._currentElement
|
|
527
|
-
);
|
|
408
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
409
|
+
ReactElementValidator.checkAndWarnForMutatedProps(this._currentElement);
|
|
528
410
|
}
|
|
529
411
|
|
|
530
|
-
this.updateComponent(
|
|
531
|
-
transaction,
|
|
532
|
-
this._currentElement,
|
|
533
|
-
this._currentElement,
|
|
534
|
-
this._context,
|
|
535
|
-
this._context
|
|
536
|
-
);
|
|
537
|
-
}
|
|
538
|
-
},
|
|
539
|
-
|
|
540
|
-
/**
|
|
541
|
-
* Compare two contexts, warning if they are different
|
|
542
|
-
* TODO: Remove this check when owner-context is removed
|
|
543
|
-
*/
|
|
544
|
-
_warnIfContextsDiffer: function(ownerBasedContext, parentBasedContext) {
|
|
545
|
-
ownerBasedContext = this._maskContext(ownerBasedContext);
|
|
546
|
-
parentBasedContext = this._maskContext(parentBasedContext);
|
|
547
|
-
var parentKeys = Object.keys(parentBasedContext).sort();
|
|
548
|
-
var displayName = this.getName() || 'ReactCompositeComponent';
|
|
549
|
-
for (var i = 0; i < parentKeys.length; i++) {
|
|
550
|
-
var key = parentKeys[i];
|
|
551
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
552
|
-
ownerBasedContext[key] === parentBasedContext[key],
|
|
553
|
-
'owner-based and parent-based contexts differ ' +
|
|
554
|
-
'(values: `%s` vs `%s`) for key (%s) while mounting %s ' +
|
|
555
|
-
'(see: http://fb.me/react-context-by-parent)',
|
|
556
|
-
ownerBasedContext[key],
|
|
557
|
-
parentBasedContext[key],
|
|
558
|
-
key,
|
|
559
|
-
displayName
|
|
560
|
-
) : null);
|
|
412
|
+
this.updateComponent(transaction, this._currentElement, this._currentElement, this._context, this._context);
|
|
561
413
|
}
|
|
562
414
|
},
|
|
563
415
|
|
|
@@ -576,13 +428,7 @@ var ReactCompositeComponentMixin = {
|
|
|
576
428
|
* @internal
|
|
577
429
|
* @overridable
|
|
578
430
|
*/
|
|
579
|
-
updateComponent: function(
|
|
580
|
-
transaction,
|
|
581
|
-
prevParentElement,
|
|
582
|
-
nextParentElement,
|
|
583
|
-
prevUnmaskedContext,
|
|
584
|
-
nextUnmaskedContext
|
|
585
|
-
) {
|
|
431
|
+
updateComponent: function (transaction, prevParentElement, nextParentElement, prevUnmaskedContext, nextUnmaskedContext) {
|
|
586
432
|
var inst = this._instance;
|
|
587
433
|
|
|
588
434
|
var nextContext = inst.context;
|
|
@@ -590,18 +436,9 @@ var ReactCompositeComponentMixin = {
|
|
|
590
436
|
|
|
591
437
|
// Distinguish between a props update versus a simple state update
|
|
592
438
|
if (prevParentElement !== nextParentElement) {
|
|
593
|
-
nextContext = this._processContext(
|
|
439
|
+
nextContext = this._processContext(nextUnmaskedContext);
|
|
594
440
|
nextProps = this._processProps(nextParentElement.props);
|
|
595
441
|
|
|
596
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
597
|
-
if (nextUnmaskedContext != null) {
|
|
598
|
-
this._warnIfContextsDiffer(
|
|
599
|
-
nextParentElement._context,
|
|
600
|
-
nextUnmaskedContext
|
|
601
|
-
);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
|
|
605
442
|
// An update here will schedule an update but immediately set
|
|
606
443
|
// _pendingStateQueue which will ensure that any state updates gets
|
|
607
444
|
// immediately reconciled instead of waiting for the next batch.
|
|
@@ -613,31 +450,16 @@ var ReactCompositeComponentMixin = {
|
|
|
613
450
|
|
|
614
451
|
var nextState = this._processPendingState(nextProps, nextContext);
|
|
615
452
|
|
|
616
|
-
var shouldUpdate =
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
622
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
623
|
-
typeof shouldUpdate !== 'undefined',
|
|
624
|
-
'%s.shouldComponentUpdate(): Returned undefined instead of a ' +
|
|
625
|
-
'boolean value. Make sure to return true or false.',
|
|
626
|
-
this.getName() || 'ReactCompositeComponent'
|
|
627
|
-
) : null);
|
|
453
|
+
var shouldUpdate = this._pendingForceUpdate || !inst.shouldComponentUpdate || inst.shouldComponentUpdate(nextProps, nextState, nextContext);
|
|
454
|
+
|
|
455
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
456
|
+
'production' !== process.env.NODE_ENV ? warning(typeof shouldUpdate !== 'undefined', '%s.shouldComponentUpdate(): Returned undefined instead of a ' + 'boolean value. Make sure to return true or false.', this.getName() || 'ReactCompositeComponent') : undefined;
|
|
628
457
|
}
|
|
629
458
|
|
|
630
459
|
if (shouldUpdate) {
|
|
631
460
|
this._pendingForceUpdate = false;
|
|
632
461
|
// Will set `this.props`, `this.state` and `this.context`.
|
|
633
|
-
this._performComponentUpdate(
|
|
634
|
-
nextParentElement,
|
|
635
|
-
nextProps,
|
|
636
|
-
nextState,
|
|
637
|
-
nextContext,
|
|
638
|
-
transaction,
|
|
639
|
-
nextUnmaskedContext
|
|
640
|
-
);
|
|
462
|
+
this._performComponentUpdate(nextParentElement, nextProps, nextState, nextContext, transaction, nextUnmaskedContext);
|
|
641
463
|
} else {
|
|
642
464
|
// If it's determined that a component should not update, we still want
|
|
643
465
|
// to set props and state but we shortcut the rest of the update.
|
|
@@ -649,7 +471,7 @@ var ReactCompositeComponentMixin = {
|
|
|
649
471
|
}
|
|
650
472
|
},
|
|
651
473
|
|
|
652
|
-
_processPendingState: function(props, context) {
|
|
474
|
+
_processPendingState: function (props, context) {
|
|
653
475
|
var inst = this._instance;
|
|
654
476
|
var queue = this._pendingStateQueue;
|
|
655
477
|
var replace = this._pendingReplaceState;
|
|
@@ -660,15 +482,14 @@ var ReactCompositeComponentMixin = {
|
|
|
660
482
|
return inst.state;
|
|
661
483
|
}
|
|
662
484
|
|
|
485
|
+
if (replace && queue.length === 1) {
|
|
486
|
+
return queue[0];
|
|
487
|
+
}
|
|
488
|
+
|
|
663
489
|
var nextState = assign({}, replace ? queue[0] : inst.state);
|
|
664
490
|
for (var i = replace ? 1 : 0; i < queue.length; i++) {
|
|
665
491
|
var partial = queue[i];
|
|
666
|
-
assign(
|
|
667
|
-
nextState,
|
|
668
|
-
typeof partial === 'function' ?
|
|
669
|
-
partial.call(inst, nextState, props, context) :
|
|
670
|
-
partial
|
|
671
|
-
);
|
|
492
|
+
assign(nextState, typeof partial === 'function' ? partial.call(inst, nextState, props, context) : partial);
|
|
672
493
|
}
|
|
673
494
|
|
|
674
495
|
return nextState;
|
|
@@ -686,14 +507,7 @@ var ReactCompositeComponentMixin = {
|
|
|
686
507
|
* @param {?object} unmaskedContext
|
|
687
508
|
* @private
|
|
688
509
|
*/
|
|
689
|
-
_performComponentUpdate: function(
|
|
690
|
-
nextElement,
|
|
691
|
-
nextProps,
|
|
692
|
-
nextState,
|
|
693
|
-
nextContext,
|
|
694
|
-
transaction,
|
|
695
|
-
unmaskedContext
|
|
696
|
-
) {
|
|
510
|
+
_performComponentUpdate: function (nextElement, nextProps, nextState, nextContext, transaction, unmaskedContext) {
|
|
697
511
|
var inst = this._instance;
|
|
698
512
|
|
|
699
513
|
var prevProps = inst.props;
|
|
@@ -713,10 +527,7 @@ var ReactCompositeComponentMixin = {
|
|
|
713
527
|
this._updateRenderedComponent(transaction, unmaskedContext);
|
|
714
528
|
|
|
715
529
|
if (inst.componentDidUpdate) {
|
|
716
|
-
transaction.getReactMountReady().enqueue(
|
|
717
|
-
inst.componentDidUpdate.bind(inst, prevProps, prevState, prevContext),
|
|
718
|
-
inst
|
|
719
|
-
);
|
|
530
|
+
transaction.getReactMountReady().enqueue(inst.componentDidUpdate.bind(inst, prevProps, prevState, prevContext), inst);
|
|
720
531
|
}
|
|
721
532
|
},
|
|
722
533
|
|
|
@@ -726,33 +537,20 @@ var ReactCompositeComponentMixin = {
|
|
|
726
537
|
* @param {ReactReconcileTransaction} transaction
|
|
727
538
|
* @internal
|
|
728
539
|
*/
|
|
729
|
-
_updateRenderedComponent: function(transaction, context) {
|
|
540
|
+
_updateRenderedComponent: function (transaction, context) {
|
|
730
541
|
var prevComponentInstance = this._renderedComponent;
|
|
731
542
|
var prevRenderedElement = prevComponentInstance._currentElement;
|
|
732
543
|
var nextRenderedElement = this._renderValidatedComponent();
|
|
733
544
|
if (shouldUpdateReactComponent(prevRenderedElement, nextRenderedElement)) {
|
|
734
|
-
ReactReconciler.receiveComponent(
|
|
735
|
-
prevComponentInstance,
|
|
736
|
-
nextRenderedElement,
|
|
737
|
-
transaction,
|
|
738
|
-
this._processChildContext(context)
|
|
739
|
-
);
|
|
545
|
+
ReactReconciler.receiveComponent(prevComponentInstance, nextRenderedElement, transaction, this._processChildContext(context));
|
|
740
546
|
} else {
|
|
741
547
|
// These two IDs are actually the same! But nothing should rely on that.
|
|
742
548
|
var thisID = this._rootNodeID;
|
|
743
549
|
var prevComponentID = prevComponentInstance._rootNodeID;
|
|
744
550
|
ReactReconciler.unmountComponent(prevComponentInstance);
|
|
745
551
|
|
|
746
|
-
this._renderedComponent = this._instantiateReactComponent(
|
|
747
|
-
|
|
748
|
-
this._currentElement.type
|
|
749
|
-
);
|
|
750
|
-
var nextMarkup = ReactReconciler.mountComponent(
|
|
751
|
-
this._renderedComponent,
|
|
752
|
-
thisID,
|
|
753
|
-
transaction,
|
|
754
|
-
this._processChildContext(context)
|
|
755
|
-
);
|
|
552
|
+
this._renderedComponent = this._instantiateReactComponent(nextRenderedElement, this._currentElement.type);
|
|
553
|
+
var nextMarkup = ReactReconciler.mountComponent(this._renderedComponent, thisID, transaction, this._processChildContext(context));
|
|
756
554
|
this._replaceNodeWithMarkupByID(prevComponentID, nextMarkup);
|
|
757
555
|
}
|
|
758
556
|
},
|
|
@@ -760,23 +558,19 @@ var ReactCompositeComponentMixin = {
|
|
|
760
558
|
/**
|
|
761
559
|
* @protected
|
|
762
560
|
*/
|
|
763
|
-
_replaceNodeWithMarkupByID: function(prevComponentID, nextMarkup) {
|
|
764
|
-
ReactComponentEnvironment.replaceNodeWithMarkupByID(
|
|
765
|
-
prevComponentID,
|
|
766
|
-
nextMarkup
|
|
767
|
-
);
|
|
561
|
+
_replaceNodeWithMarkupByID: function (prevComponentID, nextMarkup) {
|
|
562
|
+
ReactComponentEnvironment.replaceNodeWithMarkupByID(prevComponentID, nextMarkup);
|
|
768
563
|
},
|
|
769
564
|
|
|
770
565
|
/**
|
|
771
566
|
* @protected
|
|
772
567
|
*/
|
|
773
|
-
_renderValidatedComponentWithoutOwnerOrContext: function() {
|
|
568
|
+
_renderValidatedComponentWithoutOwnerOrContext: function () {
|
|
774
569
|
var inst = this._instance;
|
|
775
570
|
var renderedComponent = inst.render();
|
|
776
|
-
if (
|
|
571
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
777
572
|
// We allow auto-mocks to proceed as if they're returning null.
|
|
778
|
-
if (typeof renderedComponent === 'undefined' &&
|
|
779
|
-
inst.render._isMockFunction) {
|
|
573
|
+
if (typeof renderedComponent === 'undefined' && inst.render._isMockFunction) {
|
|
780
574
|
// This is probably bad practice. Consider warning here and
|
|
781
575
|
// deprecating this convenience.
|
|
782
576
|
renderedComponent = null;
|
|
@@ -789,30 +583,20 @@ var ReactCompositeComponentMixin = {
|
|
|
789
583
|
/**
|
|
790
584
|
* @private
|
|
791
585
|
*/
|
|
792
|
-
_renderValidatedComponent: function() {
|
|
586
|
+
_renderValidatedComponent: function () {
|
|
793
587
|
var renderedComponent;
|
|
794
588
|
var previousContext = ReactContext.current;
|
|
795
|
-
ReactContext.current = this._processChildContext(
|
|
796
|
-
this._currentElement._context
|
|
797
|
-
);
|
|
589
|
+
ReactContext.current = this._processChildContext(this._currentElement._context);
|
|
798
590
|
ReactCurrentOwner.current = this;
|
|
799
591
|
try {
|
|
800
|
-
renderedComponent =
|
|
801
|
-
this._renderValidatedComponentWithoutOwnerOrContext();
|
|
592
|
+
renderedComponent = this._renderValidatedComponentWithoutOwnerOrContext();
|
|
802
593
|
} finally {
|
|
803
594
|
ReactContext.current = previousContext;
|
|
804
595
|
ReactCurrentOwner.current = null;
|
|
805
596
|
}
|
|
806
|
-
(
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
ReactElement.isValidElement(renderedComponent),
|
|
810
|
-
'%s.render(): A valid ReactComponent must be returned. You may have ' +
|
|
811
|
-
'returned undefined, an array or some other invalid object.',
|
|
812
|
-
this.getName() || 'ReactCompositeComponent'
|
|
813
|
-
) : invariant(// TODO: An `isValidNode` function would probably be more appropriate
|
|
814
|
-
renderedComponent === null || renderedComponent === false ||
|
|
815
|
-
ReactElement.isValidElement(renderedComponent)));
|
|
597
|
+
!(
|
|
598
|
+
// TODO: An `isValidNode` function would probably be more appropriate
|
|
599
|
+
(renderedComponent === null || renderedComponent === false || ReactElement.isValidElement(renderedComponent))) ? 'production' !== process.env.NODE_ENV ? invariant(false, '%s.render(): A valid ReactComponent must be returned. You may have ' + 'returned undefined, an array or some other invalid object.', this.getName() || 'ReactCompositeComponent') : invariant(false) : undefined;
|
|
816
600
|
return renderedComponent;
|
|
817
601
|
},
|
|
818
602
|
|
|
@@ -824,9 +608,9 @@ var ReactCompositeComponentMixin = {
|
|
|
824
608
|
* @final
|
|
825
609
|
* @private
|
|
826
610
|
*/
|
|
827
|
-
attachRef: function(ref, component) {
|
|
611
|
+
attachRef: function (ref, component) {
|
|
828
612
|
var inst = this.getPublicInstance();
|
|
829
|
-
var refs = inst.refs === emptyObject ?
|
|
613
|
+
var refs = inst.refs === emptyObject ? inst.refs = {} : inst.refs;
|
|
830
614
|
refs[ref] = component.getPublicInstance();
|
|
831
615
|
},
|
|
832
616
|
|
|
@@ -837,7 +621,7 @@ var ReactCompositeComponentMixin = {
|
|
|
837
621
|
* @final
|
|
838
622
|
* @private
|
|
839
623
|
*/
|
|
840
|
-
detachRef: function(ref) {
|
|
624
|
+
detachRef: function (ref) {
|
|
841
625
|
var refs = this.getPublicInstance().refs;
|
|
842
626
|
delete refs[ref];
|
|
843
627
|
},
|
|
@@ -848,14 +632,10 @@ var ReactCompositeComponentMixin = {
|
|
|
848
632
|
* @return {string} The name or null.
|
|
849
633
|
* @internal
|
|
850
634
|
*/
|
|
851
|
-
getName: function() {
|
|
635
|
+
getName: function () {
|
|
852
636
|
var type = this._currentElement.type;
|
|
853
637
|
var constructor = this._instance && this._instance.constructor;
|
|
854
|
-
return
|
|
855
|
-
type.displayName || (constructor && constructor.displayName) ||
|
|
856
|
-
type.name || (constructor && constructor.name) ||
|
|
857
|
-
null
|
|
858
|
-
);
|
|
638
|
+
return type.displayName || constructor && constructor.displayName || type.name || constructor && constructor.name || null;
|
|
859
639
|
},
|
|
860
640
|
|
|
861
641
|
/**
|
|
@@ -866,7 +646,7 @@ var ReactCompositeComponentMixin = {
|
|
|
866
646
|
* @return {ReactComponent} the public component instance.
|
|
867
647
|
* @internal
|
|
868
648
|
*/
|
|
869
|
-
getPublicInstance: function() {
|
|
649
|
+
getPublicInstance: function () {
|
|
870
650
|
return this._instance;
|
|
871
651
|
},
|
|
872
652
|
|
|
@@ -875,15 +655,11 @@ var ReactCompositeComponentMixin = {
|
|
|
875
655
|
|
|
876
656
|
};
|
|
877
657
|
|
|
878
|
-
ReactPerf.measureMethods(
|
|
879
|
-
|
|
880
|
-
'
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
updateComponent: 'updateComponent',
|
|
884
|
-
_renderValidatedComponent: '_renderValidatedComponent'
|
|
885
|
-
}
|
|
886
|
-
);
|
|
658
|
+
ReactPerf.measureMethods(ReactCompositeComponentMixin, 'ReactCompositeComponent', {
|
|
659
|
+
mountComponent: 'mountComponent',
|
|
660
|
+
updateComponent: 'updateComponent',
|
|
661
|
+
_renderValidatedComponent: '_renderValidatedComponent'
|
|
662
|
+
});
|
|
887
663
|
|
|
888
664
|
var ReactCompositeComponent = {
|
|
889
665
|
|
|
@@ -891,4 +667,4 @@ var ReactCompositeComponent = {
|
|
|
891
667
|
|
|
892
668
|
};
|
|
893
669
|
|
|
894
|
-
module.exports = ReactCompositeComponent;
|
|
670
|
+
module.exports = ReactCompositeComponent;
|