Skip to content

Commit

Permalink
fix(LimitedCollection): fix keepOverLimit behavior discordjs#10062
Browse files Browse the repository at this point in the history
* always allow updating of elements even when maxSize is 0
* keep elements in the collection and disallow adding new ones if non matching the keepOverLimit expression
* do not remove any non-matching element from the collection when a new one is tried to add
  • Loading branch information
Pablo Thomas committed Feb 7, 2024
1 parent ae57d7f commit 2c67068
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions packages/discord.js/src/util/LimitedCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,10 @@ class LimitedCollection extends Collection {
}

set(key, value) {
if (this.maxSize === 0 && !this.keepOverLimit?.(value, key, this)) return this;
if (this.size >= this.maxSize && !this.has(key)) {
for (const [k, v] of this.entries()) {
const keep = this.keepOverLimit?.(v, k, this) ?? false;
if (!keep) {
this.delete(k);
break;
}
const keep = this.keepOverLimit?.(value, key, this) ?? false;
if (!keep) {
return this;
}
}
return super.set(key, value);
Expand Down

0 comments on commit 2c67068

Please sign in to comment.