@@ -43,11 +43,14 @@ export interface DirEntry extends Entry {
4343 priority ?: PriorityNumberType ,
4444 subdirs : Map < string , DirEntry > ,
4545 files : Map < string , FileEntry > ,
46- subrows : FileDirEntry [ ] ,
4746}
4847
4948export type FileDirEntry = FileEntry | DirEntry ;
5049
50+ export interface FileDirEntryView extends Omit < FileDirEntry , "subdirs" | "files" | "isSelected" | "parent" | "index" > {
51+ subrows : FileDirEntryView [ ] ,
52+ }
53+
5154export function isDirEntry ( entry : FileDirEntry ) : entry is DirEntry {
5255 return "files" in entry ;
5356}
@@ -78,7 +81,6 @@ export class CachedFileTree {
7881 percent : 0 ,
7982 subdirs : new Map ( ) ,
8083 files : new Map ( ) ,
81- subrows : [ ] ,
8284 isSelected : false ,
8385 wantedUpdating : false ,
8486 } ;
@@ -187,7 +189,6 @@ export class CachedFileTree {
187189 percent : 0 ,
188190 subdirs : new Map ( ) ,
189191 files : new Map ( ) ,
190- subrows : [ ] ,
191192 parent : node ,
192193 isSelected : false ,
193194 wantedUpdating : false ,
@@ -368,18 +369,30 @@ export class CachedFileTree {
368369 return result ;
369370 }
370371
371- getView ( ) : FileDirEntry [ ] {
372- const treeCopy = { ...this . tree } ;
373-
374- const recurse = ( dir : DirEntry ) => {
375- dir . subdirs . forEach ( recurse ) ;
376- dir . subrows = [
377- ...Array . from ( dir . subdirs . values ( ) ) . map ( ( d ) => ( { ...d , parent : undefined } ) ) ,
378- ...Array . from ( dir . files . values ( ) ) . map ( ( f ) => ( { ...f , parent : undefined } ) ) ] ;
372+ getView ( ) : FileDirEntryView [ ] {
373+ const toView : ( e : FileDirEntry ) => FileDirEntryView = ( e ) => {
374+ const subrows : FileDirEntryView [ ] = [ ] ;
375+ if ( isDirEntry ( e ) ) {
376+ subrows . push ( ...Array . from ( e . subdirs . values ( ) ) . map ( toView ) ) ;
377+ subrows . push ( ...Array . from ( e . files . values ( ) ) . map ( toView ) ) ;
378+ }
379+ return {
380+ name : e . name ,
381+ level : e . level ,
382+ fullpath : e . fullpath ,
383+ size : e . size ,
384+ done : e . done ,
385+ percent : e . percent ,
386+ wantedUpdating : e . wantedUpdating ,
387+ want : e . want ,
388+ priority : e . priority ,
389+ subrows,
390+ } ;
379391 } ;
380392
381- recurse ( treeCopy ) ;
393+ const result = Array . from ( this . tree . subdirs . values ( ) ) . map ( toView ) ;
394+ result . push ( ...Array . from ( this . tree . files . values ( ) ) . map ( toView ) ) ;
382395
383- return treeCopy . subrows ;
396+ return result ;
384397 }
385398}
0 commit comments