mirror of
				https://github.com/ZetaKebab/quartz.git
				synced 2025-11-04 06:49:49 +00:00 
			
		
		
		
	feat(explorer): implement map fn argument
				
					
				
			Add a function for mapping over all FileNodes as an option for `Explorer`
This commit is contained in:
		@@ -40,6 +40,11 @@ export default ((userOpts?: Partial<Options>) => {
 | 
			
		||||
      fileTree.filter(opts.filterFn)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // If provided, apply map function to fileTree
 | 
			
		||||
    if (opts.mapFn) {
 | 
			
		||||
      fileTree.map(opts.mapFn)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Get all folders of tree. Initialize with collapsed state
 | 
			
		||||
    const folders = fileTree.getFolderPaths(opts.folderDefaultState === "collapsed")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ export interface Options {
 | 
			
		||||
  useSavedState: boolean
 | 
			
		||||
  sortFn: (a: FileNode, b: FileNode) => number
 | 
			
		||||
  filterFn?: (node: FileNode) => boolean
 | 
			
		||||
  mapFn?: (node: FileNode) => void
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type DataWrapper = {
 | 
			
		||||
@@ -86,6 +87,16 @@ export class FileNode {
 | 
			
		||||
    this.children = filteredNodes
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Filter FileNode tree. Behaves similar to `Array.prototype.map()`, but modifies tree in place
 | 
			
		||||
   * @param mapFn function to filter tree with
 | 
			
		||||
   */
 | 
			
		||||
  map(mapFn: (node: FileNode) => void) {
 | 
			
		||||
    mapFn(this)
 | 
			
		||||
 | 
			
		||||
    this.children.forEach((child) => child.map(mapFn))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Get folder representation with state of tree.
 | 
			
		||||
   * Intended to only be called on root node before changes to the tree are made
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user