import { Subscriber } from './types' ; export type Subscribers = { [ url ] : Set < Subscriber > ; } ; const subscribers = { } ; const EMPTY_LIST = [ ] ; export const getSubscribers = ( url ) : Subscriber [ ] => { if ( hasSubscribers ( url ) ) { return Array . from ( subscribers [ url ] ) ; } return EMPTY_LIST ; } ; export const hasSubscribers = ( url ) : boolean => { return subscribers [ url ] ?. size > 0 ; } ; export const addSubscriber = ( url , subscriber ) : void => { subscribers [ url ] = subscribers [ url ] || new Set < Subscriber > ( ) ; subscribers [ url ] . add ( subscriber ) ; } ; export const removeSubscriber = ( url , subscriber ) : void => { subscribers [ url ] . delete ( subscriber ) ; } ;