react 0.13.0 → 0.14.0-alpha1

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 (194) 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 +3336 -1671
  16. package/dist/react-with-addons.js +3134 -5113
  17. package/dist/react-with-addons.min.js +6 -6
  18. package/dist/react.js +2812 -4567
  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 +9 -4
  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 -65
  30. package/lib/DOMPropertyOperations.js +30 -51
  31. package/lib/Danger.js +19 -60
  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 +12 -18
  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 +20 -38
  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 +7 -16
  55. package/lib/ReactClass.js +78 -231
  56. package/lib/ReactComponent.js +17 -33
  57. package/lib/ReactComponentBrowserEnvironment.js +4 -6
  58. package/lib/ReactComponentEnvironment.js +6 -12
  59. package/lib/ReactComponentWithPureRenderMixin.js +4 -5
  60. package/lib/ReactCompositeComponent.js +85 -297
  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/ReactDOMComponent.js +185 -146
  66. package/lib/ReactDOMForm.js +3 -3
  67. package/lib/ReactDOMIDOperations.js +11 -20
  68. package/lib/ReactDOMIframe.js +3 -3
  69. package/lib/ReactDOMImg.js +3 -3
  70. package/lib/ReactDOMInput.js +22 -35
  71. package/lib/ReactDOMOption.js +52 -10
  72. package/lib/ReactDOMSelect.js +53 -29
  73. package/lib/ReactDOMSelection.js +5 -20
  74. package/lib/ReactDOMTextComponent.js +17 -18
  75. package/lib/ReactDOMTextarea.js +15 -27
  76. package/lib/ReactDefaultBatchingStrategy.js +9 -13
  77. package/lib/ReactDefaultInjection.js +21 -40
  78. package/lib/ReactDefaultPerf.js +41 -72
  79. package/lib/ReactDefaultPerfAnalysis.js +8 -14
  80. package/lib/ReactElement.js +35 -72
  81. package/lib/ReactElementValidator.js +51 -110
  82. package/lib/ReactEmptyComponent.js +7 -11
  83. package/lib/ReactErrorUtils.js +2 -2
  84. package/lib/ReactEventEmitterMixin.js +3 -12
  85. package/lib/ReactEventListener.js +16 -38
  86. package/lib/ReactFragment.js +23 -54
  87. package/lib/ReactInjection.js +1 -1
  88. package/lib/ReactInputSelection.js +11 -21
  89. package/lib/ReactInstanceHandles.js +27 -57
  90. package/lib/ReactInstanceMap.js +5 -5
  91. package/lib/ReactLifeCycle.js +1 -1
  92. package/lib/ReactLink.js +2 -4
  93. package/lib/ReactMarkupChecksum.js +5 -10
  94. package/lib/ReactMount.js +136 -260
  95. package/lib/ReactMultiChild.js +19 -45
  96. package/lib/ReactMultiChildUpdateTypes.js +1 -1
  97. package/lib/ReactNativeComponent.js +7 -11
  98. package/lib/ReactOwner.js +7 -24
  99. package/lib/ReactPerf.js +8 -12
  100. package/lib/ReactPropTransferer.js +4 -4
  101. package/lib/ReactPropTypeLocationNames.js +2 -2
  102. package/lib/ReactPropTypeLocations.js +1 -1
  103. package/lib/ReactPropTypes.js +13 -46
  104. package/lib/ReactReconcileTransaction.js +9 -34
  105. package/lib/ReactReconciler.js +9 -19
  106. package/lib/ReactRef.js +5 -8
  107. package/lib/ReactRootIndex.js +2 -2
  108. package/lib/ReactServerRendering.js +7 -15
  109. package/lib/ReactServerRenderingTransaction.js +7 -32
  110. package/lib/ReactStateSetters.js +6 -6
  111. package/lib/ReactTestUtils.js +94 -166
  112. package/lib/ReactTransitionChildMapping.js +5 -7
  113. package/lib/ReactTransitionEvents.js +5 -5
  114. package/lib/ReactTransitionGroup.js +30 -52
  115. package/lib/ReactUpdateQueue.js +27 -90
  116. package/lib/ReactUpdates.js +27 -79
  117. package/lib/ReactWithAddons.js +7 -6
  118. package/lib/SVGDOMPropertyConfig.js +41 -2
  119. package/lib/SelectEventPlugin.js +28 -29
  120. package/lib/ServerReactRootIndex.js +2 -2
  121. package/lib/SimpleEventPlugin.js +136 -128
  122. package/lib/SyntheticClipboardEvent.js +3 -7
  123. package/lib/SyntheticCompositionEvent.js +3 -9
  124. package/lib/SyntheticDragEvent.js +1 -1
  125. package/lib/SyntheticEvent.js +8 -10
  126. package/lib/SyntheticFocusEvent.js +1 -1
  127. package/lib/SyntheticInputEvent.js +3 -9
  128. package/lib/SyntheticKeyboardEvent.js +4 -4
  129. package/lib/SyntheticMouseEvent.js +8 -14
  130. package/lib/SyntheticTouchEvent.js +1 -1
  131. package/lib/SyntheticUIEvent.js +3 -3
  132. package/lib/SyntheticWheelEvent.js +11 -15
  133. package/lib/Transaction.js +12 -24
  134. package/lib/ViewportMetrics.js +2 -2
  135. package/lib/accumulateInto.js +2 -5
  136. package/lib/adler32.js +2 -2
  137. package/lib/camelize.js +4 -2
  138. package/lib/camelizeStyleName.js +2 -2
  139. package/lib/cloneWithProps.js +5 -11
  140. package/lib/containsNode.js +29 -16
  141. package/lib/createArrayFromMixed.js +17 -16
  142. package/lib/createFullPageComponent.js +5 -11
  143. package/lib/createNodesFromMarkup.js +6 -8
  144. package/lib/dangerousStyleValue.js +2 -3
  145. package/lib/emptyFunction.js +10 -4
  146. package/lib/emptyObject.js +1 -1
  147. package/lib/escapeTextContentForBrowser.js +1 -1
  148. package/lib/findDOMNode.js +5 -24
  149. package/lib/flattenChildren.js +4 -10
  150. package/lib/focusNode.js +2 -3
  151. package/lib/forEachAccumulated.js +2 -2
  152. package/lib/getActiveElement.js +4 -2
  153. package/lib/getEventCharCode.js +1 -1
  154. package/lib/getEventKey.js +1 -1
  155. package/lib/getEventModifierState.js +1 -1
  156. package/lib/getEventTarget.js +1 -1
  157. package/lib/getIteratorFn.js +2 -4
  158. package/lib/getMarkupWrap.js +7 -5
  159. package/lib/getNodeForCharacterOffset.js +1 -1
  160. package/lib/getTextContentAccessor.js +2 -4
  161. package/lib/getUnboundedScrollPosition.js +1 -1
  162. package/lib/hyphenate.js +3 -1
  163. package/lib/hyphenateStyleName.js +2 -2
  164. package/lib/instantiateReactComponent.js +14 -37
  165. package/lib/invariant.js +8 -12
  166. package/lib/isEventSupported.js +7 -10
  167. package/lib/isNode.js +4 -6
  168. package/lib/isTextInputElement.js +2 -4
  169. package/lib/isTextNode.js +3 -1
  170. package/lib/joinClasses.js +2 -2
  171. package/lib/keyMirror.js +3 -6
  172. package/lib/keyOf.js +4 -3
  173. package/lib/mapObject.js +1 -1
  174. package/lib/memoizeStringOnly.js +2 -2
  175. package/lib/onlyChild.js +2 -5
  176. package/lib/performance.js +2 -5
  177. package/lib/performanceNow.js +3 -1
  178. package/lib/quoteAttributeValueForBrowser.js +1 -1
  179. package/lib/renderSubtreeIntoContainer.js +16 -0
  180. package/lib/setInnerHTML.js +11 -8
  181. package/lib/setTextContent.js +3 -3
  182. package/lib/shallowCompare.js +24 -0
  183. package/lib/shallowEqual.js +17 -11
  184. package/lib/shouldUpdateReactComponent.js +3 -64
  185. package/lib/toArray.js +8 -19
  186. package/lib/traverseAllChildren.js +19 -82
  187. package/lib/update.js +33 -90
  188. package/lib/validateDOMNesting.js +264 -0
  189. package/lib/warning.js +17 -15
  190. package/package.json +3 -3
  191. package/lib/MobileSafariClickEventPlugin.js +0 -56
  192. package/lib/ReactPutListenerQueue.js +0 -54
  193. package/lib/cx.js +0 -52
  194. 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
+ 'production' !== process.env.NODE_ENV ? invariant(!Array.isArray(obj) && (typeof obj === 'object' || typeof obj === 'function'), 'toArray: Array-like object expected') : invariant(!Array.isArray(obj) && (typeof obj === 'object' || typeof obj === 'function'));
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
+ 'production' !== process.env.NODE_ENV ? invariant(typeof length === 'number', 'toArray: Object needs a length property') : invariant(typeof length === 'number');
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
+ 'production' !== process.env.NODE_ENV ? invariant(length === 0 || length - 1 in obj, 'toArray: Object should have keys for indices') : invariant(length === 0 || length - 1 in obj);
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
  /**
@@ -90,13 +87,7 @@ function wrapUserProvidedKey(key) {
90
87
  * process.
91
88
  * @return {!number} The number of children in this subtree.
92
89
  */
93
- function traverseAllChildrenImpl(
94
- children,
95
- nameSoFar,
96
- indexSoFar,
97
- callback,
98
- traverseContext
99
- ) {
90
+ function traverseAllChildrenImpl(children, nameSoFar, indexSoFar, callback, traverseContext) {
100
91
  var type = typeof children;
101
92
 
102
93
  if (type === 'undefined' || type === 'boolean') {
@@ -104,18 +95,11 @@ function traverseAllChildrenImpl(
104
95
  children = null;
105
96
  }
106
97
 
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
- );
98
+ if (children === null || type === 'string' || type === 'number' || ReactElement.isValidElement(children)) {
99
+ callback(traverseContext, children,
100
+ // If it's the only child, treat the name as if it was wrapped in an array
101
+ // so that it's consistent if the number of children grows.
102
+ nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar, indexSoFar);
119
103
  return 1;
120
104
  }
121
105
 
@@ -125,18 +109,9 @@ function traverseAllChildrenImpl(
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
- );
112
+ nextName = (nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) + getComponentKey(child, i);
132
113
  nextIndex = indexSoFar + subtreeCount;
133
- subtreeCount += traverseAllChildrenImpl(
134
- child,
135
- nextName,
136
- nextIndex,
137
- callback,
138
- traverseContext
139
- );
114
+ subtreeCount += traverseAllChildrenImpl(child, nextName, nextIndex, callback, traverseContext);
140
115
  }
141
116
  } else {
142
117
  var iteratorFn = getIteratorFn(children);
@@ -147,27 +122,13 @@ function traverseAllChildrenImpl(
147
122
  var ii = 0;
148
123
  while (!(step = iterator.next()).done) {
149
124
  child = step.value;
150
- nextName = (
151
- (nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) +
152
- getComponentKey(child, ii++)
153
- );
125
+ nextName = (nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) + getComponentKey(child, ii++);
154
126
  nextIndex = indexSoFar + subtreeCount;
155
- subtreeCount += traverseAllChildrenImpl(
156
- child,
157
- nextName,
158
- nextIndex,
159
- callback,
160
- traverseContext
161
- );
127
+ subtreeCount += traverseAllChildrenImpl(child, nextName, nextIndex, callback, traverseContext);
162
128
  }
163
129
  } 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);
130
+ if ('production' !== process.env.NODE_ENV) {
131
+ '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.') : null;
171
132
  didWarnAboutMaps = true;
172
133
  }
173
134
  // Iterator will provide entry [k,v] tuples rather than values.
@@ -175,45 +136,21 @@ function traverseAllChildrenImpl(
175
136
  var entry = step.value;
176
137
  if (entry) {
177
138
  child = entry[1];
178
- nextName = (
179
- (nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) +
180
- wrapUserProvidedKey(entry[0]) + SUBSEPARATOR +
181
- getComponentKey(child, 0)
182
- );
139
+ nextName = (nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) + wrapUserProvidedKey(entry[0]) + SUBSEPARATOR + getComponentKey(child, 0);
183
140
  nextIndex = indexSoFar + subtreeCount;
184
- subtreeCount += traverseAllChildrenImpl(
185
- child,
186
- nextName,
187
- nextIndex,
188
- callback,
189
- traverseContext
190
- );
141
+ subtreeCount += traverseAllChildrenImpl(child, nextName, nextIndex, callback, traverseContext);
191
142
  }
192
143
  }
193
144
  }
194
145
  } 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));
146
+ 'production' !== process.env.NODE_ENV ? invariant(children.nodeType !== 1, 'traverseAllChildren(...): Encountered an invalid child; DOM ' + 'elements are not valid children of React components.') : invariant(children.nodeType !== 1);
200
147
  var fragment = ReactFragment.extract(children);
201
148
  for (var key in fragment) {
202
149
  if (fragment.hasOwnProperty(key)) {
203
150
  child = fragment[key];
204
- nextName = (
205
- (nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) +
206
- wrapUserProvidedKey(key) + SUBSEPARATOR +
207
- getComponentKey(child, 0)
208
- );
151
+ nextName = (nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) + wrapUserProvidedKey(key) + SUBSEPARATOR + getComponentKey(child, 0);
209
152
  nextIndex = indexSoFar + subtreeCount;
210
- subtreeCount += traverseAllChildrenImpl(
211
- child,
212
- nextName,
213
- nextIndex,
214
- callback,
215
- traverseContext
216
- );
153
+ subtreeCount += traverseAllChildrenImpl(child, nextName, nextIndex, callback, traverseContext);
217
154
  }
218
155
  }
219
156
  }
@@ -246,4 +183,4 @@ function traverseAllChildren(children, callback, traverseContext) {
246
183
  return traverseAllChildrenImpl(children, '', 0, callback, traverseContext);
247
184
  }
248
185
 
249
- module.exports = traverseAllChildren;
186
+ module.exports = traverseAllChildren;