import { Observable , ReplaySubject } from 'rxjs' ; import { map } from 'rxjs/operators' ; import { XEvent , XEventPayload } from '../wiring/events.types' ; import { WireMetadata , WirePayload } from '../wiring/wiring.types' ; import { Emitter , Emitters , XBus } from './x-bus.types' ; /**
 * Default  XBus implementation.
 *
 *  public export class BaseXBus implements XBus { internal protected emitters : Emitters = { } ; /**
     * Emits an event. See  XBus . .
     *
     *  param event param payload param metadata emit < Event extends XEvent > ( event , payload ? , metadata = { moduleName : null } ) { const value = { eventPayload : payload as any , metadata } ; const emitter = this . getOrCreateEmitter ( event ) ; emitter . next ( value ) ; } /**
     * Retrieves an observable. See  XBus . .
     *
     *  public param event param withMetadata returns on < Event extends XEvent > ( event , withMetadata = false ) { return withMetadata ? this . getOrCreateEmitter ( event ) : this . getOrCreateEmitter ( event ) . pipe ( map ( value => value . eventPayload ) ) ; } param event returns remarks internal protected getOrCreateEmitter < Event extends XEvent > ( event ) { return ( this . emitters [ event ] ?? ( this . emitters [ event ] = new ReplaySubject < WirePayload < XEventPayload < Event > > > ( 1 ) as any ) ) ; } } internal export const bus = new BaseXBus ( ) ;