update
This commit is contained in:
@@ -73,17 +73,25 @@ class ConfigUtils {
|
||||
return updatedConfig;
|
||||
}
|
||||
|
||||
_isPlainObject(value) {
|
||||
return Object.prototype.toString.call(value) === '[object Object]';
|
||||
}
|
||||
|
||||
// loop through objects and merge them obj1 will be updated with obj2 values
|
||||
mergeObjects(obj1, obj2) {
|
||||
for (let key in obj2) {
|
||||
if (obj2.hasOwnProperty(key)) {
|
||||
if (typeof obj2[key] === 'object') {
|
||||
if (!obj1[key]) {
|
||||
const nextValue = obj2[key];
|
||||
|
||||
if (Array.isArray(nextValue)) {
|
||||
obj1[key] = [...nextValue];
|
||||
} else if (this._isPlainObject(nextValue)) {
|
||||
if (!this._isPlainObject(obj1[key])) {
|
||||
obj1[key] = {};
|
||||
}
|
||||
this.mergeObjects(obj1[key], obj2[key]);
|
||||
this.mergeObjects(obj1[key], nextValue);
|
||||
} else {
|
||||
obj1[key] = obj2[key];
|
||||
obj1[key] = nextValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user