Skip to content

Commit

Permalink
fix(nodes): added id getter and fixed children remove method
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinEspinas committed Oct 2, 2022
1 parent 04c0b94 commit c5076ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/InnerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class InnerNode extends TreeNode {
let removedNode;
this.children = this.children.filter((n: TreeNode) => {
// Unloads and filters the given node out.
if (n === node) {
if (n.id === node.id) {
removedNode = n;
n.unload();
return false;
Expand Down
9 changes: 7 additions & 2 deletions src/core/TreeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export abstract class TreeNode {
/**
* Node's ID, generate it with [nanoid](https://github.com/ai/nanoid) if applicable.
*/
protected id: string;
protected _id: string;

/**
* Node's parent node, if root node, the parent node is replaced by the engine instance.
Expand All @@ -25,6 +25,11 @@ export abstract class TreeNode {
*/
protected isLoaded: boolean;

/**
* Get the node's ID.
*/
public get id(): string { return this._id; }

/**
* Get parent node.
*/
Expand All @@ -40,7 +45,7 @@ export abstract class TreeNode {
} else {
this.engine = parent;
}
this.id = nanoid(16);
this._id = nanoid(16);
this.isLoaded = false;
}

Expand Down

0 comments on commit c5076ba

Please sign in to comment.