Skip to content

Commit

Permalink
refactor(BitField): reverse iterator/toArray responsibilities (#9118)
Browse files Browse the repository at this point in the history
refactor(BitField): reverse iterator/toArray responsabilities
  • Loading branch information
almeidx committed Feb 17, 2023
1 parent b8684e0 commit f70df91
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/discord.js/src/util/BitField.js
Expand Up @@ -127,7 +127,7 @@ class BitField {
* @returns {string[]}
*/
toArray(...hasParams) {
return Object.keys(this.constructor.Flags).filter(bit => this.has(bit, ...hasParams));
return [...this[Symbol.iterator](...hasParams)];
}

toJSON() {
Expand All @@ -138,8 +138,10 @@ class BitField {
return this.bitfield;
}

*[Symbol.iterator]() {
yield* this.toArray();
*[Symbol.iterator](...hasParams) {
for (const bitName of Object.keys(this.constructor.Flags)) {
if (this.has(bitName, ...hasParams)) yield bitName;
}
}

/**
Expand Down

2 comments on commit f70df91

@vercel
Copy link

@vercel vercel bot commented on f70df91 Feb 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on f70df91 Feb 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.