25 lines
342 B
JavaScript
25 lines
342 B
JavaScript
export default class Node {
|
|
|
|
constructor(name, parent) {
|
|
this.name = name;
|
|
this.parent = parent;
|
|
}
|
|
|
|
get path() {
|
|
const path = [];
|
|
let node = this;
|
|
|
|
while (node) {
|
|
path.push(node.name);
|
|
node = node.parent;
|
|
}
|
|
|
|
return path.reverse().join('/');
|
|
}
|
|
|
|
get isRoot() {
|
|
return !this.parent;
|
|
}
|
|
|
|
};
|