floCloudAPI v2.4.3
- Fixed a rare bug where array has empty value - now `null` is supported by objectData update (ie, objects can now have null as value)
This commit is contained in:
parent
bffb130bd4
commit
663dfe2d54
@ -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,23 +1011,17 @@
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
const findDiff = (lhs, rhs) => ({
|
||||
added: addedDiff(lhs, rhs),
|
||||
deleted: deletedDiff(lhs, rhs),
|
||||
@ -1039,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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user