diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-04-26 15:11:27 +1000 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-04-26 15:11:27 +1000 |
| commit | de55b59141a82c68b6a5b360d6f57a7e760e2fd6 (patch) | |
| tree | 8be1a1bdbb91b8ef7b71e5553f62fff176e8d6af /src/layout.ts | |
| parent | 04e9444746d3ba8ddcc96d0fd16f1c02adce1389 (diff) | |
Make TolMap have Map type
Diffstat (limited to 'src/layout.ts')
| -rw-r--r-- | src/layout.ts | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/layout.ts b/src/layout.ts index 69e84db..6f1fd77 100644 --- a/src/layout.ts +++ b/src/layout.ts @@ -54,7 +54,7 @@ export class LayoutNode { if (chg != null && this == chg.node){ switch (chg.type){ case 'expand': - let children = chg.tolMap[this.name].children.map((name: string) => new LayoutNode(name, [])); + let children = chg.tolMap.get(this.name)!.children.map((name: string) => new LayoutNode(name, [])); newNode = new LayoutNode(this.name, children); newNode.children.forEach(n => { n.parent = newNode; @@ -200,11 +200,15 @@ export function initLayoutTree(tolMap: TolMap, rootName: string, depth: number): node.depth = atDepth; return node; } else { - let children = tolMap[nodeName].children.map( - (name: string) => initHelper(tolMap, name, depthLeft-1, atDepth+1)); - let node = new LayoutNode(nodeName, children); - children.forEach(n => n.parent = node); - return node; + let childNames = tolMap.get(nodeName)!.children; + if (childNames.length == 0 || !tolMap.has(childNames[0])){ + return new LayoutNode(nodeName, []); + } else { + let children = childNames.map((name: string) => initHelper(tolMap, name, depthLeft-1, atDepth+1)); + let node = new LayoutNode(nodeName, children); + children.forEach(n => n.parent = node); + return node; + } } } return initHelper(tolMap, rootName, depth); |
