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
+17
-2
+17
-2
@@ -61,6 +61,16 @@ function computeHash() {
|
||||
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) {
|
||||
if (!nextRefresh)
|
||||
@@ -99,12 +109,17 @@ function refresh(callback) {
|
||||
return counter = 0;
|
||||
}
|
||||
|
||||
objects = objects.map(obj => {
|
||||
// Flatten object
|
||||
obj = flattenObject(obj);
|
||||
|
||||
// If no keys are defined, consider all parameters as keys to keep the
|
||||
// same behavior from v1.0
|
||||
for (let obj of objects) {
|
||||
if (!obj["_keys"] || !obj["_keys"].length)
|
||||
obj["_keys"] = Object.keys(obj).filter(k => !k.startsWith("_"));
|
||||
}
|
||||
|
||||
return obj
|
||||
})
|
||||
|
||||
res.sort((a, b) => {
|
||||
if (a.weight === b.weight)
|
||||
|
||||
Reference in new issue
Block a user