-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components/tree): add concrete impl for filesystem nodes
Signed-off-by: Braden Mars <[email protected]>
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |