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

Also return original values for deleted and updated? Feature request. #77

Open
seanonthenet opened this issue Feb 23, 2022 · 3 comments

Comments

@seanonthenet
Copy link

seanonthenet commented Feb 23, 2022

Hi Matt. Great package thanks.

Would you be able to create versions of deletedDiff, updatedDiff, detailedDiff or have them accept an optional shouldShowOriginal argument to also return the original values too? Eg:

const lhs = {
  foo: {
    bar: {
      a: ['a', 'b'],
      b: 2,
      c: ['x', 'y'],
      e: 100 // deleted
    }
  },
  buzz: 'world'
};

const rhs = {
  foo: {
    bar: {
      a: ['a'], // index 1 ('b')  deleted
      b: 2, // unchanged
      c: ['x', 'y', 'z'], // 'z' added
      d: 'Hello, world!' // added
    }
  },
  buzz: 'fizz' // updated
};

console.log(detailedDiff(lhs, rhs, true));

/*
{
  added: {
    foo: {
      bar: {
        c: {
          '2': 'z'
        },
        d: 'Hello, world!'
      }
    }
  },
  deleted: {
    foo: {
      bar: {
        a: {
          '1': undefined
        },
        e: undefined
      }
    }
  },
  deletedOriginal: {
    foo: {
      bar: {
        a: ['a', 'b'],
        e: 100
      }
    }
  },
  updated: {
    buzz: 'fizz'
  }
  updatedOriginal: {
    buzz: 'world'
  }
}
*/

Obviously just showing detailedDiff implementation but would be same for deletedDiff, updatedDiff.

Thanks.
Sean

@guillett
Copy link

guillett commented Oct 4, 2022

@seanonthenet did you find a workaround or another package? I would like a similar feature. Thanks.

@seanonthenet
Copy link
Author

@guillett sorry, no

@TurningTide
Copy link

@guillett, @seanonthenet
as a dirty workaround:

let results = datailedDiff(oldItem, newItem);
results.deletedOriginal = deletedDiff(results.deleted, oldItem);
results.updatedOriginal = updatedDiff(results.updated, oldItem);

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

No branches or pull requests

3 participants