import { ModelBase, Misc, Model, ITaskRunner } from '@singularsystems/neo-core'; import { IViewModel } from './IViewModel'; import { IReactionDisposer } from 'mobx'; import { AxiosPromise } from 'axios'; import { WaitForTaskRunnerOptions } from '@singularsystems/neo-core/dist/Components/TaskRunner/TaskRunner'; import { BindableBase } from '@singularsystems/neo-core/dist/Model/BindableBase'; type VMConstructor = (new (taskRunner?: ITaskRunner) => T); export type valueOrLazy = T | (() => T) | VMConstructor; export default abstract class ViewModelBase extends ModelBase implements IViewModel { taskRunner: ITaskRunner; private disposeHelper; private trackedViewModels; constructor(taskRunner?: ITaskRunner, disposeHelper?: import("../Services/IDisposeHelper").IDisposeHelper); initialise(): void; /** * Registers a mobx reaction, which will be disposed in the dispose() method when the view is unmounted. * @param expression Expression to react to. * @param effect Callback to run when the result of the expression changes. */ registerReaction(expression: () => T, effect: (value: T) => void): IReactionDisposer; /** * Instantiates, and registers a child view model that will be disposed when this view model is disposed. * Does not initialise the view model unless specified in options. * The task runner will be passed to the new vm from this one. * @param viewModel View model type. */ registerViewModel(viewModel: VMConstructor, options?: { initialise: boolean; }): TViewModel; /** * Registers a child view model that will be disposed when this view model is disposed. * You must manually pass the current VMs task runner to the new viewmodel instance. */ registerViewModel(viewModel: TViewModel): TViewModel; /** * Disposes a child view model and sets the property value to null. * Note: you will need to pass in the VM property like this: (this as MyVM).meta.vmProperty */ protected disposeViewModel(vmProperty: Model.IPropertyInstance): void; /** * Uses the task runner to call an api endpoint. The returned data is deserialised into an instance of the provided model type. */ waitForModel(modelType: typeof BindableBase, task: AxiosPromise>, options?: Partial>>): Promise; /** * Registers the object for disposal when this viewmodel is disposed. */ autoDispose(disposable: T): T; /** * Binds a list of functions to the viewmodel instance. */ protected bindMethods(...fns: Function[]): void; dispose(): void; /** * Creates a view model instance. * @param viewModel ViewModel instance, callback which returns a ViewModel or ViewModel constructor. * @param taskRunner TaskRunner to set if a constructor is passed in. */ static create(viewModel: valueOrLazy, taskRunner?: ITaskRunner): TViewModel; } export {};