import { Disposable , ExplicitDataSource , TreeDataProvider , TreeItem , TreeItemIndex } from '../types' ; import { EventEmitter } from '../EventEmitter' ; export class StaticTreeDataProvider < T = any > implements TreeDataProvider { private data : ExplicitDataSource ; private onDidChangeTreeDataEmitter = new EventEmitter < TreeItemIndex [ ] > ( ) ; private setItemName ? : ( item : TreeItem < T > , newName : string ) => TreeItem < T > ; constructor ( items , setItemName ? ) { this . data = { items } ; this . setItemName = setItemName ; } public async getTreeItem ( itemId ) { return this . data . items [ itemId ] ; } public async onChangeItemChildren ( itemId , newChildren ) { this . data . items [ itemId ] . children = newChildren ; this . onDidChangeTreeDataEmitter . emit ( [ itemId ] ) ; } public onDidChangeTreeData ( listener ) { const handlerId = this . onDidChangeTreeDataEmitter . on ( payload => listener ( payload ) ) ; return { dispose : ( ) => this . onDidChangeTreeDataEmitter . off ( handlerId ) } ; } public async onRenameItem ( item , name ) { if ( this . setItemName ) { this . data . items [ item . index ] = this . setItemName ( item , name ) ; } } }