import type { PropertyPathItem, ViewModel } from './core'; import { VM_RAW } from './core'; export declare const VM_WATCHER_PATH: unique symbol; export declare const VM_WATCHER_VALUE: unique symbol; export declare const VM_WATCHER_IS_DEEP: unique symbol; export declare const VM_WATCHER_LISTENER: unique symbol; export declare const VM_WATCHER_IMM: unique symbol; export type WatchHandler = (newValue: T, oldValue: T | undefined, propertyPath?: PropertyPathItem[]) => void; export interface Watcher { [VM_RAW]?: ViewModel; [VM_WATCHER_PATH]?: PropertyPathItem[]; [VM_WATCHER_VALUE]?: T; [VM_WATCHER_LISTENER]?: WatchHandler; [VM_WATCHER_IS_DEEP]: boolean; [VM_WATCHER_IMM]: { i: number; /** * 发生变更的路径,undefined 代表初始无变更,null 代表直接深度 watch 对象无变更 path。 */ p?: PropertyPathItem[] | null; }; } export declare function destoryWatcher(watcher: Watcher): void; export declare function getValueByPath(target: unknown, path?: PropertyPathItem[]): any; /** * watch view-model by property path. * TODO: watchPath 能实现深度的基于 keyof 的类型严格的 Property Path 么? */ export declare function watchPath(vm: ViewModel, handler: WatchHandler, propertyPath?: PropertyPathItem[], deep?: boolean, immediate?: boolean): () => void; export declare function innerWatchPath(vm: ViewModel, val: unknown, handler: WatchHandler, path?: PropertyPathItem[], deep?: boolean): () => void; export type UnwatchFn = () => void; export interface WatchOptions { /** 是否立即执行监听回调函数,默认 false。 */ immediate?: boolean; /** 是否深度监听该值,默认 false。 */ deep?: boolean; } /** 监听 vm 对象的 property 属性的变更。 */ export declare function vmWatch(vm: T, property: P, handler: WatchHandler, options?: WatchOptions): UnwatchFn; /** 深度监听 vm 对象的任何变更 */ export declare function vmWatch(vm: T, handler: WatchHandler, options?: { immediate?: boolean; }): UnwatchFn; /** 监听 vm 对象上的 property path 属性,即多层的子对象的属性。 */ export declare function vmWatch(vm: T, propertyPath: PropertyPathItem[], handler: WatchHandler, options?: WatchOptions): UnwatchFn; export declare function notifyVmPropChange(vm: ViewModel, prop: PropertyPathItem): void; export declare function notifyVmArrayChange(vm: ViewModel): void;