mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
Delete flattenChildren (#10224)
* Delete flattenChildren * Stop exporting mapIntoWithKeyPrefixInternal * Remove unescapeInDev() flattenChildren() was the only traverseAllChildren() caller that relied on it.
This commit is contained in:
@@ -201,7 +201,6 @@ function toArray(children) {
|
||||
var ReactChildren = {
|
||||
forEach: forEachChildren,
|
||||
map: mapChildren,
|
||||
mapIntoWithKeyPrefixInternal: mapIntoWithKeyPrefixInternal,
|
||||
count: countChildren,
|
||||
toArray: toArray,
|
||||
};
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
/**
|
||||
* Copyright 2013-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule flattenChildren
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var traverseAllChildren = require('traverseAllChildren');
|
||||
var ReactComponentTreeHook = require('ReactComponentTreeHook');
|
||||
|
||||
if (__DEV__) {
|
||||
var warning = require('fbjs/lib/warning');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {function} traverseContext Context passed through traversal.
|
||||
* @param {?ReactComponent} child React child component.
|
||||
* @param {!string} name String name of key path to child.
|
||||
* @param {number=} selfDebugID Optional debugID of the current internal instance.
|
||||
*/
|
||||
function flattenSingleChildIntoContext(
|
||||
traverseContext: mixed,
|
||||
child: ReactElement<any>,
|
||||
name: string,
|
||||
selfDebugID?: number,
|
||||
unescapeInDev: (name: string) => string,
|
||||
): void {
|
||||
// We found a component instance.
|
||||
if (traverseContext && typeof traverseContext === 'object') {
|
||||
const result = traverseContext;
|
||||
const keyUnique = result[name] === undefined;
|
||||
if (__DEV__) {
|
||||
if (!keyUnique) {
|
||||
warning(
|
||||
false,
|
||||
'flattenChildren(...): Encountered two children with the same key, ' +
|
||||
'`%s`. Keys should be unique so that components maintain their ' +
|
||||
'identity across updates. Non-unique keys may cause children to ' +
|
||||
'be duplicated and/or omitted — the behavior is ' +
|
||||
'unsupported and could change in a future version.%s',
|
||||
unescapeInDev(name),
|
||||
ReactComponentTreeHook.getStackAddendumByID(selfDebugID),
|
||||
);
|
||||
}
|
||||
}
|
||||
if (keyUnique && child != null) {
|
||||
result[name] = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens children that are typically specified as `props.children`. Any null
|
||||
* children will not be included in the resulting object.
|
||||
* @return {!object} flattened children keyed by name.
|
||||
*/
|
||||
function flattenChildren(
|
||||
children: ReactElement<any>,
|
||||
selfDebugID?: number,
|
||||
): ?{[name: string]: ReactElement<any>} {
|
||||
if (children == null) {
|
||||
return children;
|
||||
}
|
||||
var result = {};
|
||||
|
||||
if (__DEV__) {
|
||||
traverseAllChildren(
|
||||
children,
|
||||
(traverseContext, child, name, unescapeInDev) =>
|
||||
flattenSingleChildIntoContext(
|
||||
traverseContext,
|
||||
child,
|
||||
name,
|
||||
selfDebugID,
|
||||
unescapeInDev,
|
||||
),
|
||||
result,
|
||||
);
|
||||
} else {
|
||||
traverseAllChildren(children, flattenSingleChildIntoContext, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = flattenChildren;
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var emptyFunction = require('fbjs/lib/emptyFunction');
|
||||
var invariant = require('fbjs/lib/invariant');
|
||||
|
||||
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
||||
@@ -49,30 +48,6 @@ function escape(key: string): string {
|
||||
return '$' + escapedString;
|
||||
}
|
||||
|
||||
var unescapeInDev = emptyFunction;
|
||||
if (__DEV__) {
|
||||
/**
|
||||
* Unescape and unwrap key for human-readable display
|
||||
*
|
||||
* @param {string} key to unescape.
|
||||
* @return {string} the unescaped key.
|
||||
*/
|
||||
unescapeInDev = function(key: string): string {
|
||||
var unescapeRegex = /(=0|=2)/g;
|
||||
var unescaperLookup = {
|
||||
'=0': '=',
|
||||
'=2': ':',
|
||||
};
|
||||
var keySubstring = key[0] === '.' && key[1] === '$'
|
||||
? key.substring(2)
|
||||
: key.substring(1);
|
||||
|
||||
return ('' + keySubstring).replace(unescapeRegex, function(match) {
|
||||
return unescaperLookup[match];
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Test that a single child and an array with one item have the same key
|
||||
* pattern.
|
||||
@@ -137,7 +112,6 @@ function traverseAllChildrenImpl(
|
||||
// If it's the only child, treat the name as if it was wrapped in an array
|
||||
// so that it's consistent if the number of children grows.
|
||||
nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar,
|
||||
unescapeInDev,
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user