8000 [Feature] Diff apply only added/updated? · Issue #522 · angus-c/just · GitHub
[go: up one dir, main page]

Skip to content

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

Open

Description

@joezappie

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.

Activity

  1. self-assigned this
    on Dec 29, 2022
  2. angus-c commented on Dec 30, 2022

    @angus-c
    Owner

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

  3. joezappie commented on Jan 2, 2023

    @joezappie
    Author

    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

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    0