react 15.5.2 → 15.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react-with-addons.js +1455 -1316
- package/dist/react-with-addons.min.js +3 -3
- package/dist/react.js +1595 -1439
- package/dist/react.min.js +2 -2
- package/lib/React.js +45 -17
- package/lib/{ReactComponent.js → ReactBaseClasses.js} +29 -4
- package/lib/ReactCSSTransitionGroup.js +1 -1
- package/lib/ReactComponentTreeHook.js +49 -4
- package/lib/ReactCurrentOwner.js +0 -2
- package/lib/ReactDOMFactories.js +0 -1
- package/lib/ReactElementValidator.js +6 -4
- package/lib/ReactLink.js +0 -20
- package/lib/ReactNoopUpdateQueue.js +0 -1
- package/lib/ReactTransitionGroup.js +4 -1
- package/lib/ReactVersion.js +1 -1
- package/lib/createClass.js +22 -0
- package/lib/deprecated.js +3 -3
- package/lib/lowPriorityWarning.js +64 -0
- package/lib/traverseAllChildren.js +1 -1
- package/package.json +3 -2
- package/lib/ReactClass.js +0 -722
- package/lib/ReactPureComponent.js +0 -41
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2014-2015, Facebook, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Forked from fbjs/warning:
|
|
15
|
+
* https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
|
|
16
|
+
*
|
|
17
|
+
* Only change is we use console.warn instead of console.error,
|
|
18
|
+
* and do nothing when 'console' is not supported.
|
|
19
|
+
* This really simplifies the code.
|
|
20
|
+
* ---
|
|
21
|
+
* Similar to invariant but only logs a warning if the condition is not met.
|
|
22
|
+
* This can be used to log issues in development environments in critical
|
|
23
|
+
* paths. Removing the logging code for production environments will keep the
|
|
24
|
+
* same logic and follow the same code paths.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
var lowPriorityWarning = function () {};
|
|
28
|
+
|
|
29
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
30
|
+
var printWarning = function (format) {
|
|
31
|
+
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
32
|
+
args[_key - 1] = arguments[_key];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var argIndex = 0;
|
|
36
|
+
var message = 'Warning: ' + format.replace(/%s/g, function () {
|
|
37
|
+
return args[argIndex++];
|
|
38
|
+
});
|
|
39
|
+
if (typeof console !== 'undefined') {
|
|
40
|
+
console.warn(message);
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
// --- Welcome to debugging React ---
|
|
44
|
+
// This error was thrown as a convenience so that you can use this stack
|
|
45
|
+
// to find the callsite that caused this warning to fire.
|
|
46
|
+
throw new Error(message);
|
|
47
|
+
} catch (x) {}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
lowPriorityWarning = function (condition, format) {
|
|
51
|
+
if (format === undefined) {
|
|
52
|
+
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
|
|
53
|
+
}
|
|
54
|
+
if (!condition) {
|
|
55
|
+
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
56
|
+
args[_key2 - 2] = arguments[_key2];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
printWarning.apply(undefined, [format].concat(args));
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = lowPriorityWarning;
|
|
@@ -131,7 +131,7 @@ function traverseAllChildrenImpl(children, nameSoFar, callback, traverseContext)
|
|
|
131
131
|
if (process.env.NODE_ENV !== 'production') {
|
|
132
132
|
addendum = ' If you meant to render a collection of children, use an array ' + 'instead or wrap the object using createFragment(object) from the ' + 'React add-ons.';
|
|
133
133
|
if (children._isReactElement) {
|
|
134
|
-
addendum =
|
|
134
|
+
addendum = " It looks like you're using an element created by a different " + 'version of React. Make sure to use only one copy of React.';
|
|
135
135
|
}
|
|
136
136
|
if (ReactCurrentOwner.current) {
|
|
137
137
|
var name = ReactCurrentOwner.current.getName();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react",
|
|
3
3
|
"description": "React is a JavaScript library for building user interfaces.",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.6.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react"
|
|
7
7
|
],
|
|
@@ -23,10 +23,11 @@
|
|
|
23
23
|
"node": ">=0.10.0"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"create-react-class": "^15.5.2",
|
|
26
27
|
"fbjs": "^0.8.9",
|
|
27
28
|
"loose-envify": "^1.1.0",
|
|
28
29
|
"object-assign": "^4.1.0",
|
|
29
|
-
"prop-types": "^15.5.
|
|
30
|
+
"prop-types": "^15.5.7"
|
|
30
31
|
},
|
|
31
32
|
"browserify": {
|
|
32
33
|
"transform": [
|
package/lib/ReactClass.js
DELETED
|
@@ -1,722 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
var _prodInvariant = require('./reactProdInvariant'),
|
|
14
|
-
_assign = require('object-assign');
|
|
15
|
-
|
|
16
|
-
var ReactComponent = require('./ReactComponent');
|
|
17
|
-
var ReactElement = require('./ReactElement');
|
|
18
|
-
var ReactPropTypeLocationNames = require('./ReactPropTypeLocationNames');
|
|
19
|
-
var ReactNoopUpdateQueue = require('./ReactNoopUpdateQueue');
|
|
20
|
-
|
|
21
|
-
var emptyObject = require('fbjs/lib/emptyObject');
|
|
22
|
-
var invariant = require('fbjs/lib/invariant');
|
|
23
|
-
var warning = require('fbjs/lib/warning');
|
|
24
|
-
|
|
25
|
-
var MIXINS_KEY = 'mixins';
|
|
26
|
-
|
|
27
|
-
// Helper function to allow the creation of anonymous functions which do not
|
|
28
|
-
// have .name set to the name of the variable being assigned to.
|
|
29
|
-
function identity(fn) {
|
|
30
|
-
return fn;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Policies that describe methods in `ReactClassInterface`.
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var injectedMixins = [];
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Composite components are higher-level components that compose other composite
|
|
42
|
-
* or host components.
|
|
43
|
-
*
|
|
44
|
-
* To create a new type of `ReactClass`, pass a specification of
|
|
45
|
-
* your new class to `React.createClass`. The only requirement of your class
|
|
46
|
-
* specification is that you implement a `render` method.
|
|
47
|
-
*
|
|
48
|
-
* var MyComponent = React.createClass({
|
|
49
|
-
* render: function() {
|
|
50
|
-
* return <div>Hello World</div>;
|
|
51
|
-
* }
|
|
52
|
-
* });
|
|
53
|
-
*
|
|
54
|
-
* The class specification supports a specific protocol of methods that have
|
|
55
|
-
* special meaning (e.g. `render`). See `ReactClassInterface` for
|
|
56
|
-
* more the comprehensive protocol. Any other properties and methods in the
|
|
57
|
-
* class specification will be available on the prototype.
|
|
58
|
-
*
|
|
59
|
-
* @interface ReactClassInterface
|
|
60
|
-
* @internal
|
|
61
|
-
*/
|
|
62
|
-
var ReactClassInterface = {
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* An array of Mixin objects to include when defining your component.
|
|
66
|
-
*
|
|
67
|
-
* @type {array}
|
|
68
|
-
* @optional
|
|
69
|
-
*/
|
|
70
|
-
mixins: 'DEFINE_MANY',
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* An object containing properties and methods that should be defined on
|
|
74
|
-
* the component's constructor instead of its prototype (static methods).
|
|
75
|
-
*
|
|
76
|
-
* @type {object}
|
|
77
|
-
* @optional
|
|
78
|
-
*/
|
|
79
|
-
statics: 'DEFINE_MANY',
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Definition of prop types for this component.
|
|
83
|
-
*
|
|
84
|
-
* @type {object}
|
|
85
|
-
* @optional
|
|
86
|
-
*/
|
|
87
|
-
propTypes: 'DEFINE_MANY',
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Definition of context types for this component.
|
|
91
|
-
*
|
|
92
|
-
* @type {object}
|
|
93
|
-
* @optional
|
|
94
|
-
*/
|
|
95
|
-
contextTypes: 'DEFINE_MANY',
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Definition of context types this component sets for its children.
|
|
99
|
-
*
|
|
100
|
-
* @type {object}
|
|
101
|
-
* @optional
|
|
102
|
-
*/
|
|
103
|
-
childContextTypes: 'DEFINE_MANY',
|
|
104
|
-
|
|
105
|
-
// ==== Definition methods ====
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Invoked when the component is mounted. Values in the mapping will be set on
|
|
109
|
-
* `this.props` if that prop is not specified (i.e. using an `in` check).
|
|
110
|
-
*
|
|
111
|
-
* This method is invoked before `getInitialState` and therefore cannot rely
|
|
112
|
-
* on `this.state` or use `this.setState`.
|
|
113
|
-
*
|
|
114
|
-
* @return {object}
|
|
115
|
-
* @optional
|
|
116
|
-
*/
|
|
117
|
-
getDefaultProps: 'DEFINE_MANY_MERGED',
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Invoked once before the component is mounted. The return value will be used
|
|
121
|
-
* as the initial value of `this.state`.
|
|
122
|
-
*
|
|
123
|
-
* getInitialState: function() {
|
|
124
|
-
* return {
|
|
125
|
-
* isOn: false,
|
|
126
|
-
* fooBaz: new BazFoo()
|
|
127
|
-
* }
|
|
128
|
-
* }
|
|
129
|
-
*
|
|
130
|
-
* @return {object}
|
|
131
|
-
* @optional
|
|
132
|
-
*/
|
|
133
|
-
getInitialState: 'DEFINE_MANY_MERGED',
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* @return {object}
|
|
137
|
-
* @optional
|
|
138
|
-
*/
|
|
139
|
-
getChildContext: 'DEFINE_MANY_MERGED',
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Uses props from `this.props` and state from `this.state` to render the
|
|
143
|
-
* structure of the component.
|
|
144
|
-
*
|
|
145
|
-
* No guarantees are made about when or how often this method is invoked, so
|
|
146
|
-
* it must not have side effects.
|
|
147
|
-
*
|
|
148
|
-
* render: function() {
|
|
149
|
-
* var name = this.props.name;
|
|
150
|
-
* return <div>Hello, {name}!</div>;
|
|
151
|
-
* }
|
|
152
|
-
*
|
|
153
|
-
* @return {ReactComponent}
|
|
154
|
-
* @required
|
|
155
|
-
*/
|
|
156
|
-
render: 'DEFINE_ONCE',
|
|
157
|
-
|
|
158
|
-
// ==== Delegate methods ====
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Invoked when the component is initially created and about to be mounted.
|
|
162
|
-
* This may have side effects, but any external subscriptions or data created
|
|
163
|
-
* by this method must be cleaned up in `componentWillUnmount`.
|
|
164
|
-
*
|
|
165
|
-
* @optional
|
|
166
|
-
*/
|
|
167
|
-
componentWillMount: 'DEFINE_MANY',
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Invoked when the component has been mounted and has a DOM representation.
|
|
171
|
-
* However, there is no guarantee that the DOM node is in the document.
|
|
172
|
-
*
|
|
173
|
-
* Use this as an opportunity to operate on the DOM when the component has
|
|
174
|
-
* been mounted (initialized and rendered) for the first time.
|
|
175
|
-
*
|
|
176
|
-
* @param {DOMElement} rootNode DOM element representing the component.
|
|
177
|
-
* @optional
|
|
178
|
-
*/
|
|
179
|
-
componentDidMount: 'DEFINE_MANY',
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Invoked before the component receives new props.
|
|
183
|
-
*
|
|
184
|
-
* Use this as an opportunity to react to a prop transition by updating the
|
|
185
|
-
* state using `this.setState`. Current props are accessed via `this.props`.
|
|
186
|
-
*
|
|
187
|
-
* componentWillReceiveProps: function(nextProps, nextContext) {
|
|
188
|
-
* this.setState({
|
|
189
|
-
* likesIncreasing: nextProps.likeCount > this.props.likeCount
|
|
190
|
-
* });
|
|
191
|
-
* }
|
|
192
|
-
*
|
|
193
|
-
* NOTE: There is no equivalent `componentWillReceiveState`. An incoming prop
|
|
194
|
-
* transition may cause a state change, but the opposite is not true. If you
|
|
195
|
-
* need it, you are probably looking for `componentWillUpdate`.
|
|
196
|
-
*
|
|
197
|
-
* @param {object} nextProps
|
|
198
|
-
* @optional
|
|
199
|
-
*/
|
|
200
|
-
componentWillReceiveProps: 'DEFINE_MANY',
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Invoked while deciding if the component should be updated as a result of
|
|
204
|
-
* receiving new props, state and/or context.
|
|
205
|
-
*
|
|
206
|
-
* Use this as an opportunity to `return false` when you're certain that the
|
|
207
|
-
* transition to the new props/state/context will not require a component
|
|
208
|
-
* update.
|
|
209
|
-
*
|
|
210
|
-
* shouldComponentUpdate: function(nextProps, nextState, nextContext) {
|
|
211
|
-
* return !equal(nextProps, this.props) ||
|
|
212
|
-
* !equal(nextState, this.state) ||
|
|
213
|
-
* !equal(nextContext, this.context);
|
|
214
|
-
* }
|
|
215
|
-
*
|
|
216
|
-
* @param {object} nextProps
|
|
217
|
-
* @param {?object} nextState
|
|
218
|
-
* @param {?object} nextContext
|
|
219
|
-
* @return {boolean} True if the component should update.
|
|
220
|
-
* @optional
|
|
221
|
-
*/
|
|
222
|
-
shouldComponentUpdate: 'DEFINE_ONCE',
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Invoked when the component is about to update due to a transition from
|
|
226
|
-
* `this.props`, `this.state` and `this.context` to `nextProps`, `nextState`
|
|
227
|
-
* and `nextContext`.
|
|
228
|
-
*
|
|
229
|
-
* Use this as an opportunity to perform preparation before an update occurs.
|
|
230
|
-
*
|
|
231
|
-
* NOTE: You **cannot** use `this.setState()` in this method.
|
|
232
|
-
*
|
|
233
|
-
* @param {object} nextProps
|
|
234
|
-
* @param {?object} nextState
|
|
235
|
-
* @param {?object} nextContext
|
|
236
|
-
* @param {ReactReconcileTransaction} transaction
|
|
237
|
-
* @optional
|
|
238
|
-
*/
|
|
239
|
-
componentWillUpdate: 'DEFINE_MANY',
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Invoked when the component's DOM representation has been updated.
|
|
243
|
-
*
|
|
244
|
-
* Use this as an opportunity to operate on the DOM when the component has
|
|
245
|
-
* been updated.
|
|
246
|
-
*
|
|
247
|
-
* @param {object} prevProps
|
|
248
|
-
* @param {?object} prevState
|
|
249
|
-
* @param {?object} prevContext
|
|
250
|
-
* @param {DOMElement} rootNode DOM element representing the component.
|
|
251
|
-
* @optional
|
|
252
|
-
*/
|
|
253
|
-
componentDidUpdate: 'DEFINE_MANY',
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Invoked when the component is about to be removed from its parent and have
|
|
257
|
-
* its DOM representation destroyed.
|
|
258
|
-
*
|
|
259
|
-
* Use this as an opportunity to deallocate any external resources.
|
|
260
|
-
*
|
|
261
|
-
* NOTE: There is no `componentDidUnmount` since your component will have been
|
|
262
|
-
* destroyed by that point.
|
|
263
|
-
*
|
|
264
|
-
* @optional
|
|
265
|
-
*/
|
|
266
|
-
componentWillUnmount: 'DEFINE_MANY',
|
|
267
|
-
|
|
268
|
-
// ==== Advanced methods ====
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Updates the component's currently mounted DOM representation.
|
|
272
|
-
*
|
|
273
|
-
* By default, this implements React's rendering and reconciliation algorithm.
|
|
274
|
-
* Sophisticated clients may wish to override this.
|
|
275
|
-
*
|
|
276
|
-
* @param {ReactReconcileTransaction} transaction
|
|
277
|
-
* @internal
|
|
278
|
-
* @overridable
|
|
279
|
-
*/
|
|
280
|
-
updateComponent: 'OVERRIDE_BASE'
|
|
281
|
-
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Mapping from class specification keys to special processing functions.
|
|
286
|
-
*
|
|
287
|
-
* Although these are declared like instance properties in the specification
|
|
288
|
-
* when defining classes using `React.createClass`, they are actually static
|
|
289
|
-
* and are accessible on the constructor instead of the prototype. Despite
|
|
290
|
-
* being static, they must be defined outside of the "statics" key under
|
|
291
|
-
* which all other static methods are defined.
|
|
292
|
-
*/
|
|
293
|
-
var RESERVED_SPEC_KEYS = {
|
|
294
|
-
displayName: function (Constructor, displayName) {
|
|
295
|
-
Constructor.displayName = displayName;
|
|
296
|
-
},
|
|
297
|
-
mixins: function (Constructor, mixins) {
|
|
298
|
-
if (mixins) {
|
|
299
|
-
for (var i = 0; i < mixins.length; i++) {
|
|
300
|
-
mixSpecIntoComponent(Constructor, mixins[i]);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
},
|
|
304
|
-
childContextTypes: function (Constructor, childContextTypes) {
|
|
305
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
306
|
-
validateTypeDef(Constructor, childContextTypes, 'childContext');
|
|
307
|
-
}
|
|
308
|
-
Constructor.childContextTypes = _assign({}, Constructor.childContextTypes, childContextTypes);
|
|
309
|
-
},
|
|
310
|
-
contextTypes: function (Constructor, contextTypes) {
|
|
311
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
312
|
-
validateTypeDef(Constructor, contextTypes, 'context');
|
|
313
|
-
}
|
|
314
|
-
Constructor.contextTypes = _assign({}, Constructor.contextTypes, contextTypes);
|
|
315
|
-
},
|
|
316
|
-
/**
|
|
317
|
-
* Special case getDefaultProps which should move into statics but requires
|
|
318
|
-
* automatic merging.
|
|
319
|
-
*/
|
|
320
|
-
getDefaultProps: function (Constructor, getDefaultProps) {
|
|
321
|
-
if (Constructor.getDefaultProps) {
|
|
322
|
-
Constructor.getDefaultProps = createMergedResultFunction(Constructor.getDefaultProps, getDefaultProps);
|
|
323
|
-
} else {
|
|
324
|
-
Constructor.getDefaultProps = getDefaultProps;
|
|
325
|
-
}
|
|
326
|
-
},
|
|
327
|
-
propTypes: function (Constructor, propTypes) {
|
|
328
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
329
|
-
validateTypeDef(Constructor, propTypes, 'prop');
|
|
330
|
-
}
|
|
331
|
-
Constructor.propTypes = _assign({}, Constructor.propTypes, propTypes);
|
|
332
|
-
},
|
|
333
|
-
statics: function (Constructor, statics) {
|
|
334
|
-
mixStaticSpecIntoComponent(Constructor, statics);
|
|
335
|
-
},
|
|
336
|
-
autobind: function () {} };
|
|
337
|
-
|
|
338
|
-
function validateTypeDef(Constructor, typeDef, location) {
|
|
339
|
-
for (var propName in typeDef) {
|
|
340
|
-
if (typeDef.hasOwnProperty(propName)) {
|
|
341
|
-
// use a warning instead of an invariant so components
|
|
342
|
-
// don't show up in prod but only in __DEV__
|
|
343
|
-
process.env.NODE_ENV !== 'production' ? warning(typeof typeDef[propName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', Constructor.displayName || 'ReactClass', ReactPropTypeLocationNames[location], propName) : void 0;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
function validateMethodOverride(isAlreadyDefined, name) {
|
|
349
|
-
var specPolicy = ReactClassInterface.hasOwnProperty(name) ? ReactClassInterface[name] : null;
|
|
350
|
-
|
|
351
|
-
// Disallow overriding of base class methods unless explicitly allowed.
|
|
352
|
-
if (ReactClassMixin.hasOwnProperty(name)) {
|
|
353
|
-
!(specPolicy === 'OVERRIDE_BASE') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClassInterface: You are attempting to override `%s` from your class specification. Ensure that your method names do not overlap with React methods.', name) : _prodInvariant('73', name) : void 0;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
// Disallow defining methods more than once unless explicitly allowed.
|
|
357
|
-
if (isAlreadyDefined) {
|
|
358
|
-
!(specPolicy === 'DEFINE_MANY' || specPolicy === 'DEFINE_MANY_MERGED') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClassInterface: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.', name) : _prodInvariant('74', name) : void 0;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Mixin helper which handles policy validation and reserved
|
|
364
|
-
* specification keys when building React classes.
|
|
365
|
-
*/
|
|
366
|
-
function mixSpecIntoComponent(Constructor, spec) {
|
|
367
|
-
if (!spec) {
|
|
368
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
369
|
-
var typeofSpec = typeof spec;
|
|
370
|
-
var isMixinValid = typeofSpec === 'object' && spec !== null;
|
|
371
|
-
|
|
372
|
-
process.env.NODE_ENV !== 'production' ? warning(isMixinValid, '%s: You\'re attempting to include a mixin that is either null ' + 'or not an object. Check the mixins included by the component, ' + 'as well as any mixins they include themselves. ' + 'Expected object but got %s.', Constructor.displayName || 'ReactClass', spec === null ? null : typeofSpec) : void 0;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
!(typeof spec !== 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClass: You\'re attempting to use a component class or function as a mixin. Instead, just use a regular object.') : _prodInvariant('75') : void 0;
|
|
379
|
-
!!ReactElement.isValidElement(spec) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClass: You\'re attempting to use a component as a mixin. Instead, just use a regular object.') : _prodInvariant('76') : void 0;
|
|
380
|
-
|
|
381
|
-
var proto = Constructor.prototype;
|
|
382
|
-
var autoBindPairs = proto.__reactAutoBindPairs;
|
|
383
|
-
|
|
384
|
-
// By handling mixins before any other properties, we ensure the same
|
|
385
|
-
// chaining order is applied to methods with DEFINE_MANY policy, whether
|
|
386
|
-
// mixins are listed before or after these methods in the spec.
|
|
387
|
-
if (spec.hasOwnProperty(MIXINS_KEY)) {
|
|
388
|
-
RESERVED_SPEC_KEYS.mixins(Constructor, spec.mixins);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
for (var name in spec) {
|
|
392
|
-
if (!spec.hasOwnProperty(name)) {
|
|
393
|
-
continue;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
if (name === MIXINS_KEY) {
|
|
397
|
-
// We have already handled mixins in a special case above.
|
|
398
|
-
continue;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
var property = spec[name];
|
|
402
|
-
var isAlreadyDefined = proto.hasOwnProperty(name);
|
|
403
|
-
validateMethodOverride(isAlreadyDefined, name);
|
|
404
|
-
|
|
405
|
-
if (RESERVED_SPEC_KEYS.hasOwnProperty(name)) {
|
|
406
|
-
RESERVED_SPEC_KEYS[name](Constructor, property);
|
|
407
|
-
} else {
|
|
408
|
-
// Setup methods on prototype:
|
|
409
|
-
// The following member methods should not be automatically bound:
|
|
410
|
-
// 1. Expected ReactClass methods (in the "interface").
|
|
411
|
-
// 2. Overridden methods (that were mixed in).
|
|
412
|
-
var isReactClassMethod = ReactClassInterface.hasOwnProperty(name);
|
|
413
|
-
var isFunction = typeof property === 'function';
|
|
414
|
-
var shouldAutoBind = isFunction && !isReactClassMethod && !isAlreadyDefined && spec.autobind !== false;
|
|
415
|
-
|
|
416
|
-
if (shouldAutoBind) {
|
|
417
|
-
autoBindPairs.push(name, property);
|
|
418
|
-
proto[name] = property;
|
|
419
|
-
} else {
|
|
420
|
-
if (isAlreadyDefined) {
|
|
421
|
-
var specPolicy = ReactClassInterface[name];
|
|
422
|
-
|
|
423
|
-
// These cases should already be caught by validateMethodOverride.
|
|
424
|
-
!(isReactClassMethod && (specPolicy === 'DEFINE_MANY_MERGED' || specPolicy === 'DEFINE_MANY')) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClass: Unexpected spec policy %s for key %s when mixing in component specs.', specPolicy, name) : _prodInvariant('77', specPolicy, name) : void 0;
|
|
425
|
-
|
|
426
|
-
// For methods which are defined more than once, call the existing
|
|
427
|
-
// methods before calling the new property, merging if appropriate.
|
|
428
|
-
if (specPolicy === 'DEFINE_MANY_MERGED') {
|
|
429
|
-
proto[name] = createMergedResultFunction(proto[name], property);
|
|
430
|
-
} else if (specPolicy === 'DEFINE_MANY') {
|
|
431
|
-
proto[name] = createChainedFunction(proto[name], property);
|
|
432
|
-
}
|
|
433
|
-
} else {
|
|
434
|
-
proto[name] = property;
|
|
435
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
436
|
-
// Add verbose displayName to the function, which helps when looking
|
|
437
|
-
// at profiling tools.
|
|
438
|
-
if (typeof property === 'function' && spec.displayName) {
|
|
439
|
-
proto[name].displayName = spec.displayName + '_' + name;
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
function mixStaticSpecIntoComponent(Constructor, statics) {
|
|
449
|
-
if (!statics) {
|
|
450
|
-
return;
|
|
451
|
-
}
|
|
452
|
-
for (var name in statics) {
|
|
453
|
-
var property = statics[name];
|
|
454
|
-
if (!statics.hasOwnProperty(name)) {
|
|
455
|
-
continue;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
var isReserved = name in RESERVED_SPEC_KEYS;
|
|
459
|
-
!!isReserved ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClass: You are attempting to define a reserved property, `%s`, that shouldn\'t be on the "statics" key. Define it as an instance property instead; it will still be accessible on the constructor.', name) : _prodInvariant('78', name) : void 0;
|
|
460
|
-
|
|
461
|
-
var isInherited = name in Constructor;
|
|
462
|
-
!!isInherited ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactClass: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.', name) : _prodInvariant('79', name) : void 0;
|
|
463
|
-
Constructor[name] = property;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
/**
|
|
468
|
-
* Merge two objects, but throw if both contain the same key.
|
|
469
|
-
*
|
|
470
|
-
* @param {object} one The first object, which is mutated.
|
|
471
|
-
* @param {object} two The second object
|
|
472
|
-
* @return {object} one after it has been mutated to contain everything in two.
|
|
473
|
-
*/
|
|
474
|
-
function mergeIntoWithNoDuplicateKeys(one, two) {
|
|
475
|
-
!(one && two && typeof one === 'object' && typeof two === 'object') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.') : _prodInvariant('80') : void 0;
|
|
476
|
-
|
|
477
|
-
for (var key in two) {
|
|
478
|
-
if (two.hasOwnProperty(key)) {
|
|
479
|
-
!(one[key] === undefined) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'mergeIntoWithNoDuplicateKeys(): Tried to merge two objects with the same key: `%s`. This conflict may be due to a mixin; in particular, this may be caused by two getInitialState() or getDefaultProps() methods returning objects with clashing keys.', key) : _prodInvariant('81', key) : void 0;
|
|
480
|
-
one[key] = two[key];
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
return one;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* Creates a function that invokes two functions and merges their return values.
|
|
488
|
-
*
|
|
489
|
-
* @param {function} one Function to invoke first.
|
|
490
|
-
* @param {function} two Function to invoke second.
|
|
491
|
-
* @return {function} Function that invokes the two argument functions.
|
|
492
|
-
* @private
|
|
493
|
-
*/
|
|
494
|
-
function createMergedResultFunction(one, two) {
|
|
495
|
-
return function mergedResult() {
|
|
496
|
-
var a = one.apply(this, arguments);
|
|
497
|
-
var b = two.apply(this, arguments);
|
|
498
|
-
if (a == null) {
|
|
499
|
-
return b;
|
|
500
|
-
} else if (b == null) {
|
|
501
|
-
return a;
|
|
502
|
-
}
|
|
503
|
-
var c = {};
|
|
504
|
-
mergeIntoWithNoDuplicateKeys(c, a);
|
|
505
|
-
mergeIntoWithNoDuplicateKeys(c, b);
|
|
506
|
-
return c;
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
/**
|
|
511
|
-
* Creates a function that invokes two functions and ignores their return vales.
|
|
512
|
-
*
|
|
513
|
-
* @param {function} one Function to invoke first.
|
|
514
|
-
* @param {function} two Function to invoke second.
|
|
515
|
-
* @return {function} Function that invokes the two argument functions.
|
|
516
|
-
* @private
|
|
517
|
-
*/
|
|
518
|
-
function createChainedFunction(one, two) {
|
|
519
|
-
return function chainedFunction() {
|
|
520
|
-
one.apply(this, arguments);
|
|
521
|
-
two.apply(this, arguments);
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
/**
|
|
526
|
-
* Binds a method to the component.
|
|
527
|
-
*
|
|
528
|
-
* @param {object} component Component whose method is going to be bound.
|
|
529
|
-
* @param {function} method Method to be bound.
|
|
530
|
-
* @return {function} The bound method.
|
|
531
|
-
*/
|
|
532
|
-
function bindAutoBindMethod(component, method) {
|
|
533
|
-
var boundMethod = method.bind(component);
|
|
534
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
535
|
-
boundMethod.__reactBoundContext = component;
|
|
536
|
-
boundMethod.__reactBoundMethod = method;
|
|
537
|
-
boundMethod.__reactBoundArguments = null;
|
|
538
|
-
var componentName = component.constructor.displayName;
|
|
539
|
-
var _bind = boundMethod.bind;
|
|
540
|
-
boundMethod.bind = function (newThis) {
|
|
541
|
-
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
542
|
-
args[_key - 1] = arguments[_key];
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
// User is trying to bind() an autobound method; we effectively will
|
|
546
|
-
// ignore the value of "this" that the user is trying to use, so
|
|
547
|
-
// let's warn.
|
|
548
|
-
if (newThis !== component && newThis !== null) {
|
|
549
|
-
process.env.NODE_ENV !== 'production' ? warning(false, 'bind(): React component methods may only be bound to the ' + 'component instance. See %s', componentName) : void 0;
|
|
550
|
-
} else if (!args.length) {
|
|
551
|
-
process.env.NODE_ENV !== 'production' ? warning(false, 'bind(): You are binding a component method to the component. ' + 'React does this for you automatically in a high-performance ' + 'way, so you can safely remove this call. See %s', componentName) : void 0;
|
|
552
|
-
return boundMethod;
|
|
553
|
-
}
|
|
554
|
-
var reboundMethod = _bind.apply(boundMethod, arguments);
|
|
555
|
-
reboundMethod.__reactBoundContext = component;
|
|
556
|
-
reboundMethod.__reactBoundMethod = method;
|
|
557
|
-
reboundMethod.__reactBoundArguments = args;
|
|
558
|
-
return reboundMethod;
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
return boundMethod;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
/**
|
|
565
|
-
* Binds all auto-bound methods in a component.
|
|
566
|
-
*
|
|
567
|
-
* @param {object} component Component whose method is going to be bound.
|
|
568
|
-
*/
|
|
569
|
-
function bindAutoBindMethods(component) {
|
|
570
|
-
var pairs = component.__reactAutoBindPairs;
|
|
571
|
-
for (var i = 0; i < pairs.length; i += 2) {
|
|
572
|
-
var autoBindKey = pairs[i];
|
|
573
|
-
var method = pairs[i + 1];
|
|
574
|
-
component[autoBindKey] = bindAutoBindMethod(component, method);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
/**
|
|
579
|
-
* Add more to the ReactClass base class. These are all legacy features and
|
|
580
|
-
* therefore not already part of the modern ReactComponent.
|
|
581
|
-
*/
|
|
582
|
-
var ReactClassMixin = {
|
|
583
|
-
|
|
584
|
-
/**
|
|
585
|
-
* TODO: This will be deprecated because state should always keep a consistent
|
|
586
|
-
* type signature and the only use case for this, is to avoid that.
|
|
587
|
-
*/
|
|
588
|
-
replaceState: function (newState, callback) {
|
|
589
|
-
this.updater.enqueueReplaceState(this, newState);
|
|
590
|
-
if (callback) {
|
|
591
|
-
this.updater.enqueueCallback(this, callback, 'replaceState');
|
|
592
|
-
}
|
|
593
|
-
},
|
|
594
|
-
|
|
595
|
-
/**
|
|
596
|
-
* Checks whether or not this composite component is mounted.
|
|
597
|
-
* @return {boolean} True if mounted, false otherwise.
|
|
598
|
-
* @protected
|
|
599
|
-
* @final
|
|
600
|
-
*/
|
|
601
|
-
isMounted: function () {
|
|
602
|
-
return this.updater.isMounted(this);
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
|
|
606
|
-
var ReactClassComponent = function () {};
|
|
607
|
-
_assign(ReactClassComponent.prototype, ReactComponent.prototype, ReactClassMixin);
|
|
608
|
-
|
|
609
|
-
var didWarnDeprecated = false;
|
|
610
|
-
|
|
611
|
-
/**
|
|
612
|
-
* Module for creating composite components.
|
|
613
|
-
*
|
|
614
|
-
* @class ReactClass
|
|
615
|
-
*/
|
|
616
|
-
var ReactClass = {
|
|
617
|
-
|
|
618
|
-
/**
|
|
619
|
-
* Creates a composite component class given a class specification.
|
|
620
|
-
* See https://facebook.github.io/react/docs/top-level-api.html#react.createclass
|
|
621
|
-
*
|
|
622
|
-
* @param {object} spec Class specification (which must define `render`).
|
|
623
|
-
* @return {function} Component constructor function.
|
|
624
|
-
* @public
|
|
625
|
-
*/
|
|
626
|
-
createClass: function (spec) {
|
|
627
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
628
|
-
process.env.NODE_ENV !== 'production' ? warning(didWarnDeprecated, '%s: React.createClass is deprecated and will be removed in version 16. ' + 'Use plain JavaScript classes instead. If you\'re not yet ready to ' + 'migrate, create-react-class is available on npm as a ' + 'drop-in replacement.', spec && spec.displayName || 'A Component') : void 0;
|
|
629
|
-
didWarnDeprecated = true;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
// To keep our warnings more understandable, we'll use a little hack here to
|
|
633
|
-
// ensure that Constructor.name !== 'Constructor'. This makes sure we don't
|
|
634
|
-
// unnecessarily identify a class without displayName as 'Constructor'.
|
|
635
|
-
var Constructor = identity(function (props, context, updater) {
|
|
636
|
-
// This constructor gets overridden by mocks. The argument is used
|
|
637
|
-
// by mocks to assert on what gets mounted.
|
|
638
|
-
|
|
639
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
640
|
-
process.env.NODE_ENV !== 'production' ? warning(this instanceof Constructor, 'Something is calling a React component directly. Use a factory or ' + 'JSX instead. See: https://fb.me/react-legacyfactory') : void 0;
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
// Wire up auto-binding
|
|
644
|
-
if (this.__reactAutoBindPairs.length) {
|
|
645
|
-
bindAutoBindMethods(this);
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
this.props = props;
|
|
649
|
-
this.context = context;
|
|
650
|
-
this.refs = emptyObject;
|
|
651
|
-
this.updater = updater || ReactNoopUpdateQueue;
|
|
652
|
-
|
|
653
|
-
this.state = null;
|
|
654
|
-
|
|
655
|
-
// ReactClasses doesn't have constructors. Instead, they use the
|
|
656
|
-
// getInitialState and componentWillMount methods for initialization.
|
|
657
|
-
|
|
658
|
-
var initialState = this.getInitialState ? this.getInitialState() : null;
|
|
659
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
660
|
-
// We allow auto-mocks to proceed as if they're returning null.
|
|
661
|
-
if (initialState === undefined && this.getInitialState._isMockFunction) {
|
|
662
|
-
// This is probably bad practice. Consider warning here and
|
|
663
|
-
// deprecating this convenience.
|
|
664
|
-
initialState = null;
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
!(typeof initialState === 'object' && !Array.isArray(initialState)) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.getInitialState(): must return an object or null', Constructor.displayName || 'ReactCompositeComponent') : _prodInvariant('82', Constructor.displayName || 'ReactCompositeComponent') : void 0;
|
|
668
|
-
|
|
669
|
-
this.state = initialState;
|
|
670
|
-
});
|
|
671
|
-
Constructor.prototype = new ReactClassComponent();
|
|
672
|
-
Constructor.prototype.constructor = Constructor;
|
|
673
|
-
Constructor.prototype.__reactAutoBindPairs = [];
|
|
674
|
-
|
|
675
|
-
injectedMixins.forEach(mixSpecIntoComponent.bind(null, Constructor));
|
|
676
|
-
|
|
677
|
-
mixSpecIntoComponent(Constructor, spec);
|
|
678
|
-
|
|
679
|
-
// Initialize the defaultProps property after all mixins have been merged.
|
|
680
|
-
if (Constructor.getDefaultProps) {
|
|
681
|
-
Constructor.defaultProps = Constructor.getDefaultProps();
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
685
|
-
// This is a tag to indicate that the use of these method names is ok,
|
|
686
|
-
// since it's used with createClass. If it's not, then it's likely a
|
|
687
|
-
// mistake so we'll warn you to use the static property, property
|
|
688
|
-
// initializer or constructor respectively.
|
|
689
|
-
if (Constructor.getDefaultProps) {
|
|
690
|
-
Constructor.getDefaultProps.isReactClassApproved = {};
|
|
691
|
-
}
|
|
692
|
-
if (Constructor.prototype.getInitialState) {
|
|
693
|
-
Constructor.prototype.getInitialState.isReactClassApproved = {};
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
!Constructor.prototype.render ? process.env.NODE_ENV !== 'production' ? invariant(false, 'createClass(...): Class specification must implement a `render` method.') : _prodInvariant('83') : void 0;
|
|
698
|
-
|
|
699
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
700
|
-
process.env.NODE_ENV !== 'production' ? warning(!Constructor.prototype.componentShouldUpdate, '%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.', spec.displayName || 'A component') : void 0;
|
|
701
|
-
process.env.NODE_ENV !== 'production' ? warning(!Constructor.prototype.componentWillRecieveProps, '%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', spec.displayName || 'A component') : void 0;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
// Reduce time spent doing lookups by setting these on the prototype.
|
|
705
|
-
for (var methodName in ReactClassInterface) {
|
|
706
|
-
if (!Constructor.prototype[methodName]) {
|
|
707
|
-
Constructor.prototype[methodName] = null;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
return Constructor;
|
|
712
|
-
},
|
|
713
|
-
|
|
714
|
-
injection: {
|
|
715
|
-
injectMixin: function (mixin) {
|
|
716
|
-
injectedMixins.push(mixin);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
};
|
|
721
|
-
|
|
722
|
-
module.exports = ReactClass;
|