From f8d845cede7e147bb619f8945bfb4c87c07b29ef Mon Sep 17 00:00:00 2001 From: Yotam Mann Date: Fri, 19 Jul 2019 11:09:28 -0400 Subject: [PATCH] return from 'get' should be serializable --- Tone/core/context/ToneWithContext.ts | 29 +++++++++------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/Tone/core/context/ToneWithContext.ts b/Tone/core/context/ToneWithContext.ts index ee7885b7..94f85984 100644 --- a/Tone/core/context/ToneWithContext.ts +++ b/Tone/core/context/ToneWithContext.ts @@ -6,7 +6,7 @@ import { TransportTimeClass } from "../type/TransportTime"; import "../type/Units"; import { getDefaultsFromInstance, omitFromObject, optionsFromArguments } from "../util/Defaults"; import { RecursivePartial } from "../util/Interface"; -import { isDefined, isUndef } from "../util/TypeCheck"; +import { isArray, isDefined, isNumber, isString, isUndef } from "../util/TypeCheck"; import { Context } from "./Context"; /** @@ -101,22 +101,10 @@ export abstract class ToneWithContext ex /////////////////////////////////////////////////////////////////////////// /** - * Get the object's attributes. Given no arguments get - * will return all available object properties and their corresponding - * values. Pass in a single attribute to retrieve or an array - * of attributes. The attribute strings can also include a "." - * to access deeper properties. - * @param params the parameters to get, otherwise will return all available. + * Get the object's attributes. * @example * osc.get(); * //returns {"type" : "sine", "frequency" : 440, ...etc} - * @example - * osc.get("type"); - * //returns { "type" : "sine"} - * @example - * //use dot notation to access deep properties - * synth.get(["envelope.attack", "envelope.release"]); - * //returns {"envelope" : {"attack" : 0.2, "release" : 0.4}} */ get(): Options { const defaults = getDefaultsFromInstance(this) as Options; @@ -126,16 +114,17 @@ export abstract class ToneWithContext ex if (isDefined(member) && isDefined(member.value) && isDefined(member.setValueAtTime)) { defaults[attribute] = member.value; } else if (member instanceof ToneWithContext) { - const attributes = member.get(); - // merge only the attributes that are in the defaults - Object.keys(defaults[attribute]).forEach(key => { - defaults[attribute][key] = attributes[key]; - }); - } else { + defaults[attribute] = member.get(); + // otherwise make sure it's a serializable type + } else if (isArray(member) || isNumber(member) || isString(member)) { defaults[attribute] = member; + } else { + // remove all undefined and unserializable attributes + delete defaults[attribute]; } } }); + return defaults; }