import { Emitter } from './Emitter'; import { IEventContext, IListenerConfig } from './Event'; export declare type IOnCallback = (this: IEventContext, ...args: any[]) => void; export interface IComponent { Emit: { (name: 'error', error: Error); }; On: IOn<{ name: 'error'; event: Error; }>; Declared: 'error'; } export interface IOnGeneric { name: string; event?: any; return?: any; } export declare type IOn = (name: G['name'], callback: (this: IEventContext, event: G['event']) => G['return']) => void | Promise; export interface IComponentSignaturesGeneric { Emit: (name: string, callback: any) => any; On: (name: string, callback: any) => any; Declared: any; } export interface IOnConfig { priority?: IListenerConfig['priority']; limit?: IListenerConfig['limit']; } export interface IOnceConfig { priority?: IListenerConfig['priority']; } /** * A component acts as both a subscriber and an event emitter. */ export declare abstract class Component extends Emitter implements IComponent { /** Input call signatures for emitters */ Emit: any; /** Input call signatures for listeners */ On: any; /** Declared event names by this component */ Declared: S['Declared']; /** Merged call signatures for all emitters */ _AllEmit: S['Emit'] & E['Emit'] & IComponent['Emit']; /** Merged call signatures for all listeners */ _AllOn: IComponent['On'] & E['On'] & S['On']; /** Merged list of event name that can be subscribed to */ _Subscribable: IComponent['Declared'] | E['Declared']; emit: this['_AllEmit']; on: this['_AllOn']; once: this['_AllOn']; components: Set; declarations: Set; subscriptions: Set; /** * Declare that this component will emit an event. * When a component is connected via .connect(), the delcarations are listened to. */ declare(...eventNames: Array): void; /** * Subscribe to an event */ subscribe(...eventNames: Array): void; /** * Relays an event from the **input** component to **this** component. */ relay>(component: C, eventName: C['Declared']): void; /** * Connects this component to another component by: * - Relaying events from the input component's **declared** events to this component. * - Relaying events from this component matching the **subscribed** events on the input component. */ connect(...components: Array>): any; connect(components: Array>): any; disconnect(...components: Array>): void; /** Like connect, but first listens for an event and .connect()'s to that instead */ connectOn(name: string, getComponents: () => Array>): void; private disconnectFromComponents(); }