/**
 * Very simple PubSub system.
 */ export class PubSub { subscribers : Map < string , any [ ] > = new Map < string , any [ ] > ( ) ; param message param callback returns subscribe ( message , callback ) { const subscribers = this . subscribers . get ( message ) || [ ] ; subscribers . push ( callback ) ; this . subscribers . set ( message , subscribers ) ; return ( ) => { if ( subscribers . length > 1 ) { subscribers . splice ( subscribers . indexOf ( callback ) , 1 ) ; } else { this . subscribers . delete ( message ) ; } } ; } param message param data publish ( message , data ? ) { const subscribers = this . subscribers . get ( message ) || [ ] ; subscribers . forEach ( subscriber => { subscriber ( message , data ) ; } ) ; } /**
     *
     */ unsubscribeAll ( ) { this . subscribers = new Map ( ) ; } }