Looking for a better approach to updating the children's of an object using another object which contain the updated values / new entries.
Here param "pObj" is an object which already some children's, just want to update the pObj with the latest values which available in param "data".
Below code, I was using the Kinvey serverless cloud platform. "Object.children" which is not supported by Kinvey - not clear about the reason.
Below code is working fine for me, but it looks little ugly also fixed depth too.
function mergeObjects(pObj, data) {
var tempObj = {};
if (pObj) {
tempObj = pObj;
}
if (typeof(data) == "object") {
for (var j in data) {
if (!tempObj[j]) {
tempObj[j] = {};
}
if (typeof(data[j]) == "object") {
for (var k in data[j]) {
if (!tempObj[j][k]) {
tempObj[j][k] = {};
}
if (typeof(data[j][k]) == "object") {
for (var l in data[j][k]) {
if (!tempObj[j][k][l]) {
tempObj[j][k][l] = {};
}
tempObj[j][k][l] = data[j][k][l];
}
} else {
tempObj[j][k] = data[j][k];
}
}
} else {
tempObj[j] = data[j];
}
}
}
return tempObj;
}
Kinvey legacy BL uses node 0.10, might this be the reason you cannot use Object.children?
It does support lodash, however, so maybe there's Object manipulation options in the lodash module that you can use instead.
As an alternative, you can check out the new Flex Services, a microservices layer that uses node6. It allows you to inline any npm module you want and deploy a whole node.js runtime into our FSR runtime.