mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Fixing the object diff so it only changes add and changed keys
This commit is contained in:
parent
a7a139ce5a
commit
d9b7b8ed28
2 changed files with 12 additions and 2 deletions
|
@ -49,8 +49,10 @@ define(function (require) {
|
|||
delete target[key];
|
||||
});
|
||||
|
||||
// Assign the source to the target
|
||||
_.assign(target, _.pick(source, sourceKeys));
|
||||
// Assign the changed to the source to the target
|
||||
_.assign(target, _.pick(source, diff.changed));
|
||||
// Assign the added to the source to the target
|
||||
_.assign(target, _.pick(source, diff.added));
|
||||
|
||||
return diff;
|
||||
|
||||
|
|
|
@ -64,5 +64,13 @@ define(function (require) {
|
|||
expect(results.changed).to.be.empty();
|
||||
});
|
||||
|
||||
it('should only change keys that actually changed', function () {
|
||||
var obj = { 'message': 'foo' };
|
||||
var target = { obj: obj, message: 'foo' };
|
||||
var source = { obj: _.cloneDeep(obj), message: 'test' };
|
||||
var results = diff(target, source);
|
||||
expect(target.obj).to.be(obj);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue