Skip to content
This repository was archived by the owner on Sep 18, 2020. It is now read-only.

Commit 9d6a63d

Browse files
committed
tidying up
1 parent 2bfa730 commit 9d6a63d

File tree

4 files changed

+38
-31
lines changed

4 files changed

+38
-31
lines changed

extension.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,24 @@ module.exports = function(extensionApi) {
3636
nodecg.sendMessage('update', channel, data);
3737
}
3838

39-
function addChannels() {
40-
nodecg.bundleConfig.channels.forEach(channelName => {
41-
if (channelCache[channelName] !== undefined) {
42-
return;
43-
}
39+
function addChannel(channelName) {
40+
if (channelCache[channelName] !== undefined) {
41+
return;
42+
}
4443

45-
const channel = new Channel(channelName, nodecg, live);
46-
channel.on(FOLLOW, onEvent.bind(this, channelName, FOLLOW));
47-
channel.on(
48-
SUBSCRIPTION,
49-
onEvent.bind(this, channelName, SUBSCRIPTION)
50-
);
51-
channel.on('update', onUpdate.bind(this, channelName, 'update'));
52-
channel.on(HOST, onEvent.bind(this, channelName, HOST));
53-
channelCache[channelName] = channel;
54-
});
44+
const channel = new Channel(channelName, nodecg, live);
45+
channel.on(FOLLOW, onEvent.bind(this, channelName, FOLLOW));
46+
channel.on(
47+
SUBSCRIPTION,
48+
onEvent.bind(this, channelName, SUBSCRIPTION)
49+
);
50+
channel.on('update', onUpdate.bind(this, channelName, 'update'));
51+
channel.on(HOST, onEvent.bind(this, channelName, HOST));
52+
channelCache[channelName] = channel;
53+
}
54+
55+
function addChannels() {
56+
nodecg.bundleConfig.channels.forEach(channelName => addChannel(channelName));
5557
}
5658

5759
function eachChannel(func) {

lib/Channel.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const EventEmitter = require('events');
22
const Store = require('./store');
33
const _ = require('lodash');
4+
const { FOLLOW, HOST, SUBSCRIPTION } = require('./util');
45

56
class Channel extends EventEmitter {
67
constructor(channelName, nodecg, live) {
@@ -78,14 +79,14 @@ class Channel extends EventEmitter {
7879
}
7980

8081
handleHost(host) {
81-
this.emit('host', host, Date.now());
82+
this.emit(HOST, host, Date.now());
8283
}
8384

8485
handleFollow(username) {
8586
const ts = Date.now();
8687
this.store.hasFollow(username, ts).then(result => {
8788
if (!result) {
88-
this.emit('follow', username, ts);
89+
this.emit(FOLLOW, username, ts);
8990
this.store.addFollow(username, ts);
9091
}
9192
});
@@ -95,17 +96,17 @@ class Channel extends EventEmitter {
9596
const ts = Date.now();
9697
this.store.hasSubscription(username, ts).then(result => {
9798
if (!result) {
98-
this.emit('subscription', username, ts);
99+
this.emit(SUBSCRIPTION, username, ts);
99100
this.store.addSubscription(username, ts);
100101
}
101102
});
102103
}
103104

104105
dismiss(item) {
105-
if (item.type === 'follow') {
106+
if (item.type === FOLLOW) {
106107
this.store.dismissFollow(item.username);
107108
}
108-
if (item.type === 'subscription') {
109+
if (item.type === SUBSCRIPTION) {
109110
this.store.dismissSubscription(item.username);
110111
}
111112
}

lib/store/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const Datastore = require('nedb');
22

33
const createUser = require('./createUser');
4+
const { FOLLOW, HOST, SUBSCRIPTION } = require('../util');
45

56
const Store = function(name) {
67
var dbName;
@@ -62,10 +63,10 @@ Store.prototype = {
6263
});
6364
},
6465
findUnDismissedFollows: function() {
65-
return this._findUnDismissed('follow');
66+
return this._findUnDismissed(FOLLOW);
6667
},
6768
findUnDismissedSubscriptions: function() {
68-
return this._findUnDismissed('subscription');
69+
return this._findUnDismissed(SUBSCRIPTION);
6970
},
7071
getUser: function(username) {
7172
var self = this;
@@ -80,10 +81,10 @@ Store.prototype = {
8081
});
8182
},
8283
hasFollow: function(username) {
83-
return this._hasEvent(username, 'follow');
84+
return this._hasEvent(username, FOLLOW);
8485
},
8586
hasSubscription: function(username, ts) {
86-
return this._hasEvent(username, 'subscription', ts);
87+
return this._hasEvent(username, SUBSCRIPTION, ts);
8788
},
8889
_hasEvent: function(username, type, ts) {
8990
var self = this;
@@ -119,10 +120,10 @@ Store.prototype = {
119120
});
120121
},
121122
addFollow: function(username, ts) {
122-
return this._addEvent(username, 'follow', ts);
123+
return this._addEvent(username, FOLLOW, ts);
123124
},
124125
addSubscription: function(username, ts) {
125-
return this._addEvent(username, 'subscription', ts);
126+
return this._addEvent(username, SUBSCRIPTION, ts);
126127
},
127128
_dismissEvent: function(username, type) {
128129
var self = this;
@@ -140,10 +141,10 @@ Store.prototype = {
140141
});
141142
},
142143
dismissFollow: function(username) {
143-
return this._dismissEvent(username, 'follow');
144+
return this._dismissEvent(username, FOLLOW);
144145
},
145146
dismissSubscription: function(username) {
146-
return this._dismissEvent(username, 'subscription');
147+
return this._dismissEvent(username, SUBSCRIPTION);
147148
}
148149
};
149150
module.exports = Store;

lib/util.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
export const SUBSCRIPTION = 'subscription';
2-
export const FOLLOW = 'follow';
3-
export const HOST = 'host';
1+
module.exports = {
2+
SUBSCRIPTION: 'subscription',
3+
FOLLOW: 'follow',
4+
HOST: 'host',
5+
UNFOLLOW: 'unfollow',
6+
};

0 commit comments

Comments
 (0)