export type Listener = (data: T) => void; /** * Signal is a simple event emitter for one type of event. * @example * ```ts * const foodArrived = new Signal(); * * foodArrived.subscribe(() => { * console.log('Food arrived!'); * }); * * foodArrived.notify(new Food('pizza')); * ``` * * @example Usage in a class: * ```ts * class LoginService { * public onLoginSuccess = new Signal(); * public onLoginFailure = new Signal(); * public onLoginStatusChange = new Signal(); * } * ``` * @remarks * Use Signals a public api for emitting events. * Naming a signal is like naming the event the it triggers. * If the name sounds like a property try to add a `on` prefix or `Change/Signal` suffix. * All methods are bound to the Signal instance * * Notice that the Signals are public. * We don't need to implement specific subscriptions on the class, unless we need to expose it as a remote service. */ export declare class Signal { private handlers; constructor(handlers?: Listener[]); /** * Subscribe a notification callback * * @param handler - Will be executed with a data arg when a notification occurs */ subscribe: (handler: Listener) => void; /** * Subscribe to only the next notification * * @param handler - Will be executed with a data arg when a notification occurs */ once: (handler: Listener) => void; /** * @returns true if a listener is subscribed */ has(value: Listener): boolean; /** * Unsubscribe an existing callback */ unsubscribe: (handler: Listener) => void; get size(): number; /** * Notify all subscribers with arg data */ notify: (data: T) => void; clear(): void; } //# sourceMappingURL=signal.d.ts.map