From 62b227c2bd194c5a6ed90bf5ca5ff45ecf59bdde Mon Sep 17 00:00:00 2001 From: Ryan Munro Date: Thu, 13 Feb 2020 08:26:17 +1100 Subject: [PATCH] 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 Co-authored-by: Amish Shah --- src/managers/BaseManager.js | 4 ++++ src/util/Util.js | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/managers/BaseManager.js b/src/managers/BaseManager.js index ae07ee62f..ea3717791 100644 --- a/src/managers/BaseManager.js +++ b/src/managers/BaseManager.js @@ -72,6 +72,10 @@ class BaseManager { if (typeof idOrInstance === 'string') return idOrInstance; return null; } + + valueOf() { + return this.cache; + } } module.exports = BaseManager; diff --git a/src/util/Util.js b/src/util/Util.js index da4bff449..4ab518773 100644 --- a/src/util/Util.js +++ b/src/util/Util.js @@ -36,8 +36,10 @@ class Util { const elemIsObj = isObject(element); 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 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 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