export class Subscribable < MessageType > { private subscribers : Set < ( msg : MessageType ) => void > = new Set ( ) ; constructor ( ) { } subscribe ( cb ) { this . subscribers . add ( cb ) ; return ( ) => { this . subscribers . delete ( cb ) ; } ; } publish ( msg ) { this . subscribers . forEach ( ( cb ) => cb ( msg ) ) ; } }