Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (changeInArrayElement) {
_.set(
customConfig,
clonedPath,
_.get(unifiedNewConfig, clonedPath, {})
);
} else if (changeInDeepObject) {
// Remove last item in path to get index of object in array
clonedPath.splice(-1, 1);
_.set(
customConfig,
clonedPath,
_.get(unifiedNewConfig, clonedPath, {})
);
}
applyChange(customConfig, json, d);
});
if (changeInArrayElement) {
_.set(
customConfig,
clonedPath,
_.get(unifiedNewConfig, clonedPath, {})
);
} else if (changeInDeepObject) {
// Remove last item in path to get index of object in array
clonedPath.splice(-1, 1);
_.set(
customConfig,
clonedPath,
_.get(unifiedNewConfig, clonedPath, {})
);
}
applyChange(customConfig, json, d);
});
observableDiff(from, to, (diff) => {
// diff.path looks like ['Common', 'VLAN', 'myVlan'], for example
if (this.classesOfTruth.indexOf(diff.path[1]) !== -1) {
applyChange(from, to, diff);
// the item at index 1 is the name of the class in the schema
// if these are named objects (vlans, for example) the name is at
// index 2
const schemaClass = diff.path[1];
let objectName;
if (this.namelessClasses.indexOf(schemaClass) === -1) {
objectName = diff.path[2];
}
// For additions of named classes, the object name will be in the rhs object
if (!objectName && diff.rhs) {
objectName = Object.keys(diff.rhs)[0];
}
if (updatedClasses.indexOf(schemaClass) === -1) {
updatedClasses.push(schemaClass);
redo() {
const lastChange = this._revertStack.pop();
if (lastChange) {
for (let i = 0; i < lastChange.changes.length; i++) {
let change = lastChange.changes[i];
applyChange(change.target, true, change);
}
this._commitStack.push(lastChange);
}
}
observableDiff(original, updated, function(d) {
const entry = d.path[d.path.length - 1]
if (!exclude.includes(entry)) {
applyChange(result, undefined, d)
}
})
if (!extracted) continue;
/** Read the current file */
const file = readFile(fileName);
const fileObj = JSON.parse(file);
const diffArr = DeepDiff(fileObj, extracted);
if (diffArr) {
const lang = `${scope || ''}${fileLang}`;
result[lang] = {
missing: [],
extra: []
};
for (const diff of diffArr) {
if (diff.kind === 'N') {
result[lang].missing.push(diff);
if (addMissing) {
applyChange(fileObj, extracted, diff);
}
} else if (!_prodMode && diff.kind === 'D') {
result[lang].extra.push(diff);
}
}
if (addMissing) {
const json = JSON.stringify(fileObj, null, 2);
/** Write the corrected object to the original file */
fs.writeFileSync(fileName, json, 'utf8');
}
}
}
if (_prodMode) {
return;
}
const diffSchema = changes.reduce((schema, change) => {
diff.applyChange(schema, newDiffableSchema, change)
return schema
}, {})
const schema = fromDiffableSchema(diffSchema)
import deep from 'deep-diff';
const diff = deep.diff
const applyChange = deep.applyChange
export const mergeCtxs = (original, newOnes) => {
if (newOnes.length == 1) return newOnes[0];
let diffs = newOnes
.map(c => diff(original, c))
.reduce((flat, arr) => [].concat(flat, arr), [])
let res = {...original};
diffs
.filter(a => a)
.forEach(d => applyChange(res, true, d))
return res
};