@web-atoms/core
Version:
83 lines • 2.78 kB
TypeScript
import { IDisposable, PathList } from "./types";
export declare class ObjectProperty {
target: object;
name: string;
watcher: IDisposable;
constructor(name: string);
toString(): string;
}
/**
*
*
* @export
* @class AtomWatcher
* @implements {IDisposable}
* @template T
*/
export declare class AtomWatcher<T> implements IDisposable {
private source?;
/**
* If path was given as an array of string property path, you can use this `func` that will be executed
* when any of property is updated.
*
* You must manually invoke evaluate after setting this property.
*
* @memberof AtomWatcher
*/
func: (...values: any[]) => any;
funcText: string;
path: ObjectProperty[][];
target: any;
private runEvaluate;
private forValidation;
private isExecuting;
/**
* Creates an instance of AtomWatcher.
*
* let w = new AtomWatcher(this, x => x.data.fullName = `${x.data.firstName} ${x.data.lastName}`);
*
* You must dispose `w` in order to avoid memory leaks.
* Above method will set fullName whenever, data or its firstName,lastName property is modified.
*
* AtomWatcher will assign null if any expression results in null in single property path.
*
* In order to avoid null, you can rewrite above expression as,
*
* let w = new AtomWatcher(this,
* x => {
* if(x.data.firstName && x.data.lastName){
* x.data.fullName = `${x.data.firstName} ${x.data.lastName}`
* }
* });
*
* @param {T} target - Target on which watch will be set to observe given set of properties
* @param {(PathList[] | ((x:T) => any))} path - Path is either lambda expression or array of
* property path to watch, if path was lambda, it will be executed when any of
* members will modify
* @param {Function} onChanged - This function will be executed when any member in path is updated
* @memberof AtomWatcher
*/
constructor(target: T, path: PathList[] | (() => any), onChanged: (...v: any[]) => any, source?: any);
toString(): string;
/**
* This will dispose and unregister all watchers
*
* @memberof AtomWatcher
*/
dispose(): void;
/**
* Initialize the path targets
* @param evaluate if true, evaluate entire watch expression and run onChange method
*/
init(evaluate?: boolean): void;
private evaluatePath;
/**
*
*
* @param {boolean} [force]
* @returns {*}
* @memberof AtomWatcher
*/
private evaluate;
}
//# sourceMappingURL=AtomWatcher.d.ts.map