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.
Files changed (197) hide show
  1. package/README.md +1 -1
  2. package/addons.js +7 -0
  3. package/addons/CSSTransitionGroup.js +1 -0
  4. package/addons/LinkedStateMixin.js +1 -0
  5. package/addons/Perf.js +1 -0
  6. package/addons/PureRenderMixin.js +1 -0
  7. package/addons/TestUtils.js +1 -0
  8. package/addons/TransitionGroup.js +1 -0
  9. package/addons/batchedUpdates.js +1 -0
  10. package/addons/cloneWithProps.js +1 -0
  11. package/addons/createFragment.js +1 -0
  12. package/addons/renderSubtreeIntoContainer.js +1 -0
  13. package/addons/shallowCompare.js +1 -0
  14. package/addons/update.js +1 -0
  15. package/dist/JSXTransformer.js +3355 -1685
  16. package/dist/react-with-addons.js +3320 -5133
  17. package/dist/react-with-addons.min.js +6 -7
  18. package/dist/react.js +2962 -4548
  19. package/dist/react.min.js +5 -5
  20. package/lib/AutoFocusMixin.js +4 -3
  21. package/lib/BeforeInputEventPlugin.js +30 -118
  22. package/lib/CSSCore.js +12 -23
  23. package/lib/CSSProperty.js +4 -3
  24. package/lib/CSSPropertyOperations.js +14 -30
  25. package/lib/CallbackQueue.js +7 -10
  26. package/lib/ChangeEventPlugin.js +24 -88
  27. package/lib/ClientReactRootIndex.js +2 -2
  28. package/lib/DOMChildrenOperations.js +13 -33
  29. package/lib/DOMProperty.js +41 -67
  30. package/lib/DOMPropertyOperations.js +30 -51
  31. package/lib/Danger.js +19 -62
  32. package/lib/DefaultEventPluginOrder.js +2 -12
  33. package/lib/EnterLeaveEventPlugin.js +11 -33
  34. package/lib/EventConstants.js +2 -2
  35. package/lib/EventListener.js +11 -13
  36. package/lib/EventPluginHub.js +44 -47
  37. package/lib/EventPluginRegistry.js +18 -74
  38. package/lib/EventPluginUtils.js +27 -38
  39. package/lib/EventPropagators.js +23 -26
  40. package/lib/ExecutionEnvironment.js +4 -8
  41. package/lib/FallbackCompositionState.js +3 -3
  42. package/lib/HTMLDOMPropertyConfig.js +7 -19
  43. package/lib/LinkedStateMixin.js +3 -6
  44. package/lib/LinkedValueUtils.js +34 -64
  45. package/lib/LocalEventTrapMixin.js +9 -16
  46. package/lib/Object.assign.js +1 -1
  47. package/lib/PooledClass.js +8 -11
  48. package/lib/React.js +9 -129
  49. package/lib/ReactBrowserComponentMixin.js +9 -2
  50. package/lib/ReactBrowserEventEmitter.js +26 -82
  51. package/lib/ReactCSSTransitionGroup.js +13 -24
  52. package/lib/ReactCSSTransitionGroupChild.js +18 -28
  53. package/lib/ReactChildReconciler.js +11 -19
  54. package/lib/ReactChildren.js +21 -28
  55. package/lib/ReactClass.js +81 -234
  56. package/lib/ReactComponent.js +17 -33
  57. package/lib/ReactComponentBrowserEnvironment.js +4 -8
  58. package/lib/ReactComponentEnvironment.js +6 -12
  59. package/lib/ReactComponentWithPureRenderMixin.js +4 -5
  60. package/lib/ReactCompositeComponent.js +87 -311
  61. package/lib/ReactContext.js +2 -44
  62. package/lib/ReactCurrentOwner.js +1 -3
  63. package/lib/ReactDOM.js +4 -2
  64. package/lib/ReactDOMButton.js +3 -4
  65. package/lib/ReactDOMClient.js +85 -0
  66. package/lib/ReactDOMComponent.js +182 -146
  67. package/lib/ReactDOMForm.js +3 -3
  68. package/lib/ReactDOMIDOperations.js +11 -22
  69. package/lib/ReactDOMIframe.js +3 -3
  70. package/lib/ReactDOMImg.js +3 -3
  71. package/lib/ReactDOMInput.js +22 -35
  72. package/lib/ReactDOMOption.js +67 -10
  73. package/lib/ReactDOMSelect.js +50 -28
  74. package/lib/ReactDOMSelection.js +5 -20
  75. package/lib/ReactDOMServer.js +24 -0
  76. package/lib/ReactDOMTextComponent.js +17 -18
  77. package/lib/ReactDOMTextarea.js +15 -27
  78. package/lib/ReactDefaultBatchingStrategy.js +9 -13
  79. package/lib/ReactDefaultInjection.js +31 -40
  80. package/lib/ReactDefaultPerf.js +36 -69
  81. package/lib/ReactDefaultPerfAnalysis.js +8 -14
  82. package/lib/ReactElement.js +24 -57
  83. package/lib/ReactElementValidator.js +38 -105
  84. package/lib/ReactEmptyComponent.js +7 -11
  85. package/lib/ReactErrorUtils.js +2 -2
  86. package/lib/ReactEventEmitterMixin.js +3 -12
  87. package/lib/ReactEventListener.js +16 -38
  88. package/lib/ReactFragment.js +23 -54
  89. package/lib/ReactInjection.js +1 -1
  90. package/lib/ReactInputSelection.js +11 -21
  91. package/lib/ReactInstanceHandles.js +27 -57
  92. package/lib/ReactInstanceMap.js +5 -5
  93. package/lib/ReactIsomorphic.js +70 -0
  94. package/lib/ReactLifeCycle.js +1 -1
  95. package/lib/ReactLink.js +2 -4
  96. package/lib/ReactMarkupChecksum.js +5 -10
  97. package/lib/ReactMount.js +137 -260
  98. package/lib/ReactMultiChild.js +19 -45
  99. package/lib/ReactMultiChildUpdateTypes.js +1 -1
  100. package/lib/ReactNativeComponent.js +7 -11
  101. package/lib/ReactOwner.js +7 -24
  102. package/lib/ReactPerf.js +8 -12
  103. package/lib/ReactPropTransferer.js +4 -4
  104. package/lib/ReactPropTypeLocationNames.js +2 -2
  105. package/lib/ReactPropTypeLocations.js +1 -1
  106. package/lib/ReactPropTypes.js +41 -61
  107. package/lib/ReactReconcileTransaction.js +9 -34
  108. package/lib/ReactReconciler.js +9 -19
  109. package/lib/ReactRef.js +5 -8
  110. package/lib/ReactRootIndex.js +2 -2
  111. package/lib/ReactServerRendering.js +7 -15
  112. package/lib/ReactServerRenderingTransaction.js +7 -32
  113. package/lib/ReactStateSetters.js +6 -6
  114. package/lib/ReactTestUtils.js +93 -165
  115. package/lib/ReactTransitionChildMapping.js +5 -7
  116. package/lib/ReactTransitionEvents.js +5 -5
  117. package/lib/ReactTransitionGroup.js +30 -52
  118. package/lib/ReactUpdateQueue.js +27 -90
  119. package/lib/ReactUpdates.js +27 -79
  120. package/lib/ReactWithAddons.js +7 -6
  121. package/lib/SVGDOMPropertyConfig.js +41 -4
  122. package/lib/SelectEventPlugin.js +28 -29
  123. package/lib/ServerReactRootIndex.js +2 -2
  124. package/lib/SimpleEventPlugin.js +136 -128
  125. package/lib/SyntheticClipboardEvent.js +3 -7
  126. package/lib/SyntheticCompositionEvent.js +3 -9
  127. package/lib/SyntheticDragEvent.js +1 -1
  128. package/lib/SyntheticEvent.js +8 -10
  129. package/lib/SyntheticFocusEvent.js +1 -1
  130. package/lib/SyntheticInputEvent.js +3 -9
  131. package/lib/SyntheticKeyboardEvent.js +4 -4
  132. package/lib/SyntheticMouseEvent.js +8 -14
  133. package/lib/SyntheticTouchEvent.js +1 -1
  134. package/lib/SyntheticUIEvent.js +3 -3
  135. package/lib/SyntheticWheelEvent.js +11 -15
  136. package/lib/Transaction.js +12 -24
  137. package/lib/ViewportMetrics.js +2 -2
  138. package/lib/accumulateInto.js +2 -5
  139. package/lib/adler32.js +2 -4
  140. package/lib/camelize.js +4 -2
  141. package/lib/camelizeStyleName.js +2 -2
  142. package/lib/cloneWithProps.js +5 -11
  143. package/lib/containsNode.js +29 -16
  144. package/lib/createArrayFromMixed.js +17 -16
  145. package/lib/createFullPageComponent.js +4 -11
  146. package/lib/createNodesFromMarkup.js +6 -8
  147. package/lib/dangerousStyleValue.js +2 -3
  148. package/lib/emptyFunction.js +10 -4
  149. package/lib/emptyObject.js +1 -1
  150. package/lib/escapeTextContentForBrowser.js +1 -1
  151. package/lib/findDOMNode.js +5 -24
  152. package/lib/flattenChildren.js +4 -10
  153. package/lib/focusNode.js +2 -3
  154. package/lib/forEachAccumulated.js +2 -2
  155. package/lib/getActiveElement.js +4 -2
  156. package/lib/getEventCharCode.js +1 -1
  157. package/lib/getEventKey.js +1 -1
  158. package/lib/getEventModifierState.js +1 -1
  159. package/lib/getEventTarget.js +1 -1
  160. package/lib/getIteratorFn.js +2 -4
  161. package/lib/getMarkupWrap.js +7 -5
  162. package/lib/getNodeForCharacterOffset.js +1 -1
  163. package/lib/getTextContentAccessor.js +2 -4
  164. package/lib/getUnboundedScrollPosition.js +1 -1
  165. package/lib/hyphenate.js +3 -1
  166. package/lib/hyphenateStyleName.js +2 -2
  167. package/lib/instantiateReactComponent.js +14 -38
  168. package/lib/invariant.js +8 -12
  169. package/lib/isEventSupported.js +7 -10
  170. package/lib/isNode.js +4 -6
  171. package/lib/isTextInputElement.js +2 -4
  172. package/lib/isTextNode.js +3 -1
  173. package/lib/joinClasses.js +2 -2
  174. package/lib/keyMirror.js +3 -6
  175. package/lib/keyOf.js +4 -3
  176. package/lib/mapObject.js +1 -1
  177. package/lib/memoizeStringOnly.js +2 -2
  178. package/lib/onlyChild.js +2 -5
  179. package/lib/performance.js +2 -5
  180. package/lib/performanceNow.js +3 -1
  181. package/lib/quoteAttributeValueForBrowser.js +1 -1
  182. package/lib/renderSubtreeIntoContainer.js +16 -0
  183. package/lib/setInnerHTML.js +11 -8
  184. package/lib/setTextContent.js +3 -3
  185. package/lib/shallowCompare.js +24 -0
  186. package/lib/shallowEqual.js +17 -11
  187. package/lib/shouldUpdateReactComponent.js +3 -64
  188. package/lib/toArray.js +8 -19
  189. package/lib/traverseAllChildren.js +22 -89
  190. package/lib/update.js +25 -85
  191. package/lib/validateDOMNesting.js +363 -0
  192. package/lib/warning.js +17 -15
  193. package/package.json +3 -3
  194. package/lib/MobileSafariClickEventPlugin.js +0 -56
  195. package/lib/ReactPutListenerQueue.js +0 -54
  196. package/lib/cx.js +0 -52
  197. package/lib/getReactRootElementInContainer.js +0 -33
@@ -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;
@@ -23,4 +23,4 @@ function quoteAttributeValueForBrowser(value) {
23
23
  return '"' + escapeTextContentForBrowser(value) + '"';
24
24
  }
25
25
 
26
- module.exports = quoteAttributeValueForBrowser;
26
+ module.exports = quoteAttributeValueForBrowser;
@@ -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;
@@ -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
- node.innerHTML = '\uFEFF' + html;
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;
@@ -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;
@@ -22,21 +22,27 @@ function shallowEqual(objA, objB) {
22
22
  if (objA === objB) {
23
23
  return true;
24
24
  }
25
- var key;
26
- // Test for A's keys different from B.
27
- for (key in objA) {
28
- if (objA.hasOwnProperty(key) &&
29
- (!objB.hasOwnProperty(key) || objA[key] !== objB[key])) {
30
- return false;
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
- // Test for B's keys missing from A.
34
- for (key in objB) {
35
- if (objB.hasOwnProperty(key) && !objA.hasOwnProperty(key)) {
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 (nextType === 'string' || nextType === 'number');
31
+ return nextType === 'string' || nextType === 'number';
34
32
  } else {
35
- if (nextType === 'object' &&
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
- ("production" !== process.env.NODE_ENV ? invariant(
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
- ("production" !== process.env.NODE_ENV ? invariant(
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
- ("production" !== process.env.NODE_ENV ? invariant(
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
- type === 'string' ||
109
- type === 'number' ||
110
- ReactElement.isValidElement(children)) {
111
- callback(
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, nextName, nextIndex;
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
- (nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) +
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
- (nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) +
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 ("production" !== process.env.NODE_ENV) {
165
- ("production" !== process.env.NODE_ENV ? warning(
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
- (nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) +
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
- ("production" !== process.env.NODE_ENV ? invariant(
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
- (nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) +
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, '', 0, callback, traverseContext);
179
+ return traverseAllChildrenImpl(children, '', callback, traverseContext);
247
180
  }
248
181
 
249
- module.exports = traverseAllChildren;
182
+ module.exports = traverseAllChildren;