Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove React.Children.mapIntoWithKeyPrefixInternal
  • Loading branch information
koba04 committed Jun 29, 2017
commit 437120d40d075d70f3fdf3254079c626cacce0e2
40 changes: 13 additions & 27 deletions src/isomorphic/children/ReactChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,20 @@ function mapSingleChildIntoContext(bookKeeping, child, childKey) {
var {result, keyPrefix, func, context} = bookKeeping;

var mappedChild = func.call(context, child, bookKeeping.count++);
if (mappedChild == null) {
return;
}

if (Array.isArray(mappedChild)) {
mapIntoWithKeyPrefixInternal(
mappedChild,
result,
childKey,
emptyFunction.thatReturnsArgument,
);
} else if (mappedChild != null) {
var traverseContext = {
result: result,
keyPrefix: childKey != null ? escapeUserProvidedKey(childKey) + '/' : '',
func: emptyFunction.thatReturnsArgument,
context: null,
count: 0,
};
traverseAllChildren(mappedChild, '', mapSingleChildIntoContext, traverseContext);
} else {
if (ReactElement.isValidElement(mappedChild)) {
mappedChild = ReactElement.cloneAndReplaceKey(
mappedChild,
Expand All @@ -203,25 +209,6 @@ function mapSingleChildIntoContext(bookKeeping, child, childKey) {
}
}

function mapIntoWithKeyPrefixInternal(children, array, prefix, func, context) {
if (children == null) {
return;
}
var escapedPrefix = '';
if (prefix != null) {
escapedPrefix = escapeUserProvidedKey(prefix) + '/';
}
var traverseContext = {
result: array,
keyPrefix: escapedPrefix,
func: func,
context: context,
count: 0,
};

traverseAllChildren(children, '', mapSingleChildIntoContext, traverseContext);
}

/**
* Maps children that are typically specified as `props.children`.
*
Expand Down Expand Up @@ -299,7 +286,6 @@ function countChildren(children, context) {
var ReactChildren = {
forEach: forEachChildren,
map: mapChildren,
mapIntoWithKeyPrefixInternal: mapIntoWithKeyPrefixInternal,
count: countChildren,
toArray: toArray,
};
Expand Down