You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
851 B
42 lines
851 B
'use strict'; |
|
|
|
/** |
|
* Tiny class to simplify dealing with subscription set |
|
* |
|
* @constructor |
|
* @private |
|
*/ |
|
function SubscriptionSet() { |
|
this.set = { |
|
subscribe: {}, |
|
psubscribe: {} |
|
}; |
|
} |
|
|
|
SubscriptionSet.prototype.add = function (set, channel) { |
|
this.set[mapSet(set)][channel] = true; |
|
}; |
|
|
|
SubscriptionSet.prototype.del = function (set, channel) { |
|
delete this.set[mapSet(set)][channel]; |
|
}; |
|
|
|
SubscriptionSet.prototype.channels = function (set) { |
|
return Object.keys(this.set[mapSet(set)]); |
|
}; |
|
|
|
SubscriptionSet.prototype.isEmpty = function () { |
|
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; |
|
} |
|
|
|
module.exports = SubscriptionSet;
|
|
|