mergeDeep added
mergeDeep is the same as Object.assign except it works upon multiple layers of an objectbuild-default-monitor-config-from-definitions
parent
2ad0cae75f
commit
58df790e97
|
@ -48,6 +48,26 @@ switch($user.details.lang){
|
|||
})
|
||||
break;
|
||||
}
|
||||
function isObject(item) {
|
||||
return (item && typeof item === 'object' && !Array.isArray(item));
|
||||
}
|
||||
window.mergeDeep = function(target, ...sources){
|
||||
if (!sources.length) return target;
|
||||
const source = sources.shift();
|
||||
|
||||
if (isObject(target) && isObject(source)) {
|
||||
for (const key in source) {
|
||||
if (isObject(source[key])) {
|
||||
if (!target[key]) Object.assign(target, { [key]: {} });
|
||||
mergeDeep(target[key], source[key]);
|
||||
} else {
|
||||
Object.assign(target, { [key]: source[key] });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mergeDeep(target, ...sources);
|
||||
}
|
||||
window.getApiPrefix = function(){
|
||||
return $.ccio.init('location',$user) + $user.auth_token
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue