export class Sessions extends EventManager { constructor() { this.users = []; } userExists(user) { return !!this.findUser(user); } findUser(user) { return this.users.find(u => u.username === user.username); } addUser(user) { if (!this.userExists(user)) { this.users.push(user); this.emit('user-logged-in', user); } } clearUser(user) { if (this.userExists(user)) { const index = this.users.indexOf(user); if (index > -1) { this.users.splice(index - 1, 1); this.emit('user-removed', user); } } } }