mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
62 lines
1.2 KiB
TypeScript
62 lines
1.2 KiB
TypeScript
|
|
|
|
import _deepDiff = require('deep-diff');
|
|
var diff = _deepDiff.diff;
|
|
|
|
var lhs = {
|
|
name: 'my object',
|
|
description: 'it\'s an object!',
|
|
details: {
|
|
it: 'has',
|
|
an: 'array',
|
|
with: ['a', 'few', 'elements']
|
|
}
|
|
};
|
|
|
|
var rhs = {
|
|
name: 'updated object',
|
|
description: 'it\'s an object!',
|
|
details: {
|
|
it: 'has',
|
|
an: 'array',
|
|
with: ['a', 'few', 'more', 'elements', { than: 'before' }]
|
|
}
|
|
};
|
|
|
|
var differences: deepDiff.IDiff[] = diff(lhs, rhs);
|
|
|
|
console.log(differences);
|
|
|
|
|
|
// --------------------------
|
|
|
|
var observableDiff = _deepDiff.observableDiff;
|
|
var applyChange = _deepDiff.applyChange;
|
|
|
|
var lhs = {
|
|
name: 'my object',
|
|
description: 'it\'s an object!',
|
|
details: {
|
|
it: 'has',
|
|
an: 'array',
|
|
with: ['a', 'few', 'elements']
|
|
}
|
|
};
|
|
|
|
var rhs = {
|
|
name: 'updated object',
|
|
description: 'it\'s an object!',
|
|
details: {
|
|
it: 'has',
|
|
an: 'array',
|
|
with: ['a', 'few', 'more', 'elements', { than: 'before' }]
|
|
}
|
|
};
|
|
|
|
observableDiff(lhs, rhs, function (d: deepDiff.IDiff) {
|
|
// Apply all changes except those to the 'name' property...
|
|
if (d.path.length !== 1 || d.path.join('.') !== 'name') {
|
|
applyChange(lhs, rhs, d);
|
|
}
|
|
});
|