mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
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:
@@ -1,4 +1,5 @@
|
||||
const snekfetch = require('snekfetch');
|
||||
const Collection = require('./Collection');
|
||||
const { Colors, DefaultOptions, Endpoints } = require('./Constants');
|
||||
const { Error: DiscordError, RangeError, TypeError } = require('../errors');
|
||||
const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
||||
@@ -413,6 +414,33 @@ class Util {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds methods from collections and maps onto the provided store
|
||||
* @param {DataStore} store The store to mixin
|
||||
* @param {string[]} ignored The properties to ignore
|
||||
* @private
|
||||
*/
|
||||
/* eslint-disable func-names */
|
||||
static mixin(store, ignored) {
|
||||
Object.getOwnPropertyNames(Collection.prototype)
|
||||
.concat(Object.getOwnPropertyNames(Map.prototype)).forEach(prop => {
|
||||
if (ignored.includes(prop)) return;
|
||||
if (prop === 'size') {
|
||||
Object.defineProperty(store.prototype, prop, {
|
||||
get: function() {
|
||||
return this._filtered[prop];
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
const func = Collection.prototype[prop];
|
||||
if (prop === 'constructor' || typeof func !== 'function') return;
|
||||
store.prototype[prop] = function(...args) {
|
||||
return func.apply(this._filtered, ...args);
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Util;
|
||||
|
||||
Reference in New Issue
Block a user