@osaedasia/oresume
Version:
A user-friendly library for generating complete Single Page Applications (SPAs)
55 lines (54 loc) • 1.89 kB
TypeScript
import { IObserverService, Observer, Unsubscribe } from "../../domain/definitions/interfaces/observer/IObserverService";
/**
* Implements an observable pattern for managing state changes and notifications.
* @template T - The type of data this Observable will emit
* @implements {IObserverService<T>}
*/
export declare class Observable<T> implements IObserverService<T> {
/**
* Optional storage instance for persistent state management.
*/
private readonly _storage?;
/**
* Set of unique observers registered for state change notifications.
*/
private readonly _observers;
/**
* Maps property keys to their respective observable instances.
*/
private readonly _propertyObservables;
/**
* Current state value maintained by the Observable.
*/
private _currentState;
/**
* Creates a new Observable instance.
* @param {T} defaultValue Initial state value.
* @param {string} [storeKey] Optional key for persistent storage.
*/
constructor(defaultValue: T, storeKey?: string);
/** @inheritDoc */
get state(): T;
/** @inheritDoc */
set state(newState: T);
/** @inheritDoc */
subscribe(observer: Observer<T>): Unsubscribe;
/** @inheritDoc */
listen<X>(observer: IObserverService<X>, onUpdate: Observer<X>): Unsubscribe;
/**
* Notifies all registered observers with the current value.
* @param {T} value Value to send to observers.
*/
private _notify;
/**
* Removes an observer from the subscription list.
* @param {Observer<T>} observer Observer to remove.
*/
private _unsubscribe;
/**
* Creates a proxy wrapper for observable properties.
* @param {T} objectToWrap Object to make observable.
* @returns {T} Proxied object with observable behavior.
*/
private _createObservableProxy;
}