import { Action } from '@ulangi/ulangi-action' ; import { Store } from 'redux' ; import { EventFacade } from './EventFacade' ; import { EventListener } from './types/EventListener' ; export class EventBus { private disposers : ( ( ) => void ) [ ] ; private store : Store < any > ; private eventFacade : EventFacade ; public constructor ( store , eventFacade ) { this . store = store ; this . eventFacade = eventFacade ; this . disposers = [ ] ; } public pubsub ( action , listener ) { const unsubscribe = this . subscribe ( listener ) ; this . publish ( action ) ; return unsubscribe ; } public publish ( action ) { this . store . dispatch ( action ) ; } public subscribe ( listener ) { const disposer = this . eventFacade . subscribe ( listener ) ; this . disposers . push ( disposer ) ; return disposer ; } public unsubscribeAll ( ) { this . disposers . forEach ( ( disposer ) : void => { disposer ( ) ; } ) ; } }