@synet/patterns
Version:
Robust, battle-tested collection of stable patterns used in Synet packages
28 lines (27 loc) • 719 B
TypeScript
/**
* Interface for observer objects that want to be notified of changes
* Powerful for implementing event-driven architectures
* and decoupling components in your application.
* @see /docs/observer.md
*/
export interface Observer<T> {
update(data: T): void;
}
/**
* Subject that maintains a list of observers and notifies them of changes
*/
export declare class Subject<T> {
private observers;
/**
* Add an observer to be notified of changes
*/
subscribe(observer: Observer<T>): void;
/**
* Remove an observer from the notification list
*/
unsubscribe(observer: Observer<T>): void;
/**
* Notify all observers of a change
*/
notify(data: T): void;
}