Equals updates (#987)

* Docs update

Changed the param names and param descriptions to be consistent.

* Added === comparison

Changed Presence.equals and Game.equals to first compare using ===

* Collection.equals fix

Now returns false when collection is undefined, instead of crashing
💯
This commit is contained in:
Alexander
2016-12-14 23:10:34 +01:00
committed by Schuyler Cebulskie
parent 906bb3c5f3
commit 264ee8e7f1
7 changed files with 19 additions and 18 deletions

View File

@@ -89,7 +89,7 @@ class GroupDMChannel extends Channel {
* Whether this channel equals another channel. It compares all properties, so for most operations
* it is advisable to just compare `channel.id === channel2.id` as it is much faster and is often
* what most users need.
* @param {GroupDMChannel} channel The channel to compare to
* @param {GroupDMChannel} channel Channel to compare with
* @returns {boolean}
*/
equals(channel) {

View File

@@ -692,7 +692,7 @@ class Guild {
* Whether this Guild equals another Guild. It compares all properties, so for most operations
* it is advisable to just compare `guild.id === guild2.id` as it is much faster and is often
* what most users need.
* @param {Guild} guild The guild to compare
* @param {Guild} guild Guild to compare with
* @returns {boolean}
*/
equals(guild) {

View File

@@ -259,7 +259,7 @@ class GuildChannel extends Channel {
/**
* Checks if this channel has the same type, topic, position, name, overwrites and ID as another channel.
* In most cases, a simple `channel.id === channel2.id` will do, and is much faster too.
* @param {GuildChannel} channel The channel to compare this channel to
* @param {GuildChannel} channel Channel to compare with
* @returns {boolean}
*/
equals(channel) {

View File

@@ -28,14 +28,14 @@ class Presence {
/**
* Whether this presence is equal to another
* @param {Presence} other the presence to compare
* @param {Presence} presence Presence to compare with
* @returns {boolean}
*/
equals(other) {
return (
other &&
this.status === other.status &&
this.game ? this.game.equals(other.game) : !other.game
equals(presence) {
return this === presence || (
presence &&
this.status === presence.status &&
this.game ? this.game.equals(presence.game) : !presence.game
);
}
}
@@ -75,15 +75,15 @@ class Game {
/**
* Whether this game is equal to another game
* @param {Game} other the other game to compare
* @param {Game} game Game to compare with
* @returns {boolean}
*/
equals(other) {
return (
other &&
this.name === other.name &&
this.type === other.type &&
this.url === other.url
equals(game) {
return this === game || (
game &&
this.name === game.name &&
this.type === game.type &&
this.url === game.url
);
}
}

View File

@@ -302,7 +302,7 @@ class Role {
* Whether this role equals another role. It compares all properties, so for most operations
* it is advisable to just compare `role.id === role2.id` as it is much faster and is often
* what most users need.
* @param {Role} role The role to compare to
* @param {Role} role Role to compare with
* @returns {boolean}
*/
equals(role) {

View File

@@ -230,7 +230,7 @@ class User {
/**
* Checks if the user is equal to another. It compares username, ID, discriminator, status and the game being played.
* It is recommended to compare equality by using `user.id === user2.id` unless you want to compare all properties.
* @param {User} user The user to compare
* @param {User} user User to compare with
* @returns {boolean}
*/
equals(user) {

View File

@@ -338,6 +338,7 @@ class Collection extends Map {
* @returns {boolean} Whether the collections have identical contents
*/
equals(collection) {
if (!collection) return false;
if (this === collection) return true;
if (this.size !== collection.size) return false;
return !this.find((value, key) => {