Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Diff apply only added/updated? #522

Open
joezappie opened this issue Dec 12, 2022 · 2 comments
Open

[Feature] Diff apply only added/updated? #522

joezappie opened this issue Dec 12, 2022 · 2 comments
Assignees

Comments

@joezappie
Copy link

joezappie commented Dec 12, 2022

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.

@angus-c angus-c self-assigned this Dec 29, 2022
@angus-c
Copy link
Owner

angus-c commented Dec 30, 2022

I think this is a good idea but in the spirit of Just maybe should be a separate util. Something like just-diff-new

@joezappie
Copy link
Author

joezappie commented Jan 2, 2023

I think that makes sense to make keep them separate rather than have a configuration option as you suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants