Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/utils/flattenChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

"use strict";

var ReactTextComponent = require('ReactTextComponent');

var traverseAllChildren = require('traverseAllChildren');
var warning = require('warning');

Expand All @@ -38,7 +40,18 @@ function flattenSingleChildIntoContext(traverseContext, child, name) {
name
);
if (keyUnique && child != null) {
result[name] = child;
var type = typeof child;
var normalizedValue;

if (type === 'string') {
normalizedValue = ReactTextComponent(child);
} else if (type === 'number') {
normalizedValue = ReactTextComponent('' + child);
} else {
normalizedValue = child;
}

result[name] = normalizedValue;
}
}

Expand Down
59 changes: 26 additions & 33 deletions src/utils/traverseAllChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

var ReactDescriptor = require('ReactDescriptor');
var ReactInstanceHandles = require('ReactInstanceHandles');
var ReactTextComponent = require('ReactTextComponent');

var invariant = require('invariant');

Expand Down Expand Up @@ -98,16 +97,17 @@ function wrapUserProvidedKey(key) {
*/
var traverseAllChildrenImpl =
function(children, nameSoFar, indexSoFar, callback, traverseContext) {
var nextName, nextIndex;
var subtreeCount = 0; // Count of children found in the current subtree.
if (Array.isArray(children)) {
for (var i = 0; i < children.length; i++) {
var child = children[i];
var nextName = (
nextName = (
nameSoFar +
(nameSoFar ? SUBSEPARATOR : SEPARATOR) +
getComponentKey(child, i)
);
var nextIndex = indexSoFar + subtreeCount;
nextIndex = indexSoFar + subtreeCount;
subtreeCount += traverseAllChildrenImpl(
child,
nextName,
Expand All @@ -127,39 +127,32 @@ var traverseAllChildrenImpl =
// All of the above are perceived as null.
callback(traverseContext, null, storageName, indexSoFar);
subtreeCount = 1;
} else if (ReactDescriptor.isValidDescriptor(children)) {
} else if (type === 'string' || type === 'number' ||
ReactDescriptor.isValidDescriptor(children)) {
callback(traverseContext, children, storageName, indexSoFar);
subtreeCount = 1;
} else {
if (type === 'object') {
invariant(
!children || children.nodeType !== 1,
'traverseAllChildren(...): Encountered an invalid child; DOM ' +
'elements are not valid children of React components.'
);
for (var key in children) {
if (children.hasOwnProperty(key)) {
subtreeCount += traverseAllChildrenImpl(
children[key],
(
nameSoFar + (nameSoFar ? SUBSEPARATOR : SEPARATOR) +
wrapUserProvidedKey(key) + SUBSEPARATOR +
getComponentKey(children[key], 0)
),
indexSoFar + subtreeCount,
callback,
traverseContext
);
}
} else if (type === 'object') {
invariant(
!children || children.nodeType !== 1,
'traverseAllChildren(...): Encountered an invalid child; DOM ' +
'elements are not valid children of React components.'
);
for (var key in children) {
if (children.hasOwnProperty(key)) {
nextName = (
nameSoFar + (nameSoFar ? SUBSEPARATOR : SEPARATOR) +
wrapUserProvidedKey(key) + SUBSEPARATOR +
getComponentKey(children[key], 0)
);
nextIndex = indexSoFar + subtreeCount;
subtreeCount += traverseAllChildrenImpl(
children[key],
nextName,
nextIndex,
callback,
traverseContext
);
}
} else if (type === 'string') {
var normalizedText = ReactTextComponent(children);
callback(traverseContext, normalizedText, storageName, indexSoFar);
subtreeCount += 1;
} else if (type === 'number') {
var normalizedNumber = ReactTextComponent('' + children);
callback(traverseContext, normalizedNumber, storageName, indexSoFar);
subtreeCount += 1;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the require of ReactTextComponent at the top? We aren't using it anymore.

}
}
Expand Down