Skip to content

Commit

Permalink
feat(components/tree): add concrete impl for filesystem nodes
Browse files Browse the repository at this point in the history
Signed-off-by: Braden Mars <[email protected]>
  • Loading branch information
BradenM committed Mar 5, 2024
1 parent d9bacec commit 9a3f43f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/components/tree/filesystem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Tree, type TreeVisitor, TreeNode } from './node';
import type { CCUFileItem } from '@/models/types';

abstract class FileSystemNode<T> extends TreeNode<T> {
constructor(
public value: T,
public parent?: FileSystemNode<T> | undefined,
) {
super(value, parent);
}

get path(): string {
return (this.parent ? [this.parent.name, this.name] : [this.name]).join(
'/',
);
}

abstract get name(): string;

traverse(visitor: TreeVisitor<T>) {
visitor(this);
for (const child of this.children) child.traverse(visitor);
}
}

export class FolderNode extends FileSystemNode<string> {
get name(): string {
return this.value;
}
}

export class FileNode<T extends CCUFileItem> extends FileSystemNode<T> {
get name(): string {
return this.value.filename_original;
}
}

0 comments on commit 9a3f43f

Please sign in to comment.