Fix instances being created with undefined values
Happens when creating instances using object templates with nested parameters. Resolves: #294
This commit is contained in:
1 parent
d7997988db
commit
e6caa36aa0
1 file changed
+19
-4
+19
-4
@@ -61,6 +61,16 @@ function computeHash() {
|
|||||||
hash = h.digest("hex");
|
hash = h.digest("hex");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function flattenObject(src, prefix = "", dst = {}) {
|
||||||
|
for (let k of Object.keys(src)) {
|
||||||
|
let v = src[k];
|
||||||
|
if (typeof v === "object" && !Array.isArray(v))
|
||||||
|
flattenObject(v, `${prefix}${k}.`, dst);
|
||||||
|
else
|
||||||
|
dst[`${prefix}${k}`] = v;
|
||||||
|
}
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
function refresh(callback) {
|
function refresh(callback) {
|
||||||
if (!nextRefresh)
|
if (!nextRefresh)
|
||||||
@@ -99,12 +109,17 @@ function refresh(callback) {
|
|||||||
return counter = 0;
|
return counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no keys are defined, consider all parameters as keys to keep the
|
objects = objects.map(obj => {
|
||||||
// same behavior from v1.0
|
// Flatten object
|
||||||
for (let obj of objects) {
|
obj = flattenObject(obj);
|
||||||
|
|
||||||
|
// If no keys are defined, consider all parameters as keys to keep the
|
||||||
|
// same behavior from v1.0
|
||||||
if (!obj["_keys"] || !obj["_keys"].length)
|
if (!obj["_keys"] || !obj["_keys"].length)
|
||||||
obj["_keys"] = Object.keys(obj).filter(k => !k.startsWith("_"));
|
obj["_keys"] = Object.keys(obj).filter(k => !k.startsWith("_"));
|
||||||
}
|
|
||||||
|
return obj
|
||||||
|
})
|
||||||
|
|
||||||
res.sort((a, b) => {
|
res.sort((a, b) => {
|
||||||
if (a.weight === b.weight)
|
if (a.weight === b.weight)
|
||||||
|
|||||||
Reference in new issue
Block a user