export function createSubscribable < MessageType > ( ) { const subscribers = new Set ( ) ; return { subscribe ( cb ) { subscribers . add ( cb ) ; return ( ) => { subscribers . delete ( cb ) ; } ; } , publish ( msg ) { subscribers . forEach ( ( cb ) => cb ( msg ) ) ; } , } ; }