[Feature] Diff apply only added/updated?
joezappie opened this issue · 2 comments
I have a scenario where sometimes I want object diff to be considered as the whole object, and sometimes just as a partial object. When applying a partial object, if an existing key isn't provided I want it to just leave it as is. A deep merge option built in could be nice and is I believe can be done very simply.
The way I'm handling this now is after doing a diff, I'm looping through the changes and removing any remove operation:
let changes = diff(this.data, data);
if (merge) {
changes = changes.filter((change) => change.op === 'remove');
}
diffApply(this.data, changes);
For big objects, performance could benefit from this being built in where either diff optionally doesnt include remove operations or when doing diffApply it optionally skips the removals.
diff(original, changed, { partial: true });
diffApply(obj, changes, { merge: true});
Looking through the documentation, I don't believe this is currently possible.
I think this is a good idea but in the spirit of Just maybe should be a separate util. Something like just-diff-new
I think that makes sense to make keep them separate rather than have a configuration option as you suggested.