export interface ProxyOpts { onChange: (path: (string | number)[], target: any, newValue: any, metadata: DecoratorMetadata) => void; onDelete: (path: (string | number)[], metadata: DecoratorMetadata) => void; } export interface UpdateInfo { path: (string | number)[]; value: any; deleted: boolean; customMetadata?: any; } export declare type SendFunction = (upd: UpdateInfo) => void; interface DecoratorMetadata { delay?: number; before?: boolean; after?: boolean; customData?: any; } /** * Wrap the given object in a recursive Proxy, which wraps all non-primitive values in another nested Proxy. * * Automatically keeps track of the current path to the property referenced, * and loads metadata stored from any decorators used on the properties. * * Supports callbacks for whenever any nested property is set or deleted. */ export declare function proxify(target: T, opts: ProxyOpts, tracker?: (string | number)[], metadata?: any): T; /** * Wraps the given Object in a Proxy, and broadcasts any (recursive) changes. */ export declare class Streamer { private pending; state: T; private send; constructor(state: T, sendFunction?: { (...data: any[]): void; (message?: any, ...optionalParams: any[]): void; }); setSender(sender: SendFunction): void; /** * Get all scheduled timers along the given path, and then all branching above the path's end. * @private */ private getPending; /** * Removes the Timer ID from the pending tree. Does not clear the actual timer. * Does not clear recursively to the root, but instead deletes the timer ID and wrapper object. * This is used for self-cleanup once a timer has finished. * * eg: `remove(['obj','a']) -> ['obj']` * @param path */ removePending(path: any[]): void; getValue(path: any[]): any; /** * Set a pending outgoing notification that will broadcast the value at the given path. * Unless specified otherwise, skips scheduling an alert if there is a lower-level alert already pending. * Automatically cancels any pending higher-level alerts. * @private */ private setPending; private onChange; private onDelete; sendChange(path: (string | number)[], deleted: boolean, metadata: DecoratorMetadata): void; /** * Attaches metadata to a weakly-linked metadata object, specific to this instance's class and property. * @param targetClass The Class that is being targeted. * @param propertyName The name of the property to build metadata for. * @param value The new Metadata to use. * @private */ private static setMetadata; /** * A decorator, used to tag any properties in a Class that should be throttled. * * While awaiting this delay, subsequent updates to this property will not be scheduled. * At the end of the delay, the latest value will be send. */ static delay(durationMS?: number): (targetClass: any, propertyKey: string) => void; /** * A decorator, used to tag any properties in a Class that should be throttled. * * Updates to the tagged property will be instantly sent. * Subsequent updates will not send during the timeout. * As the timeout finishes, another update will be sent if the value has changed since the initial send. * * NOTE: There is currently an issue with this decorator: * Sending a new value right after the previous send timer finishes will not properly respect the desired timer. */ static throttle(durationMS?: number): (targetClass: any, propertyKey: string) => void; /** * A decorator, used to tag the given property with custom data. * * This data will be passed back out to the custom `send` method provided to each Streamer, * whenever this property changes. */ static customMetadata(customData: any): (targetClass: any, propertyKey: string) => void; } export {};