import { EventEmitter } from "../events/event-emitter.js"; import { Event, type IEvent } from "../events/shared.js"; import { BinaryExpression } from "../parser/expressions/binary-expression.js"; import { CallExpression } from "../parser/expressions/call-expression.js"; import { ConstantExpression } from "../parser/expressions/constant-expression.js"; import { ExpressionVisitor } from "../parser/expressions/visitors/expression-visitor.js"; import type { Expressions, StrictExpressions } from "../parser/expressions/expression.js"; import { MemberExpression } from "../parser/expressions/member-expression.js"; import { NewExpression } from "../parser/expressions/new-expression.js"; import { ParameterExpression } from "../parser/expressions/parameter-expression.js"; import { TernaryExpression } from "../parser/expressions/ternary-expression.js"; import { type Subscription } from "../teardown-manager.js"; import { watcher, type Watcher, WatcherFormatter } from './shared.js'; import { AssignmentExpression } from "../parser/expressions/assignment-expression.js"; import { ObservableArray } from "./array.js"; import { FormatExpression } from "../parser/parser.js"; import { AllEventKeys } from "../events/index.js"; export interface ObjectEvent { readonly property: TKey; readonly value: T[TKey]; readonly oldValue: T[TKey]; } export declare class AsyncFormatter extends WatcherFormatter { private promise; private value; /** * Formats the value. * @param {unknown} value - The value to format. * @returns {unknown} The formatted value. */ format(value: unknown): unknown; /** * Creates an instance of AsyncFormatter. * @param {Watcher} [watcher] - The watcher instance. */ constructor(watcher?: Watcher); } export declare class EventFormatter extends WatcherFormatter { private event; private value; private sub?; /** * Formats the value. * @param {unknown} value - The value to format. * @returns {T} The formatted value. */ format(value: unknown): T; /** * Creates an instance of EventFormatter. * @param {Watcher} watcher - The watcher instance. */ constructor(watcher: Watcher); } export default class Watch extends WatcherFormatter { private value; /** * Formats the value. * @param {T} value - The value to format. * @returns {T} The formatted value. */ format(value: T): T; } export declare class BindingFormatter extends WatcherFormatter { private binding; private sub; private value; /** * Formats the value. * @param {unknown} value - The value to format. * @returns {unknown} The formatted value. */ format(value: unknown): unknown; /** * Creates an instance of BindingFormatter. * @param {Watcher} watcher - The watcher instance. */ constructor(watcher: Watcher); } export type IWatched = T & { [watcher]: ObservableObject | ObservableArray; }; export type Getter = (target: TSource) => TResult; export type WatchGetter = (target: TSource, watcher: Watcher) => TResult; export type Setter = (target: TSource, value: TValue) => void; export type IWatchable = { [watcher]?: ObservableObject; }; export declare class BuildWatcherAndSetter extends ExpressionVisitor { target: ParameterExpression; value: ParameterExpression; private static memberWatcher; private static formatWatcher; /** * Evaluates the expression. * @param {Expressions} expression - The expression to evaluate. * @returns {{ watcher: WatchGetter, setter?: Setter }} The watcher and setter. */ eval(expression: Expressions): { watcher: WatchGetter; setter?: Setter; }; private boundObservables; private getter; /** * Visits a constant expression. * @param {ConstantExpression} arg0 - The constant expression. * @returns {StrictExpressions} The visited expression. */ visitConstant(arg0: ConstantExpression): StrictExpressions; /** * Visits a format expression. * @param {FormatExpression} expression - The format expression. * @returns {FormatExpression} The visited expression. */ visitFormat(expression: FormatExpression): FormatExpression; /** * Visits a member expression. * @param {MemberExpression} arg0 - The member expression. * @returns {StrictExpressions} The visited expression. */ visitMember(arg0: MemberExpression): StrictExpressions; /** * Visits a ternary expression. * @param {TernaryExpression} expression - The ternary expression. * @returns {TernaryExpression} The visited expression. */ visitTernary(expression: TernaryExpression): TernaryExpression; /** * Visits a call expression. * @param {CallExpression} arg0 - The call expression. * @returns {StrictExpressions} The visited expression. */ visitCall(arg0: CallExpression): StrictExpressions; /** * Visits a new expression. * @param {NewExpression} expression - The new expression. * @returns {StrictExpressions} The visited expression. */ visitNew(expression: NewExpression): StrictExpressions; /** * Visits a binary expression. * @param {BinaryExpression} expression - The binary expression. * @returns {BinaryExpression} The visited expression. */ visitAssign(expression: AssignmentExpression): AssignmentExpression; /** * Visits a binary expression. * @param {BinaryExpression} expression - The binary expression. * @returns {BinaryExpression} The visited expression. */ visitBinary(expression: BinaryExpression): BinaryExpression; } type ObservableType = { [key in Exclude]: IEvent<[ObjectEvent], void>; } & { [allProperties]: IEvent<[ObjectEvent], void>; }; export type BindingChangedEvent = { value: T; oldValue: T; }; export declare const BindingsProperty: unique symbol; type Unbound = T extends Binding ? X : T; type UnboundObject = { [K in keyof T]?: Unbound; }; export declare class Binding extends EventEmitter<{ change: Event<[BindingChangedEvent]>; }> { target: unknown; readonly expression: Expressions; /** * Combines named bindings. * @param {T} obj - The object with named bindings. * @returns {Binding>} The combined binding. */ static combineNamed; }>(obj: T): Binding>; /** * Combines multiple bindings. * @param {...(T[K] | Binding)[]} bindings - The bindings to combine. * @returns {Binding} The combined binding. */ static combine(...bindings: { [K in keyof T]?: T[K] | Binding; }): Binding; /** * Checks if a target has a bound property. * @param {T} target - The target object. * @param {PropertyKey} property - The property key. * @returns {boolean} True if the target has a bound property, false otherwise. */ static hasBoundProperty(target: T, property: PropertyKey): boolean; /** * Defines a property on the target object. * @param {object} target - The target object. * @param {PropertyKey} property - The property key. * @param {T} [value] - The initial value. * @returns {Binding} The defined binding. */ static defineProperty(target: object, property: PropertyKey, value?: T): Binding; /** * Pipes the binding to another expression. * @param {TKey | string | Expressions | ((ev: BindingChangedEvent) => U)} expression - The expression to pipe to. * @returns {Binding} The piped binding. */ pipe(expression: TKey): Binding; pipe(expression: string | keyof T | Expressions | ((ev: BindingChangedEvent) => U)): Binding; watcher: Watcher; [Symbol.dispose](): void; /** * Creates an instance of Binding. * @param {unknown} target - The target object. * @param {Expressions} expression - The expression. */ constructor(target: unknown, expression: Expressions); /** * Simplifies the binding. * @param {Binding} target - The target binding. * @param {Expressions} expression - The expression. * @returns {Binding | null} The simplified binding. */ static simplify(target: Binding, expression: Expressions): Binding | null; private readonly attachWatcher; /** * Unwraps the element. * @param {T} element - The element to unwrap. * @returns {Partial} The unwrapped element. */ static unwrap(element: T): Partial; private _setter?; /** * Registers a handler for the change event. * @param {(ev: { value: T, oldValue: T }) => void} handler - The event handler. * @param {boolean} [triggerOnRegister] - Whether to trigger the handler on registration. * @returns {Subscription} The subscription. */ onChanged(handler: (ev: { value: T; oldValue: T; }) => void, triggerOnRegister?: boolean): Subscription; /** * Sets the value. * @param {T} value - The value to set. */ setValue(value: T): void; get canSet(): boolean; /** * Gets the value. * @returns {T} The value. */ getValue(): T; } export declare class EmptyBinding extends Binding { /** * Creates an instance of EmptyBinding. * @param {T} [initialValue] - The initial value. */ constructor(initialValue?: T); get canSet(): boolean; /** * Gets the value. * @returns {T} The value. */ getValue(): T; /** * Sets the value. * @param {T} newValue - The value to set. */ setValue(newValue: T): void; } export declare const allProperties: unique symbol; /** * Observable object implementation. * @param {Object} initialObject - The initial object. */ export declare class ObservableObject extends EventEmitter> { /** * Unwraps the target object. * @param {T} arg0 - The target object. * @returns {T extends ObservableObject ? X : T} The unwrapped object. */ static unwrap(arg0: T): T extends ObservableObject ? X : T; /** * Generates a dynamic proxy that gets and sets values from target, but triggers notifications on set. */ static wrap(target: T): IWatched; readonly target: T & IWatchable; /** * Creates an instance of ObservableObject. * @param {T & { [watcher]?: ObservableObject } | ObservableObject} target - The target object. */ constructor(target: (T & IWatchable) | ObservableObject); /** * Watches all properties of the object. * @param {T} obj - The object to watch. * @param {Watcher} watcher - The watcher instance. * @returns {Subscription} The subscription. */ static watchAll(obj: T, watcher: Watcher): Subscription; /** * Watches a property of the object. * @param {Watcher} watcher - The watcher instance. * @param {TKey} property - The property to watch. * @returns {Subscription} The subscription. */ watch>>(watcher: Watcher, property: TKey): Subscription; /** * Checks if an object is watched. * @param {T} x - The object to check. * @returns {boolean} True if the object is watched, false otherwise. */ static isWatched(x: T): x is IWatched; /** * Sets the value of a property. * @param {Binding | T} target - The target object or binding. * @param {Expressions | PropertyKey} expression - The expression or property key. * @param {any} value - The value to set. */ static setValue(target: Binding, expression: TKey, value: T[TKey]): any; static setValue(target: Binding, expression: string, value: any): any; static setValue(target: Binding, expression: Expressions, value: any): any; static setValue(target: T, expression: TKey, value: T[TKey]): any; static setValue(target: T, expression: string, value: any): any; static setValue(target: T, expression: Expressions, value: any): any; /** * Sets the value of a property. * @param {TKey} property - The property key. * @param {T[TKey]} value - The value to set. * @returns {boolean} True if the value was set, false otherwise. */ setValue(property: TKey, value: T[TKey]): boolean; /** * Gets the value of a property. * @param {TKey} property - The property key. * @returns {T[TKey]} The value of the property. */ getValue(property: TKey): T[TKey]; /** * Gets the value of a property. * @param {Binding | T} target - The target object or binding. * @param {TKey} property - The property key. * @returns {T[TKey]} The value of the property. */ static getValue(target: Binding, property: TKey): T[TKey]; static getValue(target: T, property: TKey): T[TKey]; /** * Gets the observable object for a property. * @param {TKey} property - The property key. * @returns {ObservableObject | null} The observable object or null. */ getObservable(property: TKey): T[TKey] extends object ? ObservableObject : null; /** * Gets the value of a property. * @param {T} target - The target object. * @param {keyof T} property - The property key. * @returns {T[keyof T]} The value of the property. */ static get(target: T, property: keyof T): T[keyof T]; } export {};