From 9c242ed1b91cf2e6ec258003ab0f9e49e7d9dedc Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Thu, 25 Jun 2020 15:05:32 +0900 Subject: [PATCH] Psalm config update, add JS object deep copy function --- www/layout/admin/javascript/edit.jq.js | 25 +++++++++++++++++++++++++ www/psalm.xml | 4 +++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/www/layout/admin/javascript/edit.jq.js b/www/layout/admin/javascript/edit.jq.js index c9344b52..bb05fbba 100644 --- a/www/layout/admin/javascript/edit.jq.js +++ b/www/layout/admin/javascript/edit.jq.js @@ -342,6 +342,31 @@ function valueInObject(object, value) // }) ? true : false; } +/** + * true deep copy for Javascript objects + * if Object.assign({}, obj) is not working (shallow) + * or if JSON.parse(JSON.stringify(obj)) is failing + * @param {Object} inObject Object to copy + * @return {Object} Copied Object + */ +function deepCopyFunction(inObject) +{ + var outObject, value, key; + if (typeof inObject !== "object" || inObject === null) { + return inObject; // Return the value if inObject is not an object + } + // Create an array or object to hold the values + outObject = Array.isArray(inObject) ? [] : {}; + // loop over ech entry in object + for (key in inObject) { + value = inObject[key]; + // Recursively (deep) copy for nested objects, including arrays + outObject[key] = deepCopyFunction(value); + } + + return outObject; +} + /** * checks if a DOM element actually exists * @param {String} id Element id to check for diff --git a/www/psalm.xml b/www/psalm.xml index 953246a6..ecb85e0f 100644 --- a/www/psalm.xml +++ b/www/psalm.xml @@ -6,6 +6,7 @@ xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" autoloader="lib/autoloader.php" + errorLevel="8" > @@ -28,7 +29,8 @@ - + +