refactor: role stores (#2478)

* refactor: reduced duplication in role stores

* fix docs

* fix: typo

* most of requested changes

* rest of changes

* ACTUAL rest of changes

* docs

* doooocs

* reason
This commit is contained in:
Isabella
2018-04-24 15:52:00 -05:00
committed by GitHub
parent e12ab7428f
commit 8b83553462
5 changed files with 183 additions and 144 deletions

View File

@@ -16,12 +16,7 @@ class GuildEmoji extends Emoji {
*/
this.guild = guild;
/**
* A collection of roles this emoji is active for (empty if all), mapped by role ID
* @type {GuildEmojiRoleStore<Snowflake, Role>}
*/
this.roles = new GuildEmojiRoleStore(this);
this._roles = [];
this._patch(data);
}
@@ -49,6 +44,14 @@ class GuildEmoji extends Emoji {
return clone;
}
/**
* A collection of roles this emoji is active for (empty if all), mapped by role ID
* @type {GuildEmojiRoleStore<Snowflake, Role>}
*/
get roles() {
return new GuildEmojiRoleStore(this);
}
/**
* The timestamp the emoji was created at
* @type {number}

View File

@@ -27,15 +27,6 @@ class GuildMember extends Base {
*/
this.user = {};
/**
* A list of roles that are applied to this GuildMember, mapped by the role ID
* @type {GuildMemberRoleStore<Snowflake, Role>}
*/
this.roles = new GuildMemberRoleStore(this);
if (data) this._patch(data);
/**
* The ID of the last message sent by the member in their guild, if one was sent
* @type {?Snowflake}
@@ -47,6 +38,9 @@ class GuildMember extends Base {
* @type {?Snowflake}
*/
this.lastMessageChannelID = null;
this._roles = [];
if (data) this._patch(data);
}
_patch(data) {
@@ -71,16 +65,25 @@ class GuildMember extends Base {
*/
if (data.joined_at) this.joinedTimestamp = new Date(data.joined_at).getTime();
this.user = this.guild.client.users.add(data.user);
if (data.user) this.user = this.guild.client.users.add(data.user);
if (data.roles) this.roles._patch(data.roles);
}
_clone() {
const clone = super._clone();
clone.roles = this.roles.clone();
clone._roles = this._roles.slice();
return clone;
}
/**
* A collection of roles that are applied to this GuildMember, mapped by the role ID
* @type {GuildMemberRoleStore<Snowflake, Role>}
* @readonly
*/
get roles() {
return new GuildMemberRoleStore(this);
}
/**
* The Message object of the last message sent by the member in their guild, if one was sent
* @type {?Message}