Skip to content

Commit 7881ca7

Browse files
committed
refactor: subscriptionSet will get constructed in form of set of subscriptions when channels/groups set is provided
1 parent 2f3147f commit 7881ca7

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

lib/entities/SubscriptionSet.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,26 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3737
};
3838
Object.defineProperty(exports, "__esModule", { value: true });
3939
exports.SubscriptionSet = void 0;
40-
var Subscription_1 = require("./Subscription");
4140
var SubscriptionSet = /** @class */ (function () {
4241
function SubscriptionSet(_a) {
4342
var _b = _a.channels, channels = _b === void 0 ? [] : _b, _c = _a.channelGroups, channelGroups = _c === void 0 ? [] : _c, subscriptionOptions = _a.subscriptionOptions, eventEmitter = _a.eventEmitter, pubnub = _a.pubnub;
43+
var _this = this;
4444
this.channelNames = [];
4545
this.groupNames = [];
46-
this.channelNames = __spreadArray(__spreadArray([], __read(this.channelNames), false), __read(channels), false);
47-
this.groupNames = __spreadArray(__spreadArray([], __read(this.groupNames), false), __read(channelGroups), false);
46+
this.subscriptionList = [];
4847
this.options = subscriptionOptions;
4948
this.eventEmitter = eventEmitter;
5049
this.pubnub = pubnub;
51-
this.subscriptionList = [
52-
new Subscription_1.Subscription({
53-
channels: this.channelNames,
54-
channelGroups: this.groupNames,
55-
subscriptionOptions: this.options,
56-
eventEmitter: this.eventEmitter,
57-
pubnub: this.pubnub,
58-
}),
59-
];
50+
channels.forEach(function (c) {
51+
var subscription = _this.pubnub.channel(c).subscription(_this.options);
52+
_this.channelNames = __spreadArray(__spreadArray([], __read(_this.channelNames), false), __read(subscription.channels), false);
53+
_this.subscriptionList.push(subscription);
54+
});
55+
channelGroups.forEach(function (cg) {
56+
var subscription = _this.pubnub.channelGroup(cg).subscription(_this.options);
57+
_this.groupNames = __spreadArray(__spreadArray([], __read(_this.groupNames), false), __read(subscription.channelGroups), false);
58+
_this.subscriptionList.push(subscription);
59+
});
6060
}
6161
SubscriptionSet.prototype.subscribe = function () {
6262
var _a, _b;

src/entities/SubscriptionSet.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class SubscriptionSet implements SubscribeCapable {
77
private options: SubscriptionOptions;
88
private pubnub: any;
99
private eventEmitter: any;
10-
private subscriptionList: Subscription[];
10+
private subscriptionList: Subscription[] = [];
1111

1212
constructor({
1313
channels = [],
@@ -22,20 +22,19 @@ export class SubscriptionSet implements SubscribeCapable {
2222
eventEmitter: any;
2323
pubnub: any;
2424
}) {
25-
this.channelNames = channels;
26-
this.groupNames = channelGroups;
2725
this.options = subscriptionOptions;
2826
this.eventEmitter = eventEmitter;
2927
this.pubnub = pubnub;
30-
this.subscriptionList = [
31-
new Subscription({
32-
channels: this.channelNames,
33-
channelGroups: this.groupNames,
34-
subscriptionOptions: this.options,
35-
eventEmitter: this.eventEmitter,
36-
pubnub: this.pubnub,
37-
}),
38-
];
28+
channels.forEach((c) => {
29+
const subscription = this.pubnub.channel(c).subscription(this.options);
30+
this.channelNames = [...this.channelNames, ...subscription.channels];
31+
this.subscriptionList.push(subscription);
32+
});
33+
channelGroups.forEach((cg) => {
34+
const subscription = this.pubnub.channelGroup(cg).subscription(this.options);
35+
this.groupNames = [...this.groupNames, ...subscription.channelGroups];
36+
this.subscriptionList.push(subscription);
37+
});
3938
}
4039
subscribe() {
4140
this.pubnub.subscribe({

0 commit comments

Comments
 (0)