react 16.0.0-alpha.3 → 16.0.0-alpha.7
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 → cjs/react.development.js} +1685 -3752
- package/cjs/react.production.min.js +1 -0
- package/index.js +7 -0
- package/package.json +7 -8
- package/{dist/react.js → umd/react.development.js} +2850 -3237
- package/umd/react.production.min.js +4 -0
- package/dist/react-with-addons.min.js +0 -17
- package/dist/react.min.js +0 -17
- package/lib/KeyEscapeUtils.js +0 -58
- package/lib/PooledClass.js +0 -111
- package/lib/React.js +0 -86
- package/lib/ReactAddonsDOMDependencies.js +0 -36
- package/lib/ReactAddonsDOMDependenciesUMDShim.js +0 -35
- package/lib/ReactBaseClasses.js +0 -136
- package/lib/ReactCSSTransitionGroup.js +0 -104
- package/lib/ReactCSSTransitionGroupChild.js +0 -166
- package/lib/ReactChildren.js +0 -190
- package/lib/ReactClass.js +0 -703
- package/lib/ReactComponentTreeHook.js +0 -381
- package/lib/ReactComponentTreeHookUMDShim.js +0 -17
- package/lib/ReactComponentWithPureRenderMixin.js +0 -47
- package/lib/ReactCurrentOwner.js +0 -30
- package/lib/ReactCurrentOwnerUMDShim.js +0 -17
- package/lib/ReactDOMFactories.js +0 -169
- package/lib/ReactDebugCurrentFrame.js +0 -53
- package/lib/ReactElement.js +0 -340
- package/lib/ReactElementSymbol.js +0 -19
- package/lib/ReactElementType.js +0 -12
- package/lib/ReactElementValidator.js +0 -269
- package/lib/ReactFragment.js +0 -68
- package/lib/ReactNoopUpdateQueue.js +0 -91
- package/lib/ReactPropTypes.js +0 -458
- package/lib/ReactPropTypesSecret.js +0 -16
- package/lib/ReactStateSetters.js +0 -103
- package/lib/ReactTransitionChildMapping.js +0 -102
- package/lib/ReactTransitionEvents.js +0 -72
- package/lib/ReactTransitionGroup.js +0 -228
- package/lib/ReactTypeOfWork.js +0 -26
- package/lib/ReactUMDEntry.js +0 -31
- package/lib/ReactUMDShim.js +0 -15
- package/lib/ReactVersion.js +0 -13
- package/lib/ReactWithAddons.js +0 -50
- package/lib/ReactWithAddonsUMDEntry.js +0 -32
- package/lib/canDefineProperty.js +0 -25
- package/lib/checkPropTypes.js +0 -64
- package/lib/checkReactTypeSpec.js +0 -22
- package/lib/deprecated.js +0 -56
- package/lib/flattenChildren.js +0 -75
- package/lib/getComponentName.js +0 -35
- package/lib/getIteratorFn.js +0 -40
- package/lib/getNextDebugID.js +0 -20
- package/lib/onlyChild.js +0 -37
- package/lib/reactProdInvariant.js +0 -38
- package/lib/shallowCompare.js +0 -24
- package/lib/sliceChildren.js +0 -33
- package/lib/traverseAllChildren.js +0 -164
- package/lib/update.js +0 -111
- package/react.js +0 -3
package/lib/getIteratorFn.js
DELETED
|
@@ -1,40 +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
|
-
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
|
-
/* global Symbol */
|
|
15
|
-
|
|
16
|
-
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
|
17
|
-
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Returns the iterator method function contained on the iterable object.
|
|
21
|
-
*
|
|
22
|
-
* Be sure to invoke the function with the iterable as context:
|
|
23
|
-
*
|
|
24
|
-
* var iteratorFn = getIteratorFn(myIterable);
|
|
25
|
-
* if (iteratorFn) {
|
|
26
|
-
* var iterator = iteratorFn.call(myIterable);
|
|
27
|
-
* ...
|
|
28
|
-
* }
|
|
29
|
-
*
|
|
30
|
-
* @param {?object} maybeIterable
|
|
31
|
-
* @return {?function}
|
|
32
|
-
*/
|
|
33
|
-
function getIteratorFn(maybeIterable) {
|
|
34
|
-
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
|
|
35
|
-
if (typeof iteratorFn === 'function') {
|
|
36
|
-
return iteratorFn;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = getIteratorFn;
|
package/lib/getNextDebugID.js
DELETED
|
@@ -1,20 +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
|
-
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
|
-
var nextDebugID = 1;
|
|
15
|
-
|
|
16
|
-
function getNextDebugID() {
|
|
17
|
-
return nextDebugID++;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports = getNextDebugID;
|
package/lib/onlyChild.js
DELETED
|
@@ -1,37 +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
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
var _prodInvariant = require('./reactProdInvariant');
|
|
13
|
-
|
|
14
|
-
var ReactElement = require('./ReactElement');
|
|
15
|
-
|
|
16
|
-
var invariant = require('fbjs/lib/invariant');
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Returns the first child in a collection of children and verifies that there
|
|
20
|
-
* is only one child in the collection.
|
|
21
|
-
*
|
|
22
|
-
* See https://facebook.github.io/react/docs/react-api.html#react.children.only
|
|
23
|
-
*
|
|
24
|
-
* The current implementation of this function assumes that a single child gets
|
|
25
|
-
* passed without a wrapper, but the purpose of this helper function is to
|
|
26
|
-
* abstract away the particular structure of children.
|
|
27
|
-
*
|
|
28
|
-
* @param {?object} children Child collection structure.
|
|
29
|
-
* @return {ReactElement} The first and only `ReactElement` contained in the
|
|
30
|
-
* structure.
|
|
31
|
-
*/
|
|
32
|
-
function onlyChild(children) {
|
|
33
|
-
!ReactElement.isValidElement(children) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'React.Children.only expected to receive a single React element child.') : _prodInvariant('143') : void 0;
|
|
34
|
-
return children;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
module.exports = onlyChild;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 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
|
-
/**
|
|
14
|
-
* WARNING: DO NOT manually require this module.
|
|
15
|
-
* This is a replacement for `invariant(...)` used by the error code system
|
|
16
|
-
* and will _only_ be required by the corresponding babel pass.
|
|
17
|
-
* It always throws.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
function reactProdInvariant(code) {
|
|
21
|
-
var argCount = arguments.length - 1;
|
|
22
|
-
|
|
23
|
-
var message = 'Minified React error #' + code + '; visit ' + 'http://facebook.github.io/react/docs/error-decoder.html?invariant=' + code;
|
|
24
|
-
|
|
25
|
-
for (var argIdx = 0; argIdx < argCount; argIdx++) {
|
|
26
|
-
message += '&args[]=' + encodeURIComponent(arguments[argIdx + 1]);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
message += ' for the full message or use the non-minified dev environment' + ' for full errors and additional helpful warnings.';
|
|
30
|
-
|
|
31
|
-
var error = new Error(message);
|
|
32
|
-
error.name = 'Invariant Violation';
|
|
33
|
-
error.framesToPop = 1; // we don't care about reactProdInvariant's own frame
|
|
34
|
-
|
|
35
|
-
throw error;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
module.exports = reactProdInvariant;
|
package/lib/shallowCompare.js
DELETED
|
@@ -1,24 +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 shallowEqual = require('fbjs/lib/shallowEqual');
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Does a shallow comparison for props and state.
|
|
17
|
-
* See ReactComponentWithPureRenderMixin
|
|
18
|
-
* See also https://facebook.github.io/react/docs/shallow-compare.html
|
|
19
|
-
*/
|
|
20
|
-
function shallowCompare(instance, nextProps, nextState) {
|
|
21
|
-
return !shallowEqual(instance.props, nextProps) || !shallowEqual(instance.state, nextState);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
module.exports = shallowCompare;
|
package/lib/sliceChildren.js
DELETED
|
@@ -1,33 +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 ReactChildren = require('./ReactChildren');
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Slice children that are typically specified as `props.children`. This version
|
|
17
|
-
* of slice children ignores empty child components.
|
|
18
|
-
*
|
|
19
|
-
* @param {*} children The children set to filter.
|
|
20
|
-
* @param {number} start The first zero-based index to include in the subset.
|
|
21
|
-
* @param {?number} end The non-inclusive last index of the subset.
|
|
22
|
-
* @return {object} mirrored array with mapped children
|
|
23
|
-
*/
|
|
24
|
-
function sliceChildren(children, start, end) {
|
|
25
|
-
if (children == null) {
|
|
26
|
-
return children;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
var array = ReactChildren.toArray(children);
|
|
30
|
-
return array.slice(start, end);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
module.exports = sliceChildren;
|
|
@@ -1,164 +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
|
-
|
|
15
|
-
var ReactCurrentOwner = require('./ReactCurrentOwner');
|
|
16
|
-
var REACT_ELEMENT_TYPE = require('./ReactElementSymbol');
|
|
17
|
-
|
|
18
|
-
var getIteratorFn = require('./getIteratorFn');
|
|
19
|
-
var invariant = require('fbjs/lib/invariant');
|
|
20
|
-
var KeyEscapeUtils = require('./KeyEscapeUtils');
|
|
21
|
-
var warning = require('fbjs/lib/warning');
|
|
22
|
-
|
|
23
|
-
var SEPARATOR = '.';
|
|
24
|
-
var SUBSEPARATOR = ':';
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* This is inlined from ReactElement since this file is shared between
|
|
28
|
-
* isomorphic and renderers. We could extract this to a
|
|
29
|
-
*
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* TODO: Test that a single child and an array with one item have the same key
|
|
34
|
-
* pattern.
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
var didWarnAboutMaps = false;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Generate a key string that identifies a component within a set.
|
|
41
|
-
*
|
|
42
|
-
* @param {*} component A component that could contain a manual key.
|
|
43
|
-
* @param {number} index Index that is used if a manual key is not provided.
|
|
44
|
-
* @return {string}
|
|
45
|
-
*/
|
|
46
|
-
function getComponentKey(component, index) {
|
|
47
|
-
// Do some typechecking here since we call this blindly. We want to ensure
|
|
48
|
-
// that we don't block potential future ES APIs.
|
|
49
|
-
if (component && typeof component === 'object' && component.key != null) {
|
|
50
|
-
// Explicit key
|
|
51
|
-
return KeyEscapeUtils.escape(component.key);
|
|
52
|
-
}
|
|
53
|
-
// Implicit key determined by the index in the set
|
|
54
|
-
return index.toString(36);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @param {?*} children Children tree container.
|
|
59
|
-
* @param {!string} nameSoFar Name of the key path so far.
|
|
60
|
-
* @param {!function} callback Callback to invoke with each child found.
|
|
61
|
-
* @param {?*} traverseContext Used to pass information throughout the traversal
|
|
62
|
-
* process.
|
|
63
|
-
* @return {!number} The number of children in this subtree.
|
|
64
|
-
*/
|
|
65
|
-
function traverseAllChildrenImpl(children, nameSoFar, callback, traverseContext) {
|
|
66
|
-
var type = typeof children;
|
|
67
|
-
|
|
68
|
-
if (type === 'undefined' || type === 'boolean') {
|
|
69
|
-
// All of the above are perceived as null.
|
|
70
|
-
children = null;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (children === null || type === 'string' || type === 'number' ||
|
|
74
|
-
// The following is inlined from ReactElement. This means we can optimize
|
|
75
|
-
// some checks. React Fiber also inlines this logic for similar purposes.
|
|
76
|
-
type === 'object' && children.$$typeof === REACT_ELEMENT_TYPE) {
|
|
77
|
-
callback(traverseContext, children,
|
|
78
|
-
// If it's the only child, treat the name as if it was wrapped in an array
|
|
79
|
-
// so that it's consistent if the number of children grows.
|
|
80
|
-
nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar);
|
|
81
|
-
return 1;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
var child;
|
|
85
|
-
var nextName;
|
|
86
|
-
var subtreeCount = 0; // Count of children found in the current subtree.
|
|
87
|
-
var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR;
|
|
88
|
-
|
|
89
|
-
if (Array.isArray(children)) {
|
|
90
|
-
for (var i = 0; i < children.length; i++) {
|
|
91
|
-
child = children[i];
|
|
92
|
-
nextName = nextNamePrefix + getComponentKey(child, i);
|
|
93
|
-
subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
var iteratorFn = getIteratorFn(children);
|
|
97
|
-
if (iteratorFn) {
|
|
98
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
99
|
-
// Warn about using Maps as children
|
|
100
|
-
if (iteratorFn === children.entries) {
|
|
101
|
-
var mapsAsChildrenAddendum = '';
|
|
102
|
-
if (ReactCurrentOwner.current) {
|
|
103
|
-
var mapsAsChildrenOwnerName = ReactCurrentOwner.current.getName();
|
|
104
|
-
if (mapsAsChildrenOwnerName) {
|
|
105
|
-
mapsAsChildrenAddendum = '\n\nCheck the render method of `' + mapsAsChildrenOwnerName + '`.';
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
process.env.NODE_ENV !== 'production' ? warning(didWarnAboutMaps, 'Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.%s', mapsAsChildrenAddendum) : void 0;
|
|
109
|
-
didWarnAboutMaps = true;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
var iterator = iteratorFn.call(children);
|
|
114
|
-
var step;
|
|
115
|
-
var ii = 0;
|
|
116
|
-
while (!(step = iterator.next()).done) {
|
|
117
|
-
child = step.value;
|
|
118
|
-
nextName = nextNamePrefix + getComponentKey(child, ii++);
|
|
119
|
-
subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
|
|
120
|
-
}
|
|
121
|
-
} else if (type === 'object') {
|
|
122
|
-
var addendum = '';
|
|
123
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
124
|
-
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.';
|
|
125
|
-
if (ReactCurrentOwner.current) {
|
|
126
|
-
var name = ReactCurrentOwner.current.getName();
|
|
127
|
-
if (name) {
|
|
128
|
-
addendum += '\n\nCheck the render method of `' + name + '`.';
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
var childrenString = String(children);
|
|
133
|
-
!false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Objects are not valid as a React child (found: %s).%s', childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString, addendum) : _prodInvariant('31', childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString, addendum) : void 0;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return subtreeCount;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Traverses children that are typically specified as `props.children`, but
|
|
142
|
-
* might also be specified through attributes:
|
|
143
|
-
*
|
|
144
|
-
* - `traverseAllChildren(this.props.children, ...)`
|
|
145
|
-
* - `traverseAllChildren(this.props.leftPanelChildren, ...)`
|
|
146
|
-
*
|
|
147
|
-
* The `traverseContext` is an optional argument that is passed through the
|
|
148
|
-
* entire traversal. It can be used to store accumulations or anything else that
|
|
149
|
-
* the callback might find relevant.
|
|
150
|
-
*
|
|
151
|
-
* @param {?*} children Children tree object.
|
|
152
|
-
* @param {!function} callback To invoke upon traversing each child.
|
|
153
|
-
* @param {?*} traverseContext Context for traversal.
|
|
154
|
-
* @return {!number} The number of children in this subtree.
|
|
155
|
-
*/
|
|
156
|
-
function traverseAllChildren(children, callback, traverseContext) {
|
|
157
|
-
if (children == null) {
|
|
158
|
-
return 0;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return traverseAllChildrenImpl(children, '', callback, traverseContext);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
module.exports = traverseAllChildren;
|
package/lib/update.js
DELETED
|
@@ -1,111 +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
|
-
/* global hasOwnProperty:true */
|
|
12
|
-
|
|
13
|
-
'use strict';
|
|
14
|
-
|
|
15
|
-
var _prodInvariant = require('./reactProdInvariant'),
|
|
16
|
-
_assign = require('object-assign');
|
|
17
|
-
|
|
18
|
-
var invariant = require('fbjs/lib/invariant');
|
|
19
|
-
var hasOwnProperty = {}.hasOwnProperty;
|
|
20
|
-
|
|
21
|
-
function shallowCopy(x) {
|
|
22
|
-
if (Array.isArray(x)) {
|
|
23
|
-
return x.concat();
|
|
24
|
-
} else if (x && typeof x === 'object') {
|
|
25
|
-
return _assign(new x.constructor(), x);
|
|
26
|
-
} else {
|
|
27
|
-
return x;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
var COMMAND_PUSH = '$push';
|
|
32
|
-
var COMMAND_UNSHIFT = '$unshift';
|
|
33
|
-
var COMMAND_SPLICE = '$splice';
|
|
34
|
-
var COMMAND_SET = '$set';
|
|
35
|
-
var COMMAND_MERGE = '$merge';
|
|
36
|
-
var COMMAND_APPLY = '$apply';
|
|
37
|
-
|
|
38
|
-
var ALL_COMMANDS_LIST = [COMMAND_PUSH, COMMAND_UNSHIFT, COMMAND_SPLICE, COMMAND_SET, COMMAND_MERGE, COMMAND_APPLY];
|
|
39
|
-
|
|
40
|
-
var ALL_COMMANDS_SET = {};
|
|
41
|
-
|
|
42
|
-
ALL_COMMANDS_LIST.forEach(function (command) {
|
|
43
|
-
ALL_COMMANDS_SET[command] = true;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
function invariantArrayCase(value, spec, command) {
|
|
47
|
-
!Array.isArray(value) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'update(): expected target of %s to be an array; got %s.', command, value) : _prodInvariant('1', command, value) : void 0;
|
|
48
|
-
var specValue = spec[command];
|
|
49
|
-
!Array.isArray(specValue) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'update(): expected spec of %s to be an array; got %s. Did you forget to wrap your parameter in an array?', command, specValue) : _prodInvariant('2', command, specValue) : void 0;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Returns a updated shallow copy of an object without mutating the original.
|
|
54
|
-
* See https://facebook.github.io/react/docs/update.html for details.
|
|
55
|
-
*/
|
|
56
|
-
function update(value, spec) {
|
|
57
|
-
!(typeof spec === 'object') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'update(): You provided a key path to update() that did not contain one of %s. Did you forget to include {%s: ...}?', ALL_COMMANDS_LIST.join(', '), COMMAND_SET) : _prodInvariant('3', ALL_COMMANDS_LIST.join(', '), COMMAND_SET) : void 0;
|
|
58
|
-
|
|
59
|
-
if (hasOwnProperty.call(spec, COMMAND_SET)) {
|
|
60
|
-
!(Object.keys(spec).length === 1) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Cannot have more than one key in an object with %s', COMMAND_SET) : _prodInvariant('4', COMMAND_SET) : void 0;
|
|
61
|
-
|
|
62
|
-
return spec[COMMAND_SET];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
var nextValue = shallowCopy(value);
|
|
66
|
-
|
|
67
|
-
if (hasOwnProperty.call(spec, COMMAND_MERGE)) {
|
|
68
|
-
var mergeObj = spec[COMMAND_MERGE];
|
|
69
|
-
!(mergeObj && typeof mergeObj === 'object') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'update(): %s expects a spec of type \'object\'; got %s', COMMAND_MERGE, mergeObj) : _prodInvariant('5', COMMAND_MERGE, mergeObj) : void 0;
|
|
70
|
-
!(nextValue && typeof nextValue === 'object') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'update(): %s expects a target of type \'object\'; got %s', COMMAND_MERGE, nextValue) : _prodInvariant('6', COMMAND_MERGE, nextValue) : void 0;
|
|
71
|
-
_assign(nextValue, spec[COMMAND_MERGE]);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (hasOwnProperty.call(spec, COMMAND_PUSH)) {
|
|
75
|
-
invariantArrayCase(value, spec, COMMAND_PUSH);
|
|
76
|
-
spec[COMMAND_PUSH].forEach(function (item) {
|
|
77
|
-
nextValue.push(item);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (hasOwnProperty.call(spec, COMMAND_UNSHIFT)) {
|
|
82
|
-
invariantArrayCase(value, spec, COMMAND_UNSHIFT);
|
|
83
|
-
spec[COMMAND_UNSHIFT].forEach(function (item) {
|
|
84
|
-
nextValue.unshift(item);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (hasOwnProperty.call(spec, COMMAND_SPLICE)) {
|
|
89
|
-
!Array.isArray(value) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Expected %s target to be an array; got %s', COMMAND_SPLICE, value) : _prodInvariant('7', COMMAND_SPLICE, value) : void 0;
|
|
90
|
-
!Array.isArray(spec[COMMAND_SPLICE]) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'update(): expected spec of %s to be an array of arrays; got %s. Did you forget to wrap your parameters in an array?', COMMAND_SPLICE, spec[COMMAND_SPLICE]) : _prodInvariant('8', COMMAND_SPLICE, spec[COMMAND_SPLICE]) : void 0;
|
|
91
|
-
spec[COMMAND_SPLICE].forEach(function (args) {
|
|
92
|
-
!Array.isArray(args) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'update(): expected spec of %s to be an array of arrays; got %s. Did you forget to wrap your parameters in an array?', COMMAND_SPLICE, spec[COMMAND_SPLICE]) : _prodInvariant('8', COMMAND_SPLICE, spec[COMMAND_SPLICE]) : void 0;
|
|
93
|
-
nextValue.splice.apply(nextValue, args);
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (hasOwnProperty.call(spec, COMMAND_APPLY)) {
|
|
98
|
-
!(typeof spec[COMMAND_APPLY] === 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'update(): expected spec of %s to be a function; got %s.', COMMAND_APPLY, spec[COMMAND_APPLY]) : _prodInvariant('9', COMMAND_APPLY, spec[COMMAND_APPLY]) : void 0;
|
|
99
|
-
nextValue = spec[COMMAND_APPLY](nextValue);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
for (var k in spec) {
|
|
103
|
-
if (!(ALL_COMMANDS_SET.hasOwnProperty(k) && ALL_COMMANDS_SET[k])) {
|
|
104
|
-
nextValue[k] = update(value[k], spec[k]);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return nextValue;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
module.exports = update;
|