@samitouri / QOS-React / commits / 9cf888f661

Delete flattenChildren (#10224)

* Delete flattenChildren * Stop exporting mapIntoWithKeyPrefixInternal * Remove unescapeInDev() flattenChildren() was the only traverseAllChildren() caller that relied on it.

Dan Abramov committed Jul 20, 2017 at 01:25 UTC 9cf888f661f95bec72243a62b5ba6028812a7758
3 files changed -119
src/isomorphic/children/ReactChildren.js
-1
@@ -201,7 +201,6 @@ function toArray(children) {
201 var ReactChildren = {
202 forEach: forEachChildren,
203 map: mapChildren,
204 - mapIntoWithKeyPrefixInternal: mapIntoWithKeyPrefixInternal,
204 count: countChildren,
205 toArray: toArray,
206 };
src/isomorphic/children/flattenChildren.js deleted
-92
@@ -1,92 +0,0 @@
1 -/**
2 - * Copyright 2013-present, 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 flattenChildren
10 - * @flow
11 - */
12 -
13 -'use strict';
14 -
15 -var traverseAllChildren = require('traverseAllChildren');
16 -var ReactComponentTreeHook = require('ReactComponentTreeHook');
17 -
18 -if (__DEV__) {
19 - var warning = require('fbjs/lib/warning');
20 -}
21 -
22 -/**
23 - * @param {function} traverseContext Context passed through traversal.
24 - * @param {?ReactComponent} child React child component.
25 - * @param {!string} name String name of key path to child.
26 - * @param {number=} selfDebugID Optional debugID of the current internal instance.
27 - */
28 -function flattenSingleChildIntoContext(
29 - traverseContext: mixed,
30 - child: ReactElement<any>,
31 - name: string,
32 - selfDebugID?: number,
33 - unescapeInDev: (name: string) => string,
34 -): void {
35 - // We found a component instance.
36 - if (traverseContext && typeof traverseContext === 'object') {
37 - const result = traverseContext;
38 - const keyUnique = result[name] === undefined;
39 - if (__DEV__) {
40 - if (!keyUnique) {
41 - warning(
42 - false,
43 - 'flattenChildren(...): Encountered two children with the same key, ' +
44 - '`%s`. Keys should be unique so that components maintain their ' +
45 - 'identity across updates. Non-unique keys may cause children to ' +
46 - 'be duplicated and/or omitted — the behavior is ' +
47 - 'unsupported and could change in a future version.%s',
48 - unescapeInDev(name),
49 - ReactComponentTreeHook.getStackAddendumByID(selfDebugID),
50 - );
51 - }
52 - }
53 - if (keyUnique && child != null) {
54 - result[name] = child;
55 - }
56 - }
57 -}
58 -
59 -/**
60 - * Flattens children that are typically specified as `props.children`. Any null
61 - * children will not be included in the resulting object.
62 - * @return {!object} flattened children keyed by name.
63 - */
64 -function flattenChildren(
65 - children: ReactElement<any>,
66 - selfDebugID?: number,
67 -): ?{[name: string]: ReactElement<any>} {
68 - if (children == null) {
69 - return children;
70 - }
71 - var result = {};
72 -
73 - if (__DEV__) {
74 - traverseAllChildren(
75 - children,
76 - (traverseContext, child, name, unescapeInDev) =>
77 - flattenSingleChildIntoContext(
78 - traverseContext,
79 - child,
80 - name,
81 - selfDebugID,
82 - unescapeInDev,
83 - ),
84 - result,
85 - );
86 - } else {
87 - traverseAllChildren(children, flattenSingleChildIntoContext, result);
88 - }
89 - return result;
90 -}
91 -
92 -module.exports = flattenChildren;
src/isomorphic/children/traverseAllChildren.js
-26
@@ -11,7 +11,6 @@
11
12 'use strict';
13
14 -var emptyFunction = require('fbjs/lib/emptyFunction');
14 var invariant = require('fbjs/lib/invariant');
15
16 var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
@@ -49,30 +48,6 @@ function escape(key: string): string {
48 return '$' + escapedString;
49 }
50
52 -var unescapeInDev = emptyFunction;
53 -if (__DEV__) {
54 - /**
55 - * Unescape and unwrap key for human-readable display
56 - *
57 - * @param {string} key to unescape.
58 - * @return {string} the unescaped key.
59 - */
60 - unescapeInDev = function(key: string): string {
61 - var unescapeRegex = /(=0|=2)/g;
62 - var unescaperLookup = {
63 - '=0': '=',
64 - '=2': ':',
65 - };
66 - var keySubstring = key[0] === '.' && key[1] === '$'
67 - ? key.substring(2)
68 - : key.substring(1);
69 -
70 - return ('' + keySubstring).replace(unescapeRegex, function(match) {
71 - return unescaperLookup[match];
72 - });
73 - };
74 -}
75 -
51 /**
52 * TODO: Test that a single child and an array with one item have the same key
53 * pattern.
@@ -137,7 +112,6 @@ function traverseAllChildrenImpl(
112 // If it's the only child, treat the name as if it was wrapped in an array
113 // so that it's consistent if the number of children grows.
114 nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar,
140 - unescapeInDev,
115 );
116 return 1;
117 }