Update floCloudAPI.js

This commit is contained in:
sairajzero 2022-11-06 04:28:21 +05:30
parent 0c85e55c20
commit c745f17afb

View File

@ -1,4 +1,4 @@
(function(EXPORTS) { //floCloudAPI v2.4.2e
(function (EXPORTS) { //floCloudAPI v2.4.3
/* FLO Cloud operations to send/request application data*/
'use strict';
const floCloudAPI = EXPORTS;
@ -986,23 +986,23 @@
}, {});
};
const mergeRecursive = (obj1, obj2) => {
const mergeRecursive = (obj1, obj2, deleteMode = false) => {
for (var p in obj2) {
try {
if (obj2[p].constructor == Object)
obj1[p] = mergeRecursive(obj1[p], obj2[p]);
obj1[p] = mergeRecursive(obj1[p], obj2[p], deleteMode);
// Property in destination object set; update its value.
else if (Ext.isArray(obj2[p])) {
else if (Array.isArray(obj2[p])) {
// obj1[p] = [];
if (obj2[p].length < 1)
obj1[p] = obj2[p];
else
obj1[p] = mergeRecursive(obj1[p], obj2[p]);
obj1[p] = mergeRecursive(obj1[p], obj2[p], deleteMode);
} else
obj1[p] = obj2[p];
obj1[p] = deleteMode && obj2[p] === null ? undefined : obj2[p];
} catch (e) {
// Property in destination object not set; create it and set its value.
obj1[p] = obj2[p];
obj1[p] = deleteMode && obj2[p] === null ? undefined : obj2[p];
}
}
return obj1;
@ -1011,20 +1011,13 @@
const cleanse = (obj) => {
Object.keys(obj).forEach(key => {
var value = obj[key];
if (typeof value === "object" && value !== null) {
// Recurse...
cleanse(value);
// ...and remove if now "empty" (NOTE: insert your definition of "empty" here)
//if (!Object.keys(value).length)
// delete obj[key];
} else if (value === null)
delete obj[key]; // null, remove it
if (typeof value === "object" && value !== null)
obj[key] = cleanse(value);
else if (typeof value === 'undefined')
delete obj[key]; // undefined, remove it
});
if (obj.constructor.toString().indexOf("Array") != -1) {
obj = obj.filter(function(el) {
return el != null;
});
}
if (Array.isArray(obj))
obj = obj.filter(v => typeof v !== 'undefined');
return obj;
}
@ -1040,7 +1033,7 @@
if (Object.keys(diff.updated).length !== 0)
obj = mergeRecursive(obj, diff.updated)
if (Object.keys(diff.deleted).length !== 0) {
obj = mergeRecursive(obj, diff.deleted)
obj = mergeRecursive(obj, diff.deleted, true)
obj = cleanse(obj)
}
if (Object.keys(diff.added).length !== 0)