import { ObjectBase } from './object.base'; export abstract class TreeNodeBase< T extends TreeNodeBase, > extends ObjectBase { protected _Path: string | undefined; protected children: T[] = []; protected parent: T | undefined; abstract isChildrenLoaded: boolean; abstract isParentLoaded: boolean; abstract Name: string; public get Path(): string | undefined { return this._Path; } async getChildren(): Promise { if (!this.isChildrenLoaded) { this.loadChildren(); this.isChildrenLoaded = true; } return this.children; } async getParent(): Promise { if (!this.isParentLoaded) { this.loadParent(); this.isParentLoaded = true; } return this.parent; } async isLeaf(): Promise { if (!this.isChildrenLoaded) { await this.loadChildren(); } return this.children.length === 0; } async getPath(): Promise { if (!this.isParentLoaded) { await this.loadParent(); } if (this.parent) { return (await this.parent.getPath()) + ' > ' + this.Name; } return this.Name; } protected async updatePath(): Promise { const path = await this.getPath(); this._Path = path; } async setParent(parent: T): Promise { this.parent = parent; await this.updatePath(); } abstract loadChildren(): Promise; abstract loadParent(): Promise; }