mirror of
https://github.com/danbulant/discord.js
synced 2026-06-05 07:42:09 +00:00
fix(BaseManager): BaseManager#valueOf should return cache (#3776)
* BaseManager#valueOf should return cache * Update Util#flatten to handle valueOf being a Collection * Update Util.js - typo Co-Authored-By: Amish Shah <amishshah.2k@gmail.com> Co-authored-by: Amish Shah <amishshah.2k@gmail.com>
This commit is contained in:
parent
592021df92
commit
62b227c2bd
2 changed files with 7 additions and 1 deletions
|
|
@ -72,6 +72,10 @@ class BaseManager {
|
||||||
if (typeof idOrInstance === 'string') return idOrInstance;
|
if (typeof idOrInstance === 'string') return idOrInstance;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
valueOf() {
|
||||||
|
return this.cache;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = BaseManager;
|
module.exports = BaseManager;
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,10 @@ class Util {
|
||||||
const elemIsObj = isObject(element);
|
const elemIsObj = isObject(element);
|
||||||
const valueOf = elemIsObj && typeof element.valueOf === 'function' ? element.valueOf() : null;
|
const valueOf = elemIsObj && typeof element.valueOf === 'function' ? element.valueOf() : null;
|
||||||
|
|
||||||
// If it's a collection, make the array of keys
|
// If it's a Collection, make the array of keys
|
||||||
if (element instanceof require('./Collection')) out[newProp] = Array.from(element.keys());
|
if (element instanceof require('./Collection')) out[newProp] = Array.from(element.keys());
|
||||||
|
// If the valueOf is a Collection, use its array of keys
|
||||||
|
else if (valueOf instanceof require('./Collection')) out[newProp] = Array.from(valueOf.keys());
|
||||||
// If it's an array, flatten each element
|
// If it's an array, flatten each element
|
||||||
else if (Array.isArray(element)) out[newProp] = element.map(e => Util.flatten(e));
|
else if (Array.isArray(element)) out[newProp] = element.map(e => Util.flatten(e));
|
||||||
// If it's an object with a primitive `valueOf`, use that value
|
// If it's an object with a primitive `valueOf`, use that value
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue