import { ConvertFunction } from './Binding.js'; /** * Transforms a value into another value. */ type Transformer = ConvertFunction; /** * A transformer that also supports an `else` function that can be used * when the transformer would otherwise skip a value (e.g. if `isDefined` is being used). */ interface TransformerWithElse extends Transformer { /** * Transformer that either invokes the given value (if its a function) * or simply returns it. * * @param value function or plain value in the */ else(value: any): Transformer; } /** * Builds function which executes a given callback only if value is not undefined or null. * The created function will have a "else" method, which can be used to bind default values. * @param callback to execute if value is defined. * @returns transformer function. * @example * ``` * let a = new Clazz(); * let b = new Clazz(); * Binding.for(a, b) * .syncToRight("prop", * ifDefined((v) => v.toUpperCase()).else("missing value") * ).enable().syncToRightNow(); * //-> b.prop === "missing value"; * a.prop = "test"; // -> b.prop === "TEST" * ``` */ declare function ifDefined(callback?: Transformer): TransformerWithElse; /** * Builds function which executes a given callback only if value is not 'almost' equal to the target value. * The created function will have a "else" method, which can be used to bind default values. * @param eps epsilon number which defines the allowed difference to the target value. * @param callback to execute if value is not almost equal. * @returns transformer function. * @example * ``` * let a = new Clazz({prop: 2}); * let b = new Clazz(); * Binding.for(a, b) * .syncToRight("prop", * ifTargetNotEqualsAlmost(0.001) * ).enable().syncToRightNow(); * a.prop = 2.0002; // -> b.prop === 2, detects no change * ``` */ declare function ifTargetNotEqualsAlmost(eps: number, callback?: Transformer): TransformerWithElse; /** * Builds function which delays the synchronization for given msec. * @param delay time in msec to wait before synchronizing. * @param callback callback which transforms the value. * @returns transformer function. * @example * ``` * let a = new Clazz({prop: 2}); * let b = new Clazz(); * Binding.for(a, b) * .syncToRight("prop", * debounce(100) * ).enable().syncToRightNow(); * b.prop // is undefined but will be set after 100msec to 2 * ``` */ declare function debounce(delay: number, callback?: Transformer): Transformer; /** * Builds function which delays the synchronization for given msec and cancels the execution if transformer is triggered * again. * @param delay time in msec to wait before synchronizing. * @param callback callback which transforms the value. * @returns transformer function. * @example * ``` * let a = new Clazz({prop: 2}); * let b = new Clazz(); * Binding.for(a, b) * .syncToRight("prop", * debounceOrCancel(100) * ).enable().syncToRightNow(); * b.prop // is undefined but will be set after 100msec to 2 * ``` */ declare function debounceOrCancel(delay: number, callback?: Transformer): Transformer; /** * Builds function which delays the synchronization for given msec and cancels the execution if transformer is triggered * again. * In contrast to debounceOrCancel this method ensures that after the given delay at least one update is performed. * * @param delay time in msec to wait before synchronizing. * @param callback callback which transforms the value. * @returns transformer function. * @example * ``` * let a = new Clazz({prop: 2}); * let b = new Clazz(); * Binding.for(a, b) * .syncToRight("prop", * deferOrCancel(100) * ).enable().syncToRightNow(); * b.prop // is undefined but will be set after 100msec to 2 * ``` */ declare function deferOrCancel(delay: number, callback?: Transformer): Transformer; /** * Builds a function which returns the sub property "instance" of an object. * @param callback delegation function to which the value is passed to. * @returns property accessor function. */ declare function instance(callback?: Transformer): Transformer; /** * Builds a function which accesses a sub property of an object. * @param name property name * @param callback delegation function to which the value is passed to. * @returns property accessor function. */ declare function prop(name: string, callback?: Transformer): Transformer; export { debounce, debounceOrCancel, deferOrCancel, ifDefined, ifTargetNotEqualsAlmost, instance, prop }; export type { Transformer, TransformerWithElse };