import { ICommandNameFlags } from "./command" ; type AddSet = ICommandNameFlags [ "ENTER_SUBSCRIBER_MODE" ] [ number ] ; type DelSet = ICommandNameFlags [ "EXIT_SUBSCRIBER_MODE" ] [ number ] ; export class export default class SubscriptionSet { private set : { [ key ] : { [ channel ] : boolean ; } ; } = { subscribe : { } , psubscribe : { } , } ; add ( set , channel ) { this . set [ mapSet ( set ) ] [ channel ] = true ; } del ( set , channel ) { delete this . set [ mapSet ( set ) ] [ channel ] ; } channels ( set ) { return Object . keys ( this . set [ mapSet ( set ) ] ) ; } isEmpty ( ) { return ( this . channels ( "subscribe" ) . length === 0 && this . channels ( "psubscribe" ) . length === 0 ) ; } } function mapSet ( set ) { if ( set === "unsubscribe" ) { return "subscribe" ; } if ( set === "punsubscribe" ) { return "psubscribe" ; } return set ; }