UNPKG

aspen-tree-model

Version:
45 lines (44 loc) 1.72 kB
import { IBasicFileSystemHost, Root } from 'aspen-core'; import { IDisposable } from 'notificar'; import { ISerializableState, TreeStateManager, TreeStateWatcher } from './treeState'; export declare class TreeModel { readonly state: TreeStateManager; readonly root: Root; private events; constructor(host: IBasicFileSystemHost, rootPath: string); onChange(callback: () => void): IDisposable; /** * Restore tree state from given state. * * Included in TreeState: * - Directory expansion states * - Scroll offset * * Not included in TreeState: * - Decorations * - Prompts * * NOTE: ⚠ `loadTreeState` should be called and `await`ed **before** passing the `TreeModel` on to the `<FileTree />` component */ loadTreeState(state: string): any; loadTreeState(state: ISerializableState): any; /** * Returns a `TreeStateWatcher` that will stay in sync with actual tree state at all times * * Included in TreeState: * - Directory expansion states * - Scroll offset * * Not included in TreeState: * - Decorations * - Prompts * * Use `TreeStateWatcher#onChange` to attach a listener for when state is updated. * * Use `TreeStateWatcher#snapshot` to get snapshot of current tree state (not serialized, but serializable; use `JSON.stringify()`). You can make a time machine with this * * Use `TreeStateWatcher#toString` to convert the current state into a JSON string. Useful if you want save the current state to be able restore it later */ getTreeStateWatcher(atSurfaceExpandedDirsOnly?: boolean): TreeStateWatcher; private dispatchChange; }