Webpack build for branch custom-structures: 47dc8fd046

This commit is contained in:
Travis CI 2017-11-20 03:44:46 +00:00
parent 3a391ba54a
commit 4b5973210f
2 changed files with 34 additions and 27 deletions

View file

@ -9601,20 +9601,7 @@ module.exports = DMChannel;
/***/ (function(module, exports, __webpack_require__) {
/**
* Allows for the extension of built-in Discord.js structures that are instantiated by {@link DataStore}s.
* When extending a built-in structure, it is important to both get the class you're extending from here,
* and to set it here afterwards.
* @example
* const { Structures } = require('discord.js');
*
* class CoolGuild extends Structures.get('Guild') {
* constructor(client, data) {
* super(client, data);
* this.cool = true;
* }
* }
*
* Structures.set('Guild', CoolGuild);
* Allows for the extension of built-in Discord.js structures that are instantiated by {@link DataStore DataStores}.
*/
class Structures {
constructor() {
@ -9622,21 +9609,41 @@ class Structures {
}
/**
* Retrieves a structure class.
* @param {string} name Name of the base structure
* @returns {Function}
* Extends a structure.
* @param {string} name Name of the structure class to extend
* @param {Function} extender Function that takes the base class to extend as its only parameter and returns the
* extended class/prototype
* @returns {Function} Extended class/prototype returned from the extender
* @example
* const { Structures } = require('discord.js');
*
* Structures.extend('Guild', Guild =>
* class CoolGuild extends Guild {
* constructor(client, data) {
* super(client, data);
* this.cool = true;
* }
* }
* );
*/
static get(name) {
return structures[name];
}
extend(name, extender) {
if (!structures[name]) throw new RangeError(`"${name}" is not a valid extensible structure.`);
if (typeof extender !== 'function') {
throw new TypeError('The extender must be a function that returns the extended class.');
}
const custom = extender(structures[name]);
if (typeof custom !== 'function') {
throw new TypeError('The extender function should return the extended class/prototype.');
}
if (Object.getPrototypeOf(custom) !== structures[name]) {
throw new Error(
'The class/prototype returned from the extender function must extend the existing structure class/prototype.'
);
}
/**
* Overrides a structure class.
* @param {string} name Name of the base structure
* @param {Function} custom Extended structure class to override with
*/
static set(name, custom) {
structures[name] = custom;
return custom;
}
}

File diff suppressed because one or more lines are too long