Skip to content

Commit

Permalink
fix(tree): add method for creating children asynchronously (closes #204)
Browse files Browse the repository at this point in the history
  • Loading branch information
rychkog authored and Georgii Rychko committed Feb 11, 2018
1 parent 9aaa065 commit 72cfcb6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/tree-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ export class TreeController {
this.treeService.fireNodeCreated(newTree);
}

public addChildAsync(newNode: TreeModel): Promise<Tree> {
if (this.tree.hasDeferredChildren() && !this.tree.childrenWereLoaded()) {
return Promise.reject(new Error('This node loads its children asynchronously, hence child cannot be added this way'));
}

const newTree = this.tree.createNode(Array.isArray(newNode.children), newNode);
this.treeService.fireNodeCreated(newTree);

// This will give TreeInternalComponent to set up a controller for the node
return new Promise(resolve => {
setTimeout(() => {
resolve(newTree);
})
})
}

public changeNodeId(id: string | number) {
if (!id) {
throw Error('You should supply an id!');
Expand Down

0 comments on commit 72cfcb6

Please sign in to comment.