Bug 1653779 - Lazily create parent map r=nchevobbe,bomsy

parentMap appears to only be used when pressing the left arrow key to navigate
to the parent folder in the source tree.  If this is too slow it could be
replaced with a traverseTree search.

Differential Revision: https://phabricator.services.mozilla.com/D115318
This commit is contained in:
wartmanm 2022-01-07 09:54:21 +00:00
Родитель cf732621d4
Коммит 93d857cb3c
2 изменённых файлов: 11 добавлений и 3 удалений

Просмотреть файл

@ -220,7 +220,7 @@ class SourcesTree extends Component {
renderTree() {
const { expanded, focused, projectRoot } = this.props;
const { highlightItems, listItems, parentMap, sourceTree } = this.state;
const { highlightItems, listItems, getParent, sourceTree } = this.state;
const treeProps = {
autoExpandAll: false,
@ -228,7 +228,7 @@ class SourcesTree extends Component {
expanded,
focused,
getChildren: getChildren,
getParent: item => parentMap.get(item),
getParent,
getPath: this.getPath,
getRoots: () => this.getRoots(sourceTree, projectRoot),
highlightItems,

Просмотреть файл

@ -99,10 +99,18 @@ export function updateTree({
const newSourceTree = collapseTree(uncollapsedTree);
let lazyParentMap;
const getParent = function(key) {
if (!lazyParentMap) {
lazyParentMap = createParentMap(newSourceTree);
}
return lazyParentMap.get(key);
};
return {
uncollapsedTree,
sourceTree: newSourceTree,
parentMap: createParentMap(newSourceTree),
getParent,
};
}