Convert disabledEvents Array to Object (#786)

* Convert disabledEvents Array to Object

Increased performance

* Commit to please Lord Gawdl3y

* Nitpick with chopsticks
This commit is contained in:
Programmix
2016-10-09 11:22:52 -07:00
committed by Schuyler Cebulskie
parent 4653f88555
commit 3e2d6ccc48
2 changed files with 14 additions and 1 deletions

View File

@@ -37,6 +37,17 @@ class Client extends EventEmitter {
this.options.shardCount = Number(process.env.SHARD_COUNT);
}
if (!(this.options.disabledEvents instanceof Array)) {
throw new TypeError('The disabledEvents client option must be an array.');
}
let disabledEvents = {};
for (const event in this.options.disabledEvents) {
disabledEvents[event] = true;
}
this.options.disabledEvents = disabledEvents;
/**
* The REST manager of the client
* @type {RESTManager}

View File

@@ -84,7 +84,9 @@ class WebSocketPacketManager {
this.setSequence(packet.s);
if (this.ws.client.options.disabledEvents.includes(packet.t)) return false;
if (this.ws.client.options.disabledEvents[packet.t] !== undefined) {
return false;
}
if (this.ws.status !== Constants.Status.READY) {
if (BeforeReadyWhitelist.indexOf(packet.t) === -1) {