mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03:31 +01:00
refactor: make LimitedCollection an implementation detail (#3872)
This commit is contained in:
@@ -17,7 +17,6 @@ module.exports = {
|
|||||||
Collection: require('./util/Collection'),
|
Collection: require('./util/Collection'),
|
||||||
Constants: require('./util/Constants'),
|
Constants: require('./util/Constants'),
|
||||||
DataResolver: require('./util/DataResolver'),
|
DataResolver: require('./util/DataResolver'),
|
||||||
LimitedCollection: require('./util/LimitedCollection'),
|
|
||||||
BaseManager: require('./managers/BaseManager'),
|
BaseManager: require('./managers/BaseManager'),
|
||||||
DiscordAPIError: require('./rest/DiscordAPIError'),
|
DiscordAPIError: require('./rest/DiscordAPIError'),
|
||||||
HTTPError: require('./rest/HTTPError'),
|
HTTPError: require('./rest/HTTPError'),
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class MessageManager extends BaseManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The cache of Messages
|
* The cache of Messages
|
||||||
* @type {LimitedCollection<Snowflake, Message>}
|
* @type {Collection<Snowflake, Message>}
|
||||||
* @name MessageManager#cache
|
* @name MessageManager#cache
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const Collection = require('./Collection.js');
|
|||||||
* @extends {Collection}
|
* @extends {Collection}
|
||||||
* @param {number} [maxSize=0] The maximum size of the Collection
|
* @param {number} [maxSize=0] The maximum size of the Collection
|
||||||
* @param {Iterable} [iterable=null] Optional entries passed to the Map constructor.
|
* @param {Iterable} [iterable=null] Optional entries passed to the Map constructor.
|
||||||
|
* @private
|
||||||
*/
|
*/
|
||||||
class LimitedCollection extends Collection {
|
class LimitedCollection extends Collection {
|
||||||
constructor(maxSize = 0, iterable = null) {
|
constructor(maxSize = 0, iterable = null) {
|
||||||
@@ -24,6 +25,10 @@ class LimitedCollection extends Collection {
|
|||||||
if (this.size >= this.maxSize && !this.has(key)) this.delete(this.firstKey());
|
if (this.size >= this.maxSize && !this.has(key)) this.delete(this.firstKey());
|
||||||
return super.set(key, value);
|
return super.set(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static get [Symbol.species]() {
|
||||||
|
return Collection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = LimitedCollection;
|
module.exports = LimitedCollection;
|
||||||
|
|||||||
7
typings/index.d.ts
vendored
7
typings/index.d.ts
vendored
@@ -1914,11 +1914,6 @@ declare module 'discord.js' {
|
|||||||
public toJSON(): object;
|
public toJSON(): object;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LimitedCollection<K, V> extends Collection<K, V> {
|
|
||||||
public constructor(maxSize: number, iterable: Iterable<any>);
|
|
||||||
public maxSize: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region Managers
|
//#region Managers
|
||||||
@@ -2016,7 +2011,7 @@ declare module 'discord.js' {
|
|||||||
export class MessageManager extends BaseManager<Snowflake, Message, MessageResolvable> {
|
export class MessageManager extends BaseManager<Snowflake, Message, MessageResolvable> {
|
||||||
constructor(channel: TextChannel | DMChannel, iterable?: Iterable<any>);
|
constructor(channel: TextChannel | DMChannel, iterable?: Iterable<any>);
|
||||||
public channel: TextBasedChannelFields;
|
public channel: TextBasedChannelFields;
|
||||||
public cache: LimitedCollection<Snowflake, Message>;
|
public cache: Collection<Snowflake, Message>;
|
||||||
public fetch(message: Snowflake, cache?: boolean): Promise<Message>;
|
public fetch(message: Snowflake, cache?: boolean): Promise<Message>;
|
||||||
public fetch(options?: ChannelLogsQueryOptions, cache?: boolean): Promise<Collection<Snowflake, Message>>;
|
public fetch(options?: ChannelLogsQueryOptions, cache?: boolean): Promise<Collection<Snowflake, Message>>;
|
||||||
public fetchPinned(cache?: boolean): Promise<Collection<Snowflake, Message>>;
|
public fetchPinned(cache?: boolean): Promise<Collection<Snowflake, Message>>;
|
||||||
|
|||||||
Reference in New Issue
Block a user