Skip to content

Commit 72cfcb6

Browse files
rychkogGeorgii Rychko
authored andcommitted
fix(tree): add method for creating children asynchronously (closes #204)
1 parent 9aaa065 commit 72cfcb6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/tree-controller.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ export class TreeController {
6767
this.treeService.fireNodeCreated(newTree);
6868
}
6969

70+
public addChildAsync(newNode: TreeModel): Promise<Tree> {
71+
if (this.tree.hasDeferredChildren() && !this.tree.childrenWereLoaded()) {
72+
return Promise.reject(new Error('This node loads its children asynchronously, hence child cannot be added this way'));
73+
}
74+
75+
const newTree = this.tree.createNode(Array.isArray(newNode.children), newNode);
76+
this.treeService.fireNodeCreated(newTree);
77+
78+
// This will give TreeInternalComponent to set up a controller for the node
79+
return new Promise(resolve => {
80+
setTimeout(() => {
81+
resolve(newTree);
82+
})
83+
})
84+
}
85+
7086
public changeNodeId(id: string | number) {
7187
if (!id) {
7288
throw Error('You should supply an id!');

0 commit comments

Comments
 (0)