Skip to content

Commit

Permalink
fix(devtools): make sure we dont access position of an undefined parent
Browse files Browse the repository at this point in the history
  • Loading branch information
mgechev authored and sumitarora committed Mar 18, 2020
1 parent 56fbbd5 commit e74dc9e
Showing 1 changed file with 11 additions and 4 deletions.
Expand Up @@ -119,12 +119,19 @@ export class DirectiveForestComponent {

populateParents(position: ElementPosition): void {
this.parents = position.reduce((nodes: FlatNode[], index: number) => {
let nodeId = [index];
let nodePosition = [index];
if (nodes.length > 0) {
nodeId = nodes[nodes.length - 1].position.concat(index);
nodePosition = nodes[nodes.length - 1].position.concat(index);
}
// It's possible selectedNode to be undefined
// In this case, we don't want to push it to the list
// of parent nodes. Instead, we want to report a warning.
const selectedNode = this.dataSource.data.find(item => item.position.toString() === nodePosition.toString());
if (selectedNode) {
nodes.push(selectedNode);
} else {
console.warn('Cant find node for position', nodePosition);
}
const selectedNode = this.dataSource.data.find(item => item.position.toString() === nodeId.toString());
nodes.push(selectedNode);
return nodes;
}, []);
}
Expand Down

0 comments on commit e74dc9e

Please sign in to comment.