react 0.14.0-alpha3 → 0.14.0-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/addons.js +8 -3
- package/dist/react-dom.js +42 -0
- package/dist/react-dom.min.js +12 -0
- package/dist/react-with-addons.js +6076 -5337
- package/dist/react-with-addons.min.js +6 -6
- package/dist/react.js +5445 -4839
- package/dist/react.min.js +6 -5
- package/lib/{AutoFocusMixin.js → AutoFocusUtils.js} +15 -5
- package/lib/BeforeInputEventPlugin.js +13 -13
- package/lib/CSSProperty.js +18 -3
- package/lib/CSSPropertyOperations.js +22 -14
- package/lib/CallbackQueue.js +4 -4
- package/lib/ChangeEventPlugin.js +18 -15
- package/lib/DOMChildrenOperations.js +17 -7
- package/lib/DOMProperty.js +82 -117
- package/lib/DOMPropertyOperations.js +84 -33
- package/lib/Danger.js +21 -16
- package/lib/DefaultEventPluginOrder.js +2 -2
- package/lib/EnterLeaveEventPlugin.js +21 -13
- package/lib/EventConstants.js +23 -1
- package/lib/EventPluginHub.js +17 -20
- package/lib/EventPluginRegistry.js +8 -8
- package/lib/EventPluginUtils.js +33 -42
- package/lib/EventPropagators.js +8 -8
- package/lib/FallbackCompositionState.js +9 -3
- package/lib/HTMLDOMPropertyConfig.js +19 -3
- package/lib/LinkedStateMixin.js +2 -2
- package/lib/LinkedValueUtils.js +50 -38
- package/lib/MetaMatchers.js +118 -0
- package/lib/OrderedMap.js +453 -0
- package/lib/PooledClass.js +15 -5
- package/lib/React.js +18 -7
- package/lib/ReactBrowserComponentMixin.js +4 -4
- package/lib/ReactBrowserEventEmitter.js +30 -7
- package/lib/ReactCSSTransitionGroup.js +35 -9
- package/lib/ReactCSSTransitionGroupChild.js +56 -30
- package/lib/ReactChildReconciler.js +24 -19
- package/lib/ReactChildren.js +75 -35
- package/lib/ReactClass.js +70 -87
- package/lib/ReactComponent.js +27 -20
- package/lib/ReactComponentBrowserEnvironment.js +2 -2
- package/lib/ReactComponentEnvironment.js +2 -2
- package/lib/ReactComponentWithPureRenderMixin.js +3 -3
- package/lib/ReactCompositeComponent.js +117 -106
- package/lib/ReactDOM.js +74 -158
- package/lib/ReactDOMButton.js +15 -26
- package/lib/ReactDOMComponent.js +441 -72
- package/lib/ReactDOMFactories.js +177 -0
- package/lib/{emptyObject.js → ReactDOMFeatureFlags.js} +6 -8
- package/lib/ReactDOMIDOperations.js +8 -66
- package/lib/ReactDOMInput.js +87 -99
- package/lib/ReactDOMOption.js +25 -44
- package/lib/ReactDOMSelect.js +88 -98
- package/lib/ReactDOMSelection.js +3 -3
- package/lib/ReactDOMServer.js +5 -3
- package/lib/ReactDOMTextComponent.js +33 -20
- package/lib/ReactDOMTextarea.js +48 -61
- package/lib/ReactDefaultBatchingStrategy.js +4 -4
- package/lib/ReactDefaultInjection.js +23 -72
- package/lib/ReactDefaultPerf.js +7 -7
- package/lib/ReactDefaultPerfAnalysis.js +6 -11
- package/lib/ReactElement.js +92 -107
- package/lib/ReactElementValidator.js +53 -173
- package/lib/ReactEmptyComponent.js +26 -62
- package/lib/ReactEmptyComponentRegistry.js +48 -0
- package/lib/ReactErrorUtils.js +45 -9
- package/lib/ReactEventEmitterMixin.js +3 -4
- package/lib/ReactEventListener.js +64 -12
- package/lib/ReactFragment.js +29 -115
- package/lib/ReactInjection.js +10 -12
- package/lib/ReactInputSelection.js +8 -7
- package/lib/ReactInstanceHandles.js +12 -12
- package/lib/ReactIsomorphic.js +15 -11
- package/lib/ReactLink.js +1 -1
- package/lib/ReactMarkupChecksum.js +6 -2
- package/lib/ReactMount.js +196 -122
- package/lib/ReactMultiChild.js +119 -25
- package/lib/ReactMultiChildUpdateTypes.js +2 -1
- package/lib/ReactNativeComponent.js +3 -8
- package/lib/ReactNoopUpdateQueue.js +118 -0
- package/lib/ReactOwner.js +3 -3
- package/lib/ReactPerf.js +2 -2
- package/lib/ReactPropTransferer.js +3 -3
- package/lib/ReactPropTypeLocationNames.js +1 -1
- package/lib/ReactPropTypeLocations.js +1 -1
- package/lib/ReactPropTypes.js +41 -12
- package/lib/ReactReconcileTransaction.js +12 -10
- package/lib/ReactReconciler.js +8 -11
- package/lib/ReactRef.js +15 -2
- package/lib/ReactServerBatchingStrategy.js +23 -0
- package/lib/ReactServerRendering.js +22 -9
- package/lib/ReactServerRenderingTransaction.js +8 -7
- package/lib/ReactTestUtils.js +89 -64
- package/lib/ReactTransitionChildMapping.js +3 -6
- package/lib/ReactTransitionEvents.js +1 -1
- package/lib/ReactTransitionGroup.js +5 -6
- package/lib/ReactUpdateQueue.js +60 -35
- package/lib/ReactUpdates.js +15 -18
- package/lib/{isTextNode.js → ReactVersion.js} +2 -13
- package/lib/ReactWithAddons.js +24 -17
- package/lib/ResponderEventPlugin.js +514 -0
- package/lib/ResponderSyntheticEvent.js +40 -0
- package/lib/ResponderTouchHistoryStore.js +180 -0
- package/lib/SVGDOMPropertyConfig.js +1 -1
- package/lib/SelectEventPlugin.js +25 -16
- package/lib/SimpleEventPlugin.js +200 -45
- package/lib/SyntheticClipboardEvent.js +3 -3
- package/lib/SyntheticCompositionEvent.js +3 -3
- package/lib/SyntheticDragEvent.js +3 -3
- package/lib/SyntheticEvent.js +24 -8
- package/lib/SyntheticFocusEvent.js +3 -3
- package/lib/SyntheticInputEvent.js +3 -3
- package/lib/SyntheticKeyboardEvent.js +6 -6
- package/lib/SyntheticMouseEvent.js +5 -5
- package/lib/SyntheticTouchEvent.js +4 -4
- package/lib/SyntheticUIEvent.js +4 -4
- package/lib/SyntheticWheelEvent.js +3 -3
- package/lib/TapEventPlugin.js +119 -0
- package/lib/Transaction.js +17 -11
- package/lib/accumulate.js +44 -0
- package/lib/accumulateInto.js +2 -2
- package/lib/adler32.js +19 -7
- package/lib/cloneWithProps.js +12 -7
- package/lib/createHierarchyRenderer.js +85 -0
- package/lib/dangerousStyleValue.js +1 -1
- package/lib/deprecated.js +48 -0
- package/lib/findDOMNode.js +11 -12
- package/lib/flattenChildren.js +4 -4
- package/lib/forEachAccumulated.js +1 -1
- package/lib/getEventCharCode.js +1 -1
- package/lib/getEventKey.js +1 -1
- package/lib/getEventModifierState.js +0 -1
- package/lib/getTestDocument.js +28 -0
- package/lib/getTextContentAccessor.js +1 -1
- package/lib/instantiateReactComponent.js +27 -25
- package/lib/isEventSupported.js +1 -1
- package/lib/isTextInputElement.js +2 -1
- package/lib/joinClasses.js +1 -1
- package/lib/onlyChild.js +3 -3
- package/lib/quoteAttributeValueForBrowser.js +1 -1
- package/lib/reactComponentExpect.js +216 -0
- package/lib/renderSubtreeIntoContainer.js +1 -1
- package/lib/setInnerHTML.js +2 -2
- package/lib/setTextContent.js +3 -3
- package/lib/shallowCompare.js +1 -1
- package/lib/shouldUpdateReactComponent.js +12 -8
- package/lib/sliceChildren.js +34 -0
- package/lib/traverseAllChildren.js +21 -19
- package/lib/update.js +13 -13
- package/lib/validateDOMNesting.js +6 -6
- package/lib/webcomponents.js +6379 -0
- package/package.json +4 -6
- package/react.js +2 -0
- package/addons/CSSTransitionGroup.js +0 -1
- package/addons/LinkedStateMixin.js +0 -1
- package/addons/Perf.js +0 -1
- package/addons/PureRenderMixin.js +0 -1
- package/addons/TestUtils.js +0 -1
- package/addons/TransitionGroup.js +0 -1
- package/addons/batchedUpdates.js +0 -1
- package/addons/cloneWithProps.js +0 -1
- package/addons/createFragment.js +0 -1
- package/addons/renderSubtreeIntoContainer.js +0 -1
- package/addons/shallowCompare.js +0 -1
- package/addons/update.js +0 -1
- package/dist/JSXTransformer.js +0 -17589
- package/lib/CSSCore.js +0 -97
- package/lib/EventListener.js +0 -84
- package/lib/ExecutionEnvironment.js +0 -38
- package/lib/LocalEventTrapMixin.js +0 -46
- package/lib/ReactContext.js +0 -32
- package/lib/ReactDOMClient.js +0 -85
- package/lib/ReactDOMForm.js +0 -47
- package/lib/ReactDOMIframe.js +0 -43
- package/lib/ReactDOMImg.js +0 -44
- package/lib/ReactLifeCycle.js +0 -35
- package/lib/camelize.js +0 -32
- package/lib/camelizeStyleName.js +0 -40
- package/lib/containsNode.js +0 -55
- package/lib/createArrayFromMixed.js +0 -85
- package/lib/createFullPageComponent.js +0 -51
- package/lib/createNodesFromMarkup.js +0 -84
- package/lib/emptyFunction.js +0 -38
- package/lib/focusNode.js +0 -26
- package/lib/getActiveElement.js +0 -29
- package/lib/getMarkupWrap.js +0 -115
- package/lib/getUnboundedScrollPosition.js +0 -38
- package/lib/hyphenate.js +0 -33
- package/lib/hyphenateStyleName.js +0 -39
- package/lib/invariant.js +0 -49
- package/lib/isNode.js +0 -23
- package/lib/keyMirror.js +0 -48
- package/lib/keyOf.js +0 -35
- package/lib/mapObject.js +0 -51
- package/lib/performance.js +0 -23
- package/lib/performanceNow.js +0 -28
- package/lib/shallowEqual.js +0 -48
- package/lib/toArray.js +0 -57
- package/lib/warning.js +0 -61
package/lib/ReactComponent.js
CHANGED
|
@@ -11,19 +11,26 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var ReactNoopUpdateQueue = require('./ReactNoopUpdateQueue');
|
|
15
15
|
|
|
16
|
-
var
|
|
17
|
-
var
|
|
16
|
+
var emptyObject = require('fbjs/lib/emptyObject');
|
|
17
|
+
var invariant = require('fbjs/lib/invariant');
|
|
18
|
+
var warning = require('fbjs/lib/warning');
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Base class helpers for the updating state of a component.
|
|
21
22
|
*/
|
|
22
|
-
function ReactComponent(props, context) {
|
|
23
|
+
function ReactComponent(props, context, updater) {
|
|
23
24
|
this.props = props;
|
|
24
25
|
this.context = context;
|
|
26
|
+
this.refs = emptyObject;
|
|
27
|
+
// We initialize the default updater but the real one gets injected by the
|
|
28
|
+
// renderer.
|
|
29
|
+
this.updater = updater || ReactNoopUpdateQueue;
|
|
25
30
|
}
|
|
26
31
|
|
|
32
|
+
ReactComponent.isReactClass = {};
|
|
33
|
+
|
|
27
34
|
/**
|
|
28
35
|
* Sets a subset of the state. Always use this to mutate
|
|
29
36
|
* state. You should treat `this.state` as immutable.
|
|
@@ -50,13 +57,13 @@ function ReactComponent(props, context) {
|
|
|
50
57
|
* @protected
|
|
51
58
|
*/
|
|
52
59
|
ReactComponent.prototype.setState = function (partialState, callback) {
|
|
53
|
-
!(typeof partialState === 'object' || typeof partialState === 'function' || partialState == null) ?
|
|
54
|
-
if (
|
|
55
|
-
|
|
60
|
+
!(typeof partialState === 'object' || typeof partialState === 'function' || partialState == null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'setState(...): takes an object of state variables to update or a ' + 'function which returns an object of state variables.') : invariant(false) : undefined;
|
|
61
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
62
|
+
process.env.NODE_ENV !== 'production' ? warning(partialState != null, 'setState(...): You passed an undefined or null state object; ' + 'instead, use forceUpdate().') : undefined;
|
|
56
63
|
}
|
|
57
|
-
|
|
64
|
+
this.updater.enqueueSetState(this, partialState);
|
|
58
65
|
if (callback) {
|
|
59
|
-
|
|
66
|
+
this.updater.enqueueCallback(this, callback);
|
|
60
67
|
}
|
|
61
68
|
};
|
|
62
69
|
|
|
@@ -75,9 +82,9 @@ ReactComponent.prototype.setState = function (partialState, callback) {
|
|
|
75
82
|
* @protected
|
|
76
83
|
*/
|
|
77
84
|
ReactComponent.prototype.forceUpdate = function (callback) {
|
|
78
|
-
|
|
85
|
+
this.updater.enqueueForceUpdate(this);
|
|
79
86
|
if (callback) {
|
|
80
|
-
|
|
87
|
+
this.updater.enqueueCallback(this, callback);
|
|
81
88
|
}
|
|
82
89
|
};
|
|
83
90
|
|
|
@@ -86,23 +93,25 @@ ReactComponent.prototype.forceUpdate = function (callback) {
|
|
|
86
93
|
* we would like to deprecate them, we're not going to move them over to this
|
|
87
94
|
* modern base class. Instead, we define a getter that warns if it's accessed.
|
|
88
95
|
*/
|
|
89
|
-
if (
|
|
96
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
90
97
|
var deprecatedAPIs = {
|
|
91
|
-
getDOMNode: ['getDOMNode', 'Use
|
|
98
|
+
getDOMNode: ['getDOMNode', 'Use ReactDOM.findDOMNode(component) instead.'],
|
|
92
99
|
isMounted: ['isMounted', 'Instead, make sure to clean up subscriptions and pending requests in ' + 'componentWillUnmount to prevent memory leaks.'],
|
|
93
|
-
replaceProps: ['replaceProps', 'Instead, call
|
|
100
|
+
replaceProps: ['replaceProps', 'Instead, call render again at the top level.'],
|
|
94
101
|
replaceState: ['replaceState', 'Refactor your code to use setState instead (see ' + 'https://github.com/facebook/react/issues/3236).'],
|
|
95
|
-
setProps: ['setProps', 'Instead, call
|
|
102
|
+
setProps: ['setProps', 'Instead, call render again at the top level.']
|
|
96
103
|
};
|
|
97
104
|
var defineDeprecationWarning = function (methodName, info) {
|
|
98
105
|
try {
|
|
99
106
|
Object.defineProperty(ReactComponent.prototype, methodName, {
|
|
100
107
|
get: function () {
|
|
101
|
-
|
|
108
|
+
process.env.NODE_ENV !== 'production' ? warning(false, '%s(...) is deprecated in plain JavaScript React classes. %s', info[0], info[1]) : undefined;
|
|
102
109
|
return undefined;
|
|
103
110
|
}
|
|
104
111
|
});
|
|
105
|
-
} catch (x) {
|
|
112
|
+
} catch (x) {
|
|
113
|
+
// IE will fail on defineProperty (es5-shim/sham too)
|
|
114
|
+
}
|
|
106
115
|
};
|
|
107
116
|
for (var fnName in deprecatedAPIs) {
|
|
108
117
|
if (deprecatedAPIs.hasOwnProperty(fnName)) {
|
|
@@ -111,6 +120,4 @@ if ('production' !== process.env.NODE_ENV) {
|
|
|
111
120
|
}
|
|
112
121
|
}
|
|
113
122
|
|
|
114
|
-
module.exports = ReactComponent;
|
|
115
|
-
|
|
116
|
-
// IE will fail on defineProperty (es5-shim/sham too)
|
|
123
|
+
module.exports = ReactComponent;
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
var ReactDOMIDOperations = require(
|
|
15
|
-
var ReactMount = require(
|
|
14
|
+
var ReactDOMIDOperations = require('./ReactDOMIDOperations');
|
|
15
|
+
var ReactMount = require('./ReactMount');
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Abstracts away all functionality of the reconciler that requires knowledge of
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
var invariant = require(
|
|
14
|
+
var invariant = require('fbjs/lib/invariant');
|
|
15
15
|
|
|
16
16
|
var injected = false;
|
|
17
17
|
|
|
@@ -38,7 +38,7 @@ var ReactComponentEnvironment = {
|
|
|
38
38
|
|
|
39
39
|
injection: {
|
|
40
40
|
injectEnvironment: function (environment) {
|
|
41
|
-
!!injected ?
|
|
41
|
+
!!injected ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactCompositeComponent: injectEnvironment() can only be called once.') : invariant(false) : undefined;
|
|
42
42
|
ReactComponentEnvironment.unmountIDFromEnvironment = environment.unmountIDFromEnvironment;
|
|
43
43
|
ReactComponentEnvironment.replaceNodeWithMarkupByID = environment.replaceNodeWithMarkupByID;
|
|
44
44
|
ReactComponentEnvironment.processChildrenUpdates = environment.processChildrenUpdates;
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
7
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
8
|
*
|
|
9
|
-
* @providesModule ReactComponentWithPureRenderMixin
|
|
10
|
-
*/
|
|
9
|
+
* @providesModule ReactComponentWithPureRenderMixin
|
|
10
|
+
*/
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
var shallowCompare = require(
|
|
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
|
|
@@ -11,25 +11,21 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
var ReactComponentEnvironment = require(
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
var
|
|
29
|
-
var emptyObject = require("./emptyObject");
|
|
30
|
-
var invariant = require("./invariant");
|
|
31
|
-
var shouldUpdateReactComponent = require("./shouldUpdateReactComponent");
|
|
32
|
-
var warning = require("./warning");
|
|
14
|
+
var ReactComponentEnvironment = require('./ReactComponentEnvironment');
|
|
15
|
+
var ReactCurrentOwner = require('./ReactCurrentOwner');
|
|
16
|
+
var ReactElement = require('./ReactElement');
|
|
17
|
+
var ReactInstanceMap = require('./ReactInstanceMap');
|
|
18
|
+
var ReactPerf = require('./ReactPerf');
|
|
19
|
+
var ReactPropTypeLocations = require('./ReactPropTypeLocations');
|
|
20
|
+
var ReactPropTypeLocationNames = require('./ReactPropTypeLocationNames');
|
|
21
|
+
var ReactReconciler = require('./ReactReconciler');
|
|
22
|
+
var ReactUpdateQueue = require('./ReactUpdateQueue');
|
|
23
|
+
|
|
24
|
+
var assign = require('./Object.assign');
|
|
25
|
+
var emptyObject = require('fbjs/lib/emptyObject');
|
|
26
|
+
var invariant = require('fbjs/lib/invariant');
|
|
27
|
+
var shouldUpdateReactComponent = require('./shouldUpdateReactComponent');
|
|
28
|
+
var warning = require('fbjs/lib/warning');
|
|
33
29
|
|
|
34
30
|
function getDeclarationErrorAddendum(component) {
|
|
35
31
|
var owner = component._currentElement._owner || null;
|
|
@@ -42,6 +38,12 @@ function getDeclarationErrorAddendum(component) {
|
|
|
42
38
|
return '';
|
|
43
39
|
}
|
|
44
40
|
|
|
41
|
+
function StatelessComponent(Component) {}
|
|
42
|
+
StatelessComponent.prototype.render = function () {
|
|
43
|
+
var Component = ReactInstanceMap.get(this)._currentElement.type;
|
|
44
|
+
return new Component(this.props, this.context, this.updater);
|
|
45
|
+
};
|
|
46
|
+
|
|
45
47
|
/**
|
|
46
48
|
* ------------------ The Life-Cycle of a Composite Component ------------------
|
|
47
49
|
*
|
|
@@ -104,7 +106,7 @@ var ReactCompositeComponentMixin = {
|
|
|
104
106
|
|
|
105
107
|
this._context = null;
|
|
106
108
|
this._mountOrder = 0;
|
|
107
|
-
this.
|
|
109
|
+
this._topLevelWrapper = null;
|
|
108
110
|
|
|
109
111
|
// See ReactUpdates and ReactUpdateQueue.
|
|
110
112
|
this._pendingCallbacks = null;
|
|
@@ -127,15 +129,38 @@ var ReactCompositeComponentMixin = {
|
|
|
127
129
|
var publicProps = this._processProps(this._currentElement.props);
|
|
128
130
|
var publicContext = this._processContext(context);
|
|
129
131
|
|
|
130
|
-
var Component =
|
|
132
|
+
var Component = this._currentElement.type;
|
|
131
133
|
|
|
132
134
|
// Initialize the public class
|
|
133
|
-
var inst
|
|
135
|
+
var inst;
|
|
136
|
+
var renderedElement;
|
|
137
|
+
|
|
138
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
139
|
+
ReactCurrentOwner.current = this;
|
|
140
|
+
try {
|
|
141
|
+
inst = new Component(publicProps, publicContext, ReactUpdateQueue);
|
|
142
|
+
} finally {
|
|
143
|
+
ReactCurrentOwner.current = null;
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
inst = new Component(publicProps, publicContext, ReactUpdateQueue);
|
|
147
|
+
}
|
|
134
148
|
|
|
135
|
-
if (
|
|
149
|
+
if (inst === null || inst === false || ReactElement.isValidElement(inst)) {
|
|
150
|
+
renderedElement = inst;
|
|
151
|
+
inst = new StatelessComponent(Component);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
136
155
|
// This will throw later in _renderValidatedComponent, but add an early
|
|
137
156
|
// warning now to help debugging
|
|
138
|
-
|
|
157
|
+
if (inst.render == null) {
|
|
158
|
+
process.env.NODE_ENV !== 'production' ? warning(false, '%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`, returned ' + 'null/false from a stateless component, or tried to render an ' + 'element whose type is a function that isn\'t a React component.', Component.displayName || Component.name || 'Component') : undefined;
|
|
159
|
+
} else {
|
|
160
|
+
// We support ES6 inheriting from React.Component, the module pattern,
|
|
161
|
+
// and stateless components, but not ES6 classes that don't extend
|
|
162
|
+
process.env.NODE_ENV !== 'production' ? warning(Component.isReactClass || !(inst instanceof Component), '%s(...): React component classes must extend React.Component.', Component.displayName || Component.name || 'Component') : undefined;
|
|
163
|
+
}
|
|
139
164
|
}
|
|
140
165
|
|
|
141
166
|
// These should be set up in the constructor, but as a convenience for
|
|
@@ -143,54 +168,51 @@ var ReactCompositeComponentMixin = {
|
|
|
143
168
|
inst.props = publicProps;
|
|
144
169
|
inst.context = publicContext;
|
|
145
170
|
inst.refs = emptyObject;
|
|
171
|
+
inst.updater = ReactUpdateQueue;
|
|
146
172
|
|
|
147
173
|
this._instance = inst;
|
|
148
174
|
|
|
149
175
|
// Store a reference from the instance back to the internal representation
|
|
150
176
|
ReactInstanceMap.set(inst, this);
|
|
151
177
|
|
|
152
|
-
if (
|
|
178
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
153
179
|
// Since plain JS classes are defined without any special initialization
|
|
154
180
|
// logic, we can not catch common errors early. Therefore, we have to
|
|
155
181
|
// catch them here, at initialization time, instead.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
182
|
+
process.env.NODE_ENV !== 'production' ? 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;
|
|
183
|
+
process.env.NODE_ENV !== 'production' ? 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;
|
|
184
|
+
process.env.NODE_ENV !== 'production' ? 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;
|
|
185
|
+
process.env.NODE_ENV !== 'production' ? 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;
|
|
186
|
+
process.env.NODE_ENV !== 'production' ? 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;
|
|
187
|
+
process.env.NODE_ENV !== 'production' ? warning(typeof inst.componentDidUnmount !== 'function', '%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', this.getName() || 'A component') : undefined;
|
|
188
|
+
process.env.NODE_ENV !== 'production' ? warning(typeof inst.componentWillRecieveProps !== 'function', '%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', this.getName() || 'A component') : undefined;
|
|
161
189
|
}
|
|
162
190
|
|
|
163
191
|
var initialState = inst.state;
|
|
164
192
|
if (initialState === undefined) {
|
|
165
193
|
inst.state = initialState = null;
|
|
166
194
|
}
|
|
167
|
-
!(typeof initialState === 'object' && !Array.isArray(initialState)) ?
|
|
195
|
+
!(typeof initialState === 'object' && !Array.isArray(initialState)) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.state: must be set to an object or null', this.getName() || 'ReactCompositeComponent') : invariant(false) : undefined;
|
|
168
196
|
|
|
169
197
|
this._pendingStateQueue = null;
|
|
170
198
|
this._pendingReplaceState = false;
|
|
171
199
|
this._pendingForceUpdate = false;
|
|
172
200
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
inst.componentWillMount();
|
|
180
|
-
// When mounting, calls to `setState` by `componentWillMount` will set
|
|
181
|
-
// `this._pendingStateQueue` without triggering a re-render.
|
|
182
|
-
if (this._pendingStateQueue) {
|
|
183
|
-
inst.state = this._processPendingState(inst.props, inst.context);
|
|
184
|
-
}
|
|
201
|
+
if (inst.componentWillMount) {
|
|
202
|
+
inst.componentWillMount();
|
|
203
|
+
// When mounting, calls to `setState` by `componentWillMount` will set
|
|
204
|
+
// `this._pendingStateQueue` without triggering a re-render.
|
|
205
|
+
if (this._pendingStateQueue) {
|
|
206
|
+
inst.state = this._processPendingState(inst.props, inst.context);
|
|
185
207
|
}
|
|
208
|
+
}
|
|
186
209
|
|
|
210
|
+
// If not a stateless component, we now render
|
|
211
|
+
if (renderedElement === undefined) {
|
|
187
212
|
renderedElement = this._renderValidatedComponent();
|
|
188
|
-
} finally {
|
|
189
|
-
ReactLifeCycle.currentlyMountingInstance = previouslyMounting;
|
|
190
213
|
}
|
|
191
214
|
|
|
192
|
-
this._renderedComponent = this._instantiateReactComponent(renderedElement
|
|
193
|
-
);
|
|
215
|
+
this._renderedComponent = this._instantiateReactComponent(renderedElement);
|
|
194
216
|
|
|
195
217
|
var markup = ReactReconciler.mountComponent(this._renderedComponent, rootID, transaction, this._processChildContext(context));
|
|
196
218
|
if (inst.componentDidMount) {
|
|
@@ -210,19 +232,16 @@ var ReactCompositeComponentMixin = {
|
|
|
210
232
|
var inst = this._instance;
|
|
211
233
|
|
|
212
234
|
if (inst.componentWillUnmount) {
|
|
213
|
-
|
|
214
|
-
ReactLifeCycle.currentlyUnmountingInstance = this;
|
|
215
|
-
try {
|
|
216
|
-
inst.componentWillUnmount();
|
|
217
|
-
} finally {
|
|
218
|
-
ReactLifeCycle.currentlyUnmountingInstance = previouslyUnmounting;
|
|
219
|
-
}
|
|
235
|
+
inst.componentWillUnmount();
|
|
220
236
|
}
|
|
221
237
|
|
|
222
238
|
ReactReconciler.unmountComponent(this._renderedComponent);
|
|
223
239
|
this._renderedComponent = null;
|
|
240
|
+
this._instance = null;
|
|
224
241
|
|
|
225
242
|
// Reset pending fields
|
|
243
|
+
// Even if this component is scheduled for another update in ReactUpdates,
|
|
244
|
+
// it would still be ignored because these fields are reset.
|
|
226
245
|
this._pendingStateQueue = null;
|
|
227
246
|
this._pendingReplaceState = false;
|
|
228
247
|
this._pendingForceUpdate = false;
|
|
@@ -233,6 +252,7 @@ var ReactCompositeComponentMixin = {
|
|
|
233
252
|
// longer accessible.
|
|
234
253
|
this._context = null;
|
|
235
254
|
this._rootNodeID = null;
|
|
255
|
+
this._topLevelWrapper = null;
|
|
236
256
|
|
|
237
257
|
// Delete the reference from the instance to this internal representation
|
|
238
258
|
// which allow the internals to be properly cleaned up even if the user
|
|
@@ -246,22 +266,6 @@ var ReactCompositeComponentMixin = {
|
|
|
246
266
|
// TODO: inst.context = null;
|
|
247
267
|
},
|
|
248
268
|
|
|
249
|
-
/**
|
|
250
|
-
* Schedule a partial update to the props. Only used for internal testing.
|
|
251
|
-
*
|
|
252
|
-
* @param {object} partialProps Subset of the next props.
|
|
253
|
-
* @param {?function} callback Called after props are updated.
|
|
254
|
-
* @final
|
|
255
|
-
* @internal
|
|
256
|
-
*/
|
|
257
|
-
_setPropsInternal: function (partialProps, callback) {
|
|
258
|
-
// This is a deoptimized path. We optimize for always having an element.
|
|
259
|
-
// This creates an extra internal element.
|
|
260
|
-
var element = this._pendingElement || this._currentElement;
|
|
261
|
-
this._pendingElement = ReactElement.cloneAndReplaceProps(element, assign({}, element.props, partialProps));
|
|
262
|
-
ReactUpdates.enqueueUpdate(this, callback);
|
|
263
|
-
},
|
|
264
|
-
|
|
265
269
|
/**
|
|
266
270
|
* Filters the context object to only contain keys specified in
|
|
267
271
|
* `contextTypes`
|
|
@@ -272,7 +276,7 @@ var ReactCompositeComponentMixin = {
|
|
|
272
276
|
*/
|
|
273
277
|
_maskContext: function (context) {
|
|
274
278
|
var maskedContext = null;
|
|
275
|
-
var Component =
|
|
279
|
+
var Component = this._currentElement.type;
|
|
276
280
|
var contextTypes = Component.contextTypes;
|
|
277
281
|
if (!contextTypes) {
|
|
278
282
|
return emptyObject;
|
|
@@ -294,8 +298,8 @@ var ReactCompositeComponentMixin = {
|
|
|
294
298
|
*/
|
|
295
299
|
_processContext: function (context) {
|
|
296
300
|
var maskedContext = this._maskContext(context);
|
|
297
|
-
if (
|
|
298
|
-
var Component =
|
|
301
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
302
|
+
var Component = this._currentElement.type;
|
|
299
303
|
if (Component.contextTypes) {
|
|
300
304
|
this._checkPropTypes(Component.contextTypes, maskedContext, ReactPropTypeLocations.context);
|
|
301
305
|
}
|
|
@@ -309,15 +313,16 @@ var ReactCompositeComponentMixin = {
|
|
|
309
313
|
* @private
|
|
310
314
|
*/
|
|
311
315
|
_processChildContext: function (currentContext) {
|
|
316
|
+
var Component = this._currentElement.type;
|
|
312
317
|
var inst = this._instance;
|
|
313
318
|
var childContext = inst.getChildContext && inst.getChildContext();
|
|
314
319
|
if (childContext) {
|
|
315
|
-
!(typeof
|
|
316
|
-
if (
|
|
317
|
-
this._checkPropTypes(
|
|
320
|
+
!(typeof Component.childContextTypes === 'object') ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.getChildContext(): childContextTypes must be defined in order to ' + 'use getChildContext().', this.getName() || 'ReactCompositeComponent') : invariant(false) : undefined;
|
|
321
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
322
|
+
this._checkPropTypes(Component.childContextTypes, childContext, ReactPropTypeLocations.childContext);
|
|
318
323
|
}
|
|
319
324
|
for (var name in childContext) {
|
|
320
|
-
!(name in
|
|
325
|
+
!(name in Component.childContextTypes) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.getChildContext(): key "%s" is not defined in childContextTypes.', this.getName() || 'ReactCompositeComponent', name) : invariant(false) : undefined;
|
|
321
326
|
}
|
|
322
327
|
return assign({}, currentContext, childContext);
|
|
323
328
|
}
|
|
@@ -334,8 +339,8 @@ var ReactCompositeComponentMixin = {
|
|
|
334
339
|
* @private
|
|
335
340
|
*/
|
|
336
341
|
_processProps: function (newProps) {
|
|
337
|
-
if (
|
|
338
|
-
var Component =
|
|
342
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
343
|
+
var Component = this._currentElement.type;
|
|
339
344
|
if (Component.propTypes) {
|
|
340
345
|
this._checkPropTypes(Component.propTypes, newProps, ReactPropTypeLocations.prop);
|
|
341
346
|
}
|
|
@@ -361,22 +366,22 @@ var ReactCompositeComponentMixin = {
|
|
|
361
366
|
try {
|
|
362
367
|
// This is intentionally an invariant that gets caught. It's the same
|
|
363
368
|
// behavior as without this statement except with a better message.
|
|
364
|
-
!(typeof propTypes[propName] === 'function') ?
|
|
369
|
+
!(typeof propTypes[propName] === 'function') ? process.env.NODE_ENV !== 'production' ? 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;
|
|
365
370
|
error = propTypes[propName](props, propName, componentName, location);
|
|
366
371
|
} catch (ex) {
|
|
367
372
|
error = ex;
|
|
368
373
|
}
|
|
369
374
|
if (error instanceof Error) {
|
|
370
375
|
// We may want to extend this logic for similar errors in
|
|
371
|
-
//
|
|
376
|
+
// top-level render calls, so I'm abstracting it away into
|
|
372
377
|
// a function to minimize refactoring in the future
|
|
373
378
|
var addendum = getDeclarationErrorAddendum(this);
|
|
374
379
|
|
|
375
380
|
if (location === ReactPropTypeLocations.prop) {
|
|
376
381
|
// Preface gives us something to blacklist in warning module
|
|
377
|
-
|
|
382
|
+
process.env.NODE_ENV !== 'production' ? warning(false, 'Failed Composite propType: %s%s', error.message, addendum) : undefined;
|
|
378
383
|
} else {
|
|
379
|
-
|
|
384
|
+
process.env.NODE_ENV !== 'production' ? warning(false, 'Failed Context Types: %s%s', error.message, addendum) : undefined;
|
|
380
385
|
}
|
|
381
386
|
}
|
|
382
387
|
}
|
|
@@ -405,10 +410,6 @@ var ReactCompositeComponentMixin = {
|
|
|
405
410
|
}
|
|
406
411
|
|
|
407
412
|
if (this._pendingStateQueue !== null || this._pendingForceUpdate) {
|
|
408
|
-
if ('production' !== process.env.NODE_ENV) {
|
|
409
|
-
ReactElementValidator.checkAndWarnForMutatedProps(this._currentElement);
|
|
410
|
-
}
|
|
411
|
-
|
|
412
413
|
this.updateComponent(transaction, this._currentElement, this._currentElement, this._context, this._context);
|
|
413
414
|
}
|
|
414
415
|
},
|
|
@@ -431,14 +432,16 @@ var ReactCompositeComponentMixin = {
|
|
|
431
432
|
updateComponent: function (transaction, prevParentElement, nextParentElement, prevUnmaskedContext, nextUnmaskedContext) {
|
|
432
433
|
var inst = this._instance;
|
|
433
434
|
|
|
434
|
-
var nextContext = inst.context;
|
|
435
|
-
var nextProps
|
|
435
|
+
var nextContext = this._context === nextUnmaskedContext ? inst.context : this._processContext(nextUnmaskedContext);
|
|
436
|
+
var nextProps;
|
|
436
437
|
|
|
437
438
|
// Distinguish between a props update versus a simple state update
|
|
438
|
-
if (prevParentElement
|
|
439
|
-
|
|
439
|
+
if (prevParentElement === nextParentElement) {
|
|
440
|
+
// Skip checking prop types again -- we don't read inst.props to avoid
|
|
441
|
+
// warning for DOM component props in this upgrade
|
|
442
|
+
nextProps = nextParentElement.props;
|
|
443
|
+
} else {
|
|
440
444
|
nextProps = this._processProps(nextParentElement.props);
|
|
441
|
-
|
|
442
445
|
// An update here will schedule an update but immediately set
|
|
443
446
|
// _pendingStateQueue which will ensure that any state updates gets
|
|
444
447
|
// immediately reconciled instead of waiting for the next batch.
|
|
@@ -452,8 +455,8 @@ var ReactCompositeComponentMixin = {
|
|
|
452
455
|
|
|
453
456
|
var shouldUpdate = this._pendingForceUpdate || !inst.shouldComponentUpdate || inst.shouldComponentUpdate(nextProps, nextState, nextContext);
|
|
454
457
|
|
|
455
|
-
if (
|
|
456
|
-
|
|
458
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
459
|
+
process.env.NODE_ENV !== 'production' ? warning(typeof shouldUpdate !== 'undefined', '%s.shouldComponentUpdate(): Returned undefined instead of a ' + 'boolean value. Make sure to return true or false.', this.getName() || 'ReactCompositeComponent') : undefined;
|
|
457
460
|
}
|
|
458
461
|
|
|
459
462
|
if (shouldUpdate) {
|
|
@@ -510,9 +513,15 @@ var ReactCompositeComponentMixin = {
|
|
|
510
513
|
_performComponentUpdate: function (nextElement, nextProps, nextState, nextContext, transaction, unmaskedContext) {
|
|
511
514
|
var inst = this._instance;
|
|
512
515
|
|
|
513
|
-
var
|
|
514
|
-
var
|
|
515
|
-
var
|
|
516
|
+
var hasComponentDidUpdate = Boolean(inst.componentDidUpdate);
|
|
517
|
+
var prevProps;
|
|
518
|
+
var prevState;
|
|
519
|
+
var prevContext;
|
|
520
|
+
if (hasComponentDidUpdate) {
|
|
521
|
+
prevProps = inst.props;
|
|
522
|
+
prevState = inst.state;
|
|
523
|
+
prevContext = inst.context;
|
|
524
|
+
}
|
|
516
525
|
|
|
517
526
|
if (inst.componentWillUpdate) {
|
|
518
527
|
inst.componentWillUpdate(nextProps, nextState, nextContext);
|
|
@@ -526,7 +535,7 @@ var ReactCompositeComponentMixin = {
|
|
|
526
535
|
|
|
527
536
|
this._updateRenderedComponent(transaction, unmaskedContext);
|
|
528
537
|
|
|
529
|
-
if (
|
|
538
|
+
if (hasComponentDidUpdate) {
|
|
530
539
|
transaction.getReactMountReady().enqueue(inst.componentDidUpdate.bind(inst, prevProps, prevState, prevContext), inst);
|
|
531
540
|
}
|
|
532
541
|
},
|
|
@@ -549,7 +558,7 @@ var ReactCompositeComponentMixin = {
|
|
|
549
558
|
var prevComponentID = prevComponentInstance._rootNodeID;
|
|
550
559
|
ReactReconciler.unmountComponent(prevComponentInstance);
|
|
551
560
|
|
|
552
|
-
this._renderedComponent = this._instantiateReactComponent(nextRenderedElement
|
|
561
|
+
this._renderedComponent = this._instantiateReactComponent(nextRenderedElement);
|
|
553
562
|
var nextMarkup = ReactReconciler.mountComponent(this._renderedComponent, thisID, transaction, this._processChildContext(context));
|
|
554
563
|
this._replaceNodeWithMarkupByID(prevComponentID, nextMarkup);
|
|
555
564
|
}
|
|
@@ -568,7 +577,7 @@ var ReactCompositeComponentMixin = {
|
|
|
568
577
|
_renderValidatedComponentWithoutOwnerOrContext: function () {
|
|
569
578
|
var inst = this._instance;
|
|
570
579
|
var renderedComponent = inst.render();
|
|
571
|
-
if (
|
|
580
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
572
581
|
// We allow auto-mocks to proceed as if they're returning null.
|
|
573
582
|
if (typeof renderedComponent === 'undefined' && inst.render._isMockFunction) {
|
|
574
583
|
// This is probably bad practice. Consider warning here and
|
|
@@ -585,18 +594,15 @@ var ReactCompositeComponentMixin = {
|
|
|
585
594
|
*/
|
|
586
595
|
_renderValidatedComponent: function () {
|
|
587
596
|
var renderedComponent;
|
|
588
|
-
var previousContext = ReactContext.current;
|
|
589
|
-
ReactContext.current = this._processChildContext(this._currentElement._context);
|
|
590
597
|
ReactCurrentOwner.current = this;
|
|
591
598
|
try {
|
|
592
599
|
renderedComponent = this._renderValidatedComponentWithoutOwnerOrContext();
|
|
593
600
|
} finally {
|
|
594
|
-
ReactContext.current = previousContext;
|
|
595
601
|
ReactCurrentOwner.current = null;
|
|
596
602
|
}
|
|
597
603
|
!(
|
|
598
604
|
// TODO: An `isValidNode` function would probably be more appropriate
|
|
599
|
-
|
|
605
|
+
renderedComponent === null || renderedComponent === false || ReactElement.isValidElement(renderedComponent)) ? process.env.NODE_ENV !== 'production' ? 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;
|
|
600
606
|
return renderedComponent;
|
|
601
607
|
},
|
|
602
608
|
|
|
@@ -610,6 +616,7 @@ var ReactCompositeComponentMixin = {
|
|
|
610
616
|
*/
|
|
611
617
|
attachRef: function (ref, component) {
|
|
612
618
|
var inst = this.getPublicInstance();
|
|
619
|
+
!(inst != null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Stateless function components cannot have refs.') : invariant(false) : undefined;
|
|
613
620
|
var refs = inst.refs === emptyObject ? inst.refs = {} : inst.refs;
|
|
614
621
|
refs[ref] = component.getPublicInstance();
|
|
615
622
|
},
|
|
@@ -640,14 +647,18 @@ var ReactCompositeComponentMixin = {
|
|
|
640
647
|
|
|
641
648
|
/**
|
|
642
649
|
* Get the publicly accessible representation of this component - i.e. what
|
|
643
|
-
* is exposed by refs and returned by
|
|
650
|
+
* is exposed by refs and returned by render. Can be null for stateless
|
|
644
651
|
* components.
|
|
645
652
|
*
|
|
646
653
|
* @return {ReactComponent} the public component instance.
|
|
647
654
|
* @internal
|
|
648
655
|
*/
|
|
649
656
|
getPublicInstance: function () {
|
|
650
|
-
|
|
657
|
+
var inst = this._instance;
|
|
658
|
+
if (inst instanceof StatelessComponent) {
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
661
|
+
return inst;
|
|
651
662
|
},
|
|
652
663
|
|
|
653
664
|
// Stub
|