UNPKG

@osaedasia/oresume

Version:

A user-friendly library for generating complete Single Page Applications (SPAs)

44 lines (43 loc) 1.61 kB
/** * Represents a function that handles state changes. * @template T The type of state being observed. */ export type Observer<T> = (newState: T) => void; /** * Represents a function that removes an observer subscription. */ export type Unsubscribe = () => void; /** * Interface representing an observer service for managing state and subscriptions. * @template T The type of the state being observed. */ export interface IObserverService<T> { /** * @returns {T} The current state value. */ get state(): T; /** * @param {T} value The new state value to set. */ set state(value: T); /** * Subscribes an observer to state changes. * @param {Observer<T>} observer The function to be called when state changes. * @returns {Unsubscribe} A function to remove the subscription. */ subscribe(observer: Observer<T>): Unsubscribe; /** * Subscribes to updates from another observer service. * @template X Type of the observed state. * @param {IObserverService<X>} observer The observer service to subscribe to. * @param {Observer<X>} onUpdate Callback function for handling updates. * @returns {Unsubscribe} A function to remove the subscription. */ listen<X>(observer: IObserverService<X>, onUpdate: Observer<X>): Unsubscribe; } /** * Type guard to check if an object implements the IObserverService interface. * @param {any} obj Object to check * @returns {boolean} True if the object implements IObserverService */ export declare function isAnObserverService(obj: any): obj is IObserverService<any>;