export class EmaSubscription { constructor ( private action , public scope , private service ) { } unsubscribe ( ) { this . service . unsubscribe ( this ) ; } call ( ) { this . action ( ) ; } } export class PubSubService { private subs : EmaSubscription [ ] = [ ] ; publish ( scope ) { this . subs . filter ( x => x . scope === scope ) . forEach ( sub => { sub . call ( ) ; } ) ; } subscribe ( scope , action ) { const sub = new EmaSubscription ( action , scope , this ) ; this . subs . push ( sub ) ; return sub ; } unsubscribe ( sub ) { this . subs = this . subs . filter ( s => s !== sub ) ; } }