react 0.13.2 → 0.14.0-alpha3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/addons.js +7 -0
- package/addons/CSSTransitionGroup.js +1 -0
- package/addons/LinkedStateMixin.js +1 -0
- package/addons/Perf.js +1 -0
- package/addons/PureRenderMixin.js +1 -0
- package/addons/TestUtils.js +1 -0
- package/addons/TransitionGroup.js +1 -0
- package/addons/batchedUpdates.js +1 -0
- package/addons/cloneWithProps.js +1 -0
- package/addons/createFragment.js +1 -0
- package/addons/renderSubtreeIntoContainer.js +1 -0
- package/addons/shallowCompare.js +1 -0
- package/addons/update.js +1 -0
- package/dist/JSXTransformer.js +3355 -1685
- package/dist/react-with-addons.js +3320 -5133
- package/dist/react-with-addons.min.js +6 -7
- package/dist/react.js +2962 -4548
- package/dist/react.min.js +5 -5
- package/lib/AutoFocusMixin.js +4 -3
- package/lib/BeforeInputEventPlugin.js +30 -118
- package/lib/CSSCore.js +12 -23
- package/lib/CSSProperty.js +4 -3
- package/lib/CSSPropertyOperations.js +14 -30
- package/lib/CallbackQueue.js +7 -10
- package/lib/ChangeEventPlugin.js +24 -88
- package/lib/ClientReactRootIndex.js +2 -2
- package/lib/DOMChildrenOperations.js +13 -33
- package/lib/DOMProperty.js +41 -67
- package/lib/DOMPropertyOperations.js +30 -51
- package/lib/Danger.js +19 -62
- package/lib/DefaultEventPluginOrder.js +2 -12
- package/lib/EnterLeaveEventPlugin.js +11 -33
- package/lib/EventConstants.js +2 -2
- package/lib/EventListener.js +11 -13
- package/lib/EventPluginHub.js +44 -47
- package/lib/EventPluginRegistry.js +18 -74
- package/lib/EventPluginUtils.js +27 -38
- package/lib/EventPropagators.js +23 -26
- package/lib/ExecutionEnvironment.js +4 -8
- package/lib/FallbackCompositionState.js +3 -3
- package/lib/HTMLDOMPropertyConfig.js +7 -19
- package/lib/LinkedStateMixin.js +3 -6
- package/lib/LinkedValueUtils.js +34 -64
- package/lib/LocalEventTrapMixin.js +9 -16
- package/lib/Object.assign.js +1 -1
- package/lib/PooledClass.js +8 -11
- package/lib/React.js +9 -129
- package/lib/ReactBrowserComponentMixin.js +9 -2
- package/lib/ReactBrowserEventEmitter.js +26 -82
- package/lib/ReactCSSTransitionGroup.js +13 -24
- package/lib/ReactCSSTransitionGroupChild.js +18 -28
- package/lib/ReactChildReconciler.js +11 -19
- package/lib/ReactChildren.js +21 -28
- package/lib/ReactClass.js +81 -234
- package/lib/ReactComponent.js +17 -33
- package/lib/ReactComponentBrowserEnvironment.js +4 -8
- package/lib/ReactComponentEnvironment.js +6 -12
- package/lib/ReactComponentWithPureRenderMixin.js +4 -5
- package/lib/ReactCompositeComponent.js +87 -311
- package/lib/ReactContext.js +2 -44
- package/lib/ReactCurrentOwner.js +1 -3
- package/lib/ReactDOM.js +4 -2
- package/lib/ReactDOMButton.js +3 -4
- package/lib/ReactDOMClient.js +85 -0
- package/lib/ReactDOMComponent.js +182 -146
- package/lib/ReactDOMForm.js +3 -3
- package/lib/ReactDOMIDOperations.js +11 -22
- package/lib/ReactDOMIframe.js +3 -3
- package/lib/ReactDOMImg.js +3 -3
- package/lib/ReactDOMInput.js +22 -35
- package/lib/ReactDOMOption.js +67 -10
- package/lib/ReactDOMSelect.js +50 -28
- package/lib/ReactDOMSelection.js +5 -20
- package/lib/ReactDOMServer.js +24 -0
- package/lib/ReactDOMTextComponent.js +17 -18
- package/lib/ReactDOMTextarea.js +15 -27
- package/lib/ReactDefaultBatchingStrategy.js +9 -13
- package/lib/ReactDefaultInjection.js +31 -40
- package/lib/ReactDefaultPerf.js +36 -69
- package/lib/ReactDefaultPerfAnalysis.js +8 -14
- package/lib/ReactElement.js +24 -57
- package/lib/ReactElementValidator.js +38 -105
- package/lib/ReactEmptyComponent.js +7 -11
- package/lib/ReactErrorUtils.js +2 -2
- package/lib/ReactEventEmitterMixin.js +3 -12
- package/lib/ReactEventListener.js +16 -38
- package/lib/ReactFragment.js +23 -54
- package/lib/ReactInjection.js +1 -1
- package/lib/ReactInputSelection.js +11 -21
- package/lib/ReactInstanceHandles.js +27 -57
- package/lib/ReactInstanceMap.js +5 -5
- package/lib/ReactIsomorphic.js +70 -0
- package/lib/ReactLifeCycle.js +1 -1
- package/lib/ReactLink.js +2 -4
- package/lib/ReactMarkupChecksum.js +5 -10
- package/lib/ReactMount.js +137 -260
- package/lib/ReactMultiChild.js +19 -45
- package/lib/ReactMultiChildUpdateTypes.js +1 -1
- package/lib/ReactNativeComponent.js +7 -11
- package/lib/ReactOwner.js +7 -24
- package/lib/ReactPerf.js +8 -12
- package/lib/ReactPropTransferer.js +4 -4
- package/lib/ReactPropTypeLocationNames.js +2 -2
- package/lib/ReactPropTypeLocations.js +1 -1
- package/lib/ReactPropTypes.js +41 -61
- package/lib/ReactReconcileTransaction.js +9 -34
- package/lib/ReactReconciler.js +9 -19
- package/lib/ReactRef.js +5 -8
- package/lib/ReactRootIndex.js +2 -2
- package/lib/ReactServerRendering.js +7 -15
- package/lib/ReactServerRenderingTransaction.js +7 -32
- package/lib/ReactStateSetters.js +6 -6
- package/lib/ReactTestUtils.js +93 -165
- package/lib/ReactTransitionChildMapping.js +5 -7
- package/lib/ReactTransitionEvents.js +5 -5
- package/lib/ReactTransitionGroup.js +30 -52
- package/lib/ReactUpdateQueue.js +27 -90
- package/lib/ReactUpdates.js +27 -79
- package/lib/ReactWithAddons.js +7 -6
- package/lib/SVGDOMPropertyConfig.js +41 -4
- package/lib/SelectEventPlugin.js +28 -29
- package/lib/ServerReactRootIndex.js +2 -2
- package/lib/SimpleEventPlugin.js +136 -128
- package/lib/SyntheticClipboardEvent.js +3 -7
- package/lib/SyntheticCompositionEvent.js +3 -9
- package/lib/SyntheticDragEvent.js +1 -1
- package/lib/SyntheticEvent.js +8 -10
- package/lib/SyntheticFocusEvent.js +1 -1
- package/lib/SyntheticInputEvent.js +3 -9
- package/lib/SyntheticKeyboardEvent.js +4 -4
- package/lib/SyntheticMouseEvent.js +8 -14
- package/lib/SyntheticTouchEvent.js +1 -1
- package/lib/SyntheticUIEvent.js +3 -3
- package/lib/SyntheticWheelEvent.js +11 -15
- package/lib/Transaction.js +12 -24
- package/lib/ViewportMetrics.js +2 -2
- package/lib/accumulateInto.js +2 -5
- package/lib/adler32.js +2 -4
- package/lib/camelize.js +4 -2
- package/lib/camelizeStyleName.js +2 -2
- package/lib/cloneWithProps.js +5 -11
- package/lib/containsNode.js +29 -16
- package/lib/createArrayFromMixed.js +17 -16
- package/lib/createFullPageComponent.js +4 -11
- package/lib/createNodesFromMarkup.js +6 -8
- package/lib/dangerousStyleValue.js +2 -3
- package/lib/emptyFunction.js +10 -4
- package/lib/emptyObject.js +1 -1
- package/lib/escapeTextContentForBrowser.js +1 -1
- package/lib/findDOMNode.js +5 -24
- package/lib/flattenChildren.js +4 -10
- package/lib/focusNode.js +2 -3
- package/lib/forEachAccumulated.js +2 -2
- package/lib/getActiveElement.js +4 -2
- package/lib/getEventCharCode.js +1 -1
- package/lib/getEventKey.js +1 -1
- package/lib/getEventModifierState.js +1 -1
- package/lib/getEventTarget.js +1 -1
- package/lib/getIteratorFn.js +2 -4
- package/lib/getMarkupWrap.js +7 -5
- package/lib/getNodeForCharacterOffset.js +1 -1
- package/lib/getTextContentAccessor.js +2 -4
- package/lib/getUnboundedScrollPosition.js +1 -1
- package/lib/hyphenate.js +3 -1
- package/lib/hyphenateStyleName.js +2 -2
- package/lib/instantiateReactComponent.js +14 -38
- package/lib/invariant.js +8 -12
- package/lib/isEventSupported.js +7 -10
- package/lib/isNode.js +4 -6
- package/lib/isTextInputElement.js +2 -4
- package/lib/isTextNode.js +3 -1
- package/lib/joinClasses.js +2 -2
- package/lib/keyMirror.js +3 -6
- package/lib/keyOf.js +4 -3
- package/lib/mapObject.js +1 -1
- package/lib/memoizeStringOnly.js +2 -2
- package/lib/onlyChild.js +2 -5
- package/lib/performance.js +2 -5
- package/lib/performanceNow.js +3 -1
- package/lib/quoteAttributeValueForBrowser.js +1 -1
- package/lib/renderSubtreeIntoContainer.js +16 -0
- package/lib/setInnerHTML.js +11 -8
- package/lib/setTextContent.js +3 -3
- package/lib/shallowCompare.js +24 -0
- package/lib/shallowEqual.js +17 -11
- package/lib/shouldUpdateReactComponent.js +3 -64
- package/lib/toArray.js +8 -19
- package/lib/traverseAllChildren.js +22 -89
- package/lib/update.js +25 -85
- package/lib/validateDOMNesting.js +363 -0
- package/lib/warning.js +17 -15
- package/package.json +3 -3
- package/lib/MobileSafariClickEventPlugin.js +0 -56
- package/lib/ReactPutListenerQueue.js +0 -54
- package/lib/cx.js +0 -52
- package/lib/getReactRootElementInContainer.js +0 -33
package/lib/performanceNow.js
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* @typechecks
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
13
15
|
var performance = require("./performance");
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -23,4 +25,4 @@ if (!performance || !performance.now) {
|
|
|
23
25
|
|
|
24
26
|
var performanceNow = performance.now.bind(performance);
|
|
25
27
|
|
|
26
|
-
module.exports = performanceNow;
|
|
28
|
+
module.exports = performanceNow;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013-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
|
+
* @providesModule renderSubtreeIntoContainer
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var ReactMount = require("./ReactMount");
|
|
15
|
+
|
|
16
|
+
module.exports = ReactMount.renderSubtreeIntoContainer;
|
package/lib/setInnerHTML.js
CHANGED
|
@@ -26,14 +26,14 @@ var NONVISIBLE_TEST = /<(!--|link|noscript|meta|script|style)[ \r\n\t\f\/>]/;
|
|
|
26
26
|
* @param {string} html
|
|
27
27
|
* @internal
|
|
28
28
|
*/
|
|
29
|
-
var setInnerHTML = function(node, html) {
|
|
29
|
+
var setInnerHTML = function (node, html) {
|
|
30
30
|
node.innerHTML = html;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
// Win8 apps: Allow all html to be inserted
|
|
34
34
|
if (typeof MSApp !== 'undefined' && MSApp.execUnsafeLocalFunction) {
|
|
35
|
-
setInnerHTML = function(node, html) {
|
|
36
|
-
MSApp.execUnsafeLocalFunction(function() {
|
|
35
|
+
setInnerHTML = function (node, html) {
|
|
36
|
+
MSApp.execUnsafeLocalFunction(function () {
|
|
37
37
|
node.innerHTML = html;
|
|
38
38
|
});
|
|
39
39
|
};
|
|
@@ -49,7 +49,7 @@ if (ExecutionEnvironment.canUseDOM) {
|
|
|
49
49
|
var testElement = document.createElement('div');
|
|
50
50
|
testElement.innerHTML = ' ';
|
|
51
51
|
if (testElement.innerHTML === '') {
|
|
52
|
-
setInnerHTML = function(node, html) {
|
|
52
|
+
setInnerHTML = function (node, html) {
|
|
53
53
|
// Magic theory: IE8 supposedly differentiates between added and updated
|
|
54
54
|
// nodes when processing innerHTML, innerHTML on updated nodes suffers
|
|
55
55
|
// from worse whitespace behavior. Re-adding a node like this triggers
|
|
@@ -63,11 +63,14 @@ if (ExecutionEnvironment.canUseDOM) {
|
|
|
63
63
|
// thin air on IE8, this only happens if there is no visible text
|
|
64
64
|
// in-front of the non-visible tags. Piggyback on the whitespace fix
|
|
65
65
|
// and simply check if any non-visible tags appear in the source.
|
|
66
|
-
if (WHITESPACE_TEST.test(html) ||
|
|
67
|
-
html[0] === '<' && NONVISIBLE_TEST.test(html)) {
|
|
66
|
+
if (WHITESPACE_TEST.test(html) || html[0] === '<' && NONVISIBLE_TEST.test(html)) {
|
|
68
67
|
// Recover leading whitespace by temporarily prepending any character.
|
|
69
68
|
// \uFEFF has the potential advantage of being zero-width/invisible.
|
|
70
|
-
|
|
69
|
+
// UglifyJS drops U+FEFF chars when parsing, so use String.fromCharCode
|
|
70
|
+
// in hopes that this is preserved even if "\uFEFF" is transformed to
|
|
71
|
+
// the actual Unicode character (by Babel, for example).
|
|
72
|
+
// https://github.com/mishoo/UglifyJS2/blob/v2.4.20/lib/parse.js#L216
|
|
73
|
+
node.innerHTML = String.fromCharCode(65279) + html;
|
|
71
74
|
|
|
72
75
|
// deleteData leaves an empty `TextNode` which offsets the index of all
|
|
73
76
|
// children. Definitely want to avoid this.
|
|
@@ -84,4 +87,4 @@ if (ExecutionEnvironment.canUseDOM) {
|
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
module.exports = setInnerHTML;
|
|
90
|
+
module.exports = setInnerHTML;
|
package/lib/setTextContent.js
CHANGED
|
@@ -25,16 +25,16 @@ var setInnerHTML = require("./setInnerHTML");
|
|
|
25
25
|
* @param {string} text
|
|
26
26
|
* @internal
|
|
27
27
|
*/
|
|
28
|
-
var setTextContent = function(node, text) {
|
|
28
|
+
var setTextContent = function (node, text) {
|
|
29
29
|
node.textContent = text;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
if (ExecutionEnvironment.canUseDOM) {
|
|
33
33
|
if (!('textContent' in document.documentElement)) {
|
|
34
|
-
setTextContent = function(node, text) {
|
|
34
|
+
setTextContent = function (node, text) {
|
|
35
35
|
setInnerHTML(node, escapeTextContentForBrowser(text));
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
module.exports = setTextContent;
|
|
40
|
+
module.exports = setTextContent;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013-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
|
+
* @providesModule shallowCompare
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var shallowEqual = require("./shallowEqual");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Does a shallow comparison for props and state.
|
|
18
|
+
* See ReactComponentWithPureRenderMixin
|
|
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/shallowEqual.js
CHANGED
|
@@ -22,21 +22,27 @@ function shallowEqual(objA, objB) {
|
|
|
22
22
|
if (objA === objB) {
|
|
23
23
|
return true;
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
|
|
26
|
+
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var keysA = Object.keys(objA);
|
|
31
|
+
var keysB = Object.keys(objB);
|
|
32
|
+
|
|
33
|
+
if (keysA.length !== keysB.length) {
|
|
34
|
+
return false;
|
|
32
35
|
}
|
|
33
|
-
|
|
34
|
-
for
|
|
35
|
-
|
|
36
|
+
|
|
37
|
+
// Test for A's keys different from B.
|
|
38
|
+
var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
|
|
39
|
+
for (var i = 0; i < keysA.length; i++) {
|
|
40
|
+
if (!bHasOwnProperty(keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) {
|
|
36
41
|
return false;
|
|
37
42
|
}
|
|
38
43
|
}
|
|
44
|
+
|
|
39
45
|
return true;
|
|
40
46
|
}
|
|
41
47
|
|
|
42
|
-
module.exports = shallowEqual;
|
|
48
|
+
module.exports = shallowEqual;
|
|
@@ -12,8 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
var warning = require("./warning");
|
|
16
|
-
|
|
17
15
|
/**
|
|
18
16
|
* Given a `prevElement` and `nextElement`, determines if the existing
|
|
19
17
|
* instance should be updated as opposed to being destroyed or replaced by a new
|
|
@@ -30,71 +28,12 @@ function shouldUpdateReactComponent(prevElement, nextElement) {
|
|
|
30
28
|
var prevType = typeof prevElement;
|
|
31
29
|
var nextType = typeof nextElement;
|
|
32
30
|
if (prevType === 'string' || prevType === 'number') {
|
|
33
|
-
return
|
|
31
|
+
return nextType === 'string' || nextType === 'number';
|
|
34
32
|
} else {
|
|
35
|
-
|
|
36
|
-
prevElement.type === nextElement.type &&
|
|
37
|
-
prevElement.key === nextElement.key) {
|
|
38
|
-
var ownersMatch = prevElement._owner === nextElement._owner;
|
|
39
|
-
var prevName = null;
|
|
40
|
-
var nextName = null;
|
|
41
|
-
var nextDisplayName = null;
|
|
42
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
43
|
-
if (!ownersMatch) {
|
|
44
|
-
if (prevElement._owner != null &&
|
|
45
|
-
prevElement._owner.getPublicInstance() != null &&
|
|
46
|
-
prevElement._owner.getPublicInstance().constructor != null) {
|
|
47
|
-
prevName =
|
|
48
|
-
prevElement._owner.getPublicInstance().constructor.displayName;
|
|
49
|
-
}
|
|
50
|
-
if (nextElement._owner != null &&
|
|
51
|
-
nextElement._owner.getPublicInstance() != null &&
|
|
52
|
-
nextElement._owner.getPublicInstance().constructor != null) {
|
|
53
|
-
nextName =
|
|
54
|
-
nextElement._owner.getPublicInstance().constructor.displayName;
|
|
55
|
-
}
|
|
56
|
-
if (nextElement.type != null &&
|
|
57
|
-
nextElement.type.displayName != null) {
|
|
58
|
-
nextDisplayName = nextElement.type.displayName;
|
|
59
|
-
}
|
|
60
|
-
if (nextElement.type != null && typeof nextElement.type === 'string') {
|
|
61
|
-
nextDisplayName = nextElement.type;
|
|
62
|
-
}
|
|
63
|
-
if (typeof nextElement.type !== 'string' ||
|
|
64
|
-
nextElement.type === 'input' ||
|
|
65
|
-
nextElement.type === 'textarea') {
|
|
66
|
-
if ((prevElement._owner != null &&
|
|
67
|
-
prevElement._owner._isOwnerNecessary === false) ||
|
|
68
|
-
(nextElement._owner != null &&
|
|
69
|
-
nextElement._owner._isOwnerNecessary === false)) {
|
|
70
|
-
if (prevElement._owner != null) {
|
|
71
|
-
prevElement._owner._isOwnerNecessary = true;
|
|
72
|
-
}
|
|
73
|
-
if (nextElement._owner != null) {
|
|
74
|
-
nextElement._owner._isOwnerNecessary = true;
|
|
75
|
-
}
|
|
76
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
77
|
-
false,
|
|
78
|
-
'<%s /> is being rendered by both %s and %s using the same ' +
|
|
79
|
-
'key (%s) in the same place. Currently, this means that ' +
|
|
80
|
-
'they don\'t preserve state. This behavior should be very ' +
|
|
81
|
-
'rare so we\'re considering deprecating it. Please contact ' +
|
|
82
|
-
'the React team and explain your use case so that we can ' +
|
|
83
|
-
'take that into consideration.',
|
|
84
|
-
nextDisplayName || 'Unknown Component',
|
|
85
|
-
prevName || '[Unknown]',
|
|
86
|
-
nextName || '[Unknown]',
|
|
87
|
-
prevElement.key
|
|
88
|
-
) : null);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return ownersMatch;
|
|
94
|
-
}
|
|
33
|
+
return nextType === 'object' && prevElement.type === nextElement.type && prevElement.key === nextElement.key;
|
|
95
34
|
}
|
|
96
35
|
}
|
|
97
36
|
return false;
|
|
98
37
|
}
|
|
99
38
|
|
|
100
|
-
module.exports = shouldUpdateReactComponent;
|
|
39
|
+
module.exports = shouldUpdateReactComponent;
|
package/lib/toArray.js
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* @typechecks
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
13
15
|
var invariant = require("./invariant");
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -26,24 +28,11 @@ function toArray(obj) {
|
|
|
26
28
|
|
|
27
29
|
// Some browse builtin objects can report typeof 'function' (e.g. NodeList in
|
|
28
30
|
// old versions of Safari).
|
|
29
|
-
(
|
|
30
|
-
!Array.isArray(obj) &&
|
|
31
|
-
(typeof obj === 'object' || typeof obj === 'function'),
|
|
32
|
-
'toArray: Array-like object expected'
|
|
33
|
-
) : invariant(!Array.isArray(obj) &&
|
|
34
|
-
(typeof obj === 'object' || typeof obj === 'function')));
|
|
31
|
+
!(!Array.isArray(obj) && (typeof obj === 'object' || typeof obj === 'function')) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'toArray: Array-like object expected') : invariant(false) : undefined;
|
|
35
32
|
|
|
36
|
-
(
|
|
37
|
-
typeof length === 'number',
|
|
38
|
-
'toArray: Object needs a length property'
|
|
39
|
-
) : invariant(typeof length === 'number'));
|
|
33
|
+
!(typeof length === 'number') ? 'production' !== process.env.NODE_ENV ? invariant(false, 'toArray: Object needs a length property') : invariant(false) : undefined;
|
|
40
34
|
|
|
41
|
-
(
|
|
42
|
-
length === 0 ||
|
|
43
|
-
(length - 1) in obj,
|
|
44
|
-
'toArray: Object should have keys for indices'
|
|
45
|
-
) : invariant(length === 0 ||
|
|
46
|
-
(length - 1) in obj));
|
|
35
|
+
!(length === 0 || length - 1 in obj) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'toArray: Object should have keys for indices') : invariant(false) : undefined;
|
|
47
36
|
|
|
48
37
|
// Old IE doesn't give collections access to hasOwnProperty. Assume inputs
|
|
49
38
|
// without method will throw during the slice call and skip straight to the
|
|
@@ -51,9 +40,7 @@ function toArray(obj) {
|
|
|
51
40
|
if (obj.hasOwnProperty) {
|
|
52
41
|
try {
|
|
53
42
|
return Array.prototype.slice.call(obj);
|
|
54
|
-
} catch (e) {
|
|
55
|
-
// IE < 9 does not support Array#slice on collections objects
|
|
56
|
-
}
|
|
43
|
+
} catch (e) {}
|
|
57
44
|
}
|
|
58
45
|
|
|
59
46
|
// Fall back to copying key by key. This assumes all keys have a value,
|
|
@@ -66,3 +53,5 @@ function toArray(obj) {
|
|
|
66
53
|
}
|
|
67
54
|
|
|
68
55
|
module.exports = toArray;
|
|
56
|
+
|
|
57
|
+
// IE < 9 does not support Array#slice on collections objects
|
|
@@ -64,10 +64,7 @@ function getComponentKey(component, index) {
|
|
|
64
64
|
* @return {string} An escaped string.
|
|
65
65
|
*/
|
|
66
66
|
function escapeUserProvidedKey(text) {
|
|
67
|
-
return ('' + text).replace(
|
|
68
|
-
userProvidedKeyEscapeRegex,
|
|
69
|
-
userProvidedKeyEscaper
|
|
70
|
-
);
|
|
67
|
+
return ('' + text).replace(userProvidedKeyEscapeRegex, userProvidedKeyEscaper);
|
|
71
68
|
}
|
|
72
69
|
|
|
73
70
|
/**
|
|
@@ -84,19 +81,12 @@ function wrapUserProvidedKey(key) {
|
|
|
84
81
|
/**
|
|
85
82
|
* @param {?*} children Children tree container.
|
|
86
83
|
* @param {!string} nameSoFar Name of the key path so far.
|
|
87
|
-
* @param {!number} indexSoFar Number of children encountered until this point.
|
|
88
84
|
* @param {!function} callback Callback to invoke with each child found.
|
|
89
85
|
* @param {?*} traverseContext Used to pass information throughout the traversal
|
|
90
86
|
* process.
|
|
91
87
|
* @return {!number} The number of children in this subtree.
|
|
92
88
|
*/
|
|
93
|
-
function traverseAllChildrenImpl(
|
|
94
|
-
children,
|
|
95
|
-
nameSoFar,
|
|
96
|
-
indexSoFar,
|
|
97
|
-
callback,
|
|
98
|
-
traverseContext
|
|
99
|
-
) {
|
|
89
|
+
function traverseAllChildrenImpl(children, nameSoFar, callback, traverseContext) {
|
|
100
90
|
var type = typeof children;
|
|
101
91
|
|
|
102
92
|
if (type === 'undefined' || type === 'boolean') {
|
|
@@ -104,39 +94,23 @@ function traverseAllChildrenImpl(
|
|
|
104
94
|
children = null;
|
|
105
95
|
}
|
|
106
96
|
|
|
107
|
-
if (children === null ||
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
traverseContext,
|
|
113
|
-
children,
|
|
114
|
-
// If it's the only child, treat the name as if it was wrapped in an array
|
|
115
|
-
// so that it's consistent if the number of children grows.
|
|
116
|
-
nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar,
|
|
117
|
-
indexSoFar
|
|
118
|
-
);
|
|
97
|
+
if (children === null || type === 'string' || type === 'number' || ReactElement.isValidElement(children)) {
|
|
98
|
+
callback(traverseContext, children,
|
|
99
|
+
// If it's the only child, treat the name as if it was wrapped in an array
|
|
100
|
+
// so that it's consistent if the number of children grows.
|
|
101
|
+
nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar);
|
|
119
102
|
return 1;
|
|
120
103
|
}
|
|
121
104
|
|
|
122
|
-
var child
|
|
105
|
+
var child;
|
|
106
|
+
var nextName;
|
|
123
107
|
var subtreeCount = 0; // Count of children found in the current subtree.
|
|
124
108
|
|
|
125
109
|
if (Array.isArray(children)) {
|
|
126
110
|
for (var i = 0; i < children.length; i++) {
|
|
127
111
|
child = children[i];
|
|
128
|
-
nextName = (
|
|
129
|
-
|
|
130
|
-
getComponentKey(child, i)
|
|
131
|
-
);
|
|
132
|
-
nextIndex = indexSoFar + subtreeCount;
|
|
133
|
-
subtreeCount += traverseAllChildrenImpl(
|
|
134
|
-
child,
|
|
135
|
-
nextName,
|
|
136
|
-
nextIndex,
|
|
137
|
-
callback,
|
|
138
|
-
traverseContext
|
|
139
|
-
);
|
|
112
|
+
nextName = (nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) + getComponentKey(child, i);
|
|
113
|
+
subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
|
|
140
114
|
}
|
|
141
115
|
} else {
|
|
142
116
|
var iteratorFn = getIteratorFn(children);
|
|
@@ -147,27 +121,12 @@ function traverseAllChildrenImpl(
|
|
|
147
121
|
var ii = 0;
|
|
148
122
|
while (!(step = iterator.next()).done) {
|
|
149
123
|
child = step.value;
|
|
150
|
-
nextName = (
|
|
151
|
-
|
|
152
|
-
getComponentKey(child, ii++)
|
|
153
|
-
);
|
|
154
|
-
nextIndex = indexSoFar + subtreeCount;
|
|
155
|
-
subtreeCount += traverseAllChildrenImpl(
|
|
156
|
-
child,
|
|
157
|
-
nextName,
|
|
158
|
-
nextIndex,
|
|
159
|
-
callback,
|
|
160
|
-
traverseContext
|
|
161
|
-
);
|
|
124
|
+
nextName = (nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) + getComponentKey(child, ii++);
|
|
125
|
+
subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
|
|
162
126
|
}
|
|
163
127
|
} else {
|
|
164
|
-
if (
|
|
165
|
-
|
|
166
|
-
didWarnAboutMaps,
|
|
167
|
-
'Using Maps as children is not yet fully supported. It is an ' +
|
|
168
|
-
'experimental feature that might be removed. Convert it to a ' +
|
|
169
|
-
'sequence / iterable of keyed ReactElements instead.'
|
|
170
|
-
) : null);
|
|
128
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
129
|
+
'production' !== process.env.NODE_ENV ? warning(didWarnAboutMaps, 'Using Maps as children is not yet fully supported. It is an ' + 'experimental feature that might be removed. Convert it to a ' + 'sequence / iterable of keyed ReactElements instead.') : undefined;
|
|
171
130
|
didWarnAboutMaps = true;
|
|
172
131
|
}
|
|
173
132
|
// Iterator will provide entry [k,v] tuples rather than values.
|
|
@@ -175,45 +134,19 @@ function traverseAllChildrenImpl(
|
|
|
175
134
|
var entry = step.value;
|
|
176
135
|
if (entry) {
|
|
177
136
|
child = entry[1];
|
|
178
|
-
nextName = (
|
|
179
|
-
|
|
180
|
-
wrapUserProvidedKey(entry[0]) + SUBSEPARATOR +
|
|
181
|
-
getComponentKey(child, 0)
|
|
182
|
-
);
|
|
183
|
-
nextIndex = indexSoFar + subtreeCount;
|
|
184
|
-
subtreeCount += traverseAllChildrenImpl(
|
|
185
|
-
child,
|
|
186
|
-
nextName,
|
|
187
|
-
nextIndex,
|
|
188
|
-
callback,
|
|
189
|
-
traverseContext
|
|
190
|
-
);
|
|
137
|
+
nextName = (nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) + wrapUserProvidedKey(entry[0]) + SUBSEPARATOR + getComponentKey(child, 0);
|
|
138
|
+
subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
|
|
191
139
|
}
|
|
192
140
|
}
|
|
193
141
|
}
|
|
194
142
|
} else if (type === 'object') {
|
|
195
|
-
(
|
|
196
|
-
children.nodeType !== 1,
|
|
197
|
-
'traverseAllChildren(...): Encountered an invalid child; DOM ' +
|
|
198
|
-
'elements are not valid children of React components.'
|
|
199
|
-
) : invariant(children.nodeType !== 1));
|
|
143
|
+
!(children.nodeType !== 1) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'traverseAllChildren(...): Encountered an invalid child; DOM ' + 'elements are not valid children of React components.') : invariant(false) : undefined;
|
|
200
144
|
var fragment = ReactFragment.extract(children);
|
|
201
145
|
for (var key in fragment) {
|
|
202
146
|
if (fragment.hasOwnProperty(key)) {
|
|
203
147
|
child = fragment[key];
|
|
204
|
-
nextName = (
|
|
205
|
-
|
|
206
|
-
wrapUserProvidedKey(key) + SUBSEPARATOR +
|
|
207
|
-
getComponentKey(child, 0)
|
|
208
|
-
);
|
|
209
|
-
nextIndex = indexSoFar + subtreeCount;
|
|
210
|
-
subtreeCount += traverseAllChildrenImpl(
|
|
211
|
-
child,
|
|
212
|
-
nextName,
|
|
213
|
-
nextIndex,
|
|
214
|
-
callback,
|
|
215
|
-
traverseContext
|
|
216
|
-
);
|
|
148
|
+
nextName = (nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) + wrapUserProvidedKey(key) + SUBSEPARATOR + getComponentKey(child, 0);
|
|
149
|
+
subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
|
|
217
150
|
}
|
|
218
151
|
}
|
|
219
152
|
}
|
|
@@ -243,7 +176,7 @@ function traverseAllChildren(children, callback, traverseContext) {
|
|
|
243
176
|
return 0;
|
|
244
177
|
}
|
|
245
178
|
|
|
246
|
-
return traverseAllChildrenImpl(children, '',
|
|
179
|
+
return traverseAllChildrenImpl(children, '', callback, traverseContext);
|
|
247
180
|
}
|
|
248
181
|
|
|
249
|
-
module.exports = traverseAllChildren;
|
|
182
|
+
module.exports = traverseAllChildren;
|