{"version":3,"file":"types.cjs","sources":["../../../src/events/types.ts"],"sourcesContent":["import { Unsubscribable, Observable } from 'rxjs';\n\n/**\n * @alpha\n * internal interface\n */\nexport interface BusEvent {\n  readonly type: string;\n  readonly payload?: any;\n  origin?: EventBus;\n}\n\n/**\n * @alpha\n * Base event type\n */\nexport abstract class BusEventBase implements BusEvent {\n  readonly type: string;\n  readonly payload?: any;\n  readonly origin?: EventBus;\n\n  /** @internal */\n  tags?: Set<string>;\n\n  constructor() {\n    //@ts-ignore\n    this.type = this.__proto__.constructor.type;\n  }\n\n  /**\n   * @internal\n   * Tag event for finer-grained filtering in subscribers\n   */\n  setTags(tags: string[]) {\n    this.tags = new Set(tags);\n    return this;\n  }\n}\n\n/**\n * @alpha\n * Base event type with payload\n */\nexport abstract class BusEventWithPayload<T> extends BusEventBase {\n  readonly payload: T;\n\n  constructor(payload: T) {\n    super();\n    this.payload = payload;\n  }\n}\n\n/*\n * Interface for an event type constructor\n */\nexport interface BusEventType<T extends BusEvent> {\n  type: string;\n  new (...args: any[]): T;\n}\n\n/**\n * @alpha\n * Event callback/handler type\n */\nexport interface BusEventHandler<T extends BusEvent> {\n  (event: T): void;\n}\n\n/**\n * @alpha\n * Main minimal interface\n */\nexport interface EventFilterOptions {\n  onlyLocal: boolean;\n}\n\n/**\n * @alpha\n * Main minimal interface\n */\nexport interface EventBus {\n  /**\n   * Publish single event\n   */\n  publish<T extends BusEvent>(event: T): void;\n\n  /**\n   * Get observable of events\n   */\n  getStream<T extends BusEvent>(eventType: BusEventType<T>): Observable<T>;\n\n  /**\n   * Subscribe to an event stream\n   *\n   * This function is a wrapper around the `getStream(...)` function\n   */\n  subscribe<T extends BusEvent>(eventType: BusEventType<T>, handler: BusEventHandler<T>): Unsubscribable;\n\n  /**\n   * Remove all event subscriptions\n   */\n  removeAllListeners(): void;\n\n  /**\n   * Returns a new bus scoped that knows where it exists in a heiarchy\n   *\n   * @internal -- This is included for internal use only should not be used directly\n   */\n  newScopedBus(key: string, filter: EventFilterOptions): EventBus;\n}\n\n/**\n * @public\n * @deprecated event type\n */\nexport interface AppEvent<T> {\n  readonly name: string;\n  payload?: T;\n}\n\n/** @public */\nexport interface LegacyEmitter {\n  /**\n   * @deprecated use $emit\n   */\n  emit<T>(event: AppEvent<T> | string, payload?: T): void;\n\n  /**\n   * @deprecated use $on\n   */\n  on<T>(event: AppEvent<T> | string, handler: LegacyEventHandler<T>): void;\n\n  /**\n   * @deprecated use $on\n   */\n  off<T>(event: AppEvent<T> | string, handler: LegacyEventHandler<T>): void;\n}\n\n/** @public */\nexport interface LegacyEventHandler<T> {\n  (payload?: T): void;\n  wrapper?: (event: BusEvent) => void;\n}\n\n/** @alpha */\nexport interface EventBusExtended extends EventBus, LegacyEmitter {}\n"],"names":[],"mappings":";;;;;AAgBO,MAAe,YAAA,CAAiC;AAAA,EAQrD,WAAA,GAAc;AAEZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA,CAAK,SAAA,CAAU,WAAA,CAAY,IAAA;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,QAAQ,IAAA,EAAgB;AACtB,IAAA,IAAA,CAAK,IAAA,GAAO,IAAI,GAAA,CAAI,IAAI,CAAA;AACxB,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AAMO,MAAe,4BAA+B,YAAA,CAAa;AAAA,EAGhE,YAAY,OAAA,EAAY;AACtB,IAAA,KAAA,EAAM;AACN,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAAA,EACjB;AACF;;;;;"}