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

FeatureRequest: change the diff of array elements (or add such an option) #78

Closed
zatziky opened this issue Sep 8, 2016 · 3 comments
Closed

Comments

@zatziky
Copy link

zatziky commented Sep 8, 2016

For our auditing system we needed to persist the whole array element
and not just the difference.

The object difference for

const objA = {array: [{a: 1}]};
const objB = {array: [{a: 2}]};

would look in the original deep-diff like:

[{
  kind: "E",
  lhs: 1,
  rhs: 2,
  path: ["array", 0, "a"]
}]

Our need is that the result keeps the original and changed elements. It also has the kind as A and changes the structure a bit:

[{
   kind: "A",
   path: ["array", 0],
   item: {
       kind: "E",
       path: ["a"],
       elementLeft: {a: 1},
       elementRight: {a: 2},
       lhs: 1,
       rhs: 2
   }
}]

You could add an option to change the default behavior so that it creates diffs of edited array elements in the proposed manner. I've made a small project deepdiff-keep-element where you can check our intentions in tests.

@flitbit
Copy link
Collaborator

flitbit commented Apr 25, 2017

I like the proposal, it basically rolls up (or short-circuits) the changes for each array element. I can see that this may be handy for some use cases. I also like the ramda library you're using - very cool. I try not to use any dependencies at all, that's why the code is so long-winded.

Here's my take: some use cases may benefit from different difference-reporting structures, therefore, it would be nice if deep-diff had a pluggable difference-reporting mechanism.

With such a mechanism, many implementations are possible, including mine (default) and yours.

@TheScree
Copy link

I'd second implementation of this suggestion, I've found myself needing to know which elements inside an object's attribute (which happens to be an array of values) has changed.

Array parsing feels important to be honest. You aren't just telling users that a difference existed, you've taken the steps to list out exactly what changed. I'd like to see this library fully embrace that role.

@flitbit
Copy link
Collaborator

flitbit commented Feb 26, 2018

This issue has changed as the structure of the differences has changed. I added an issue-78 which shows an easy, user implemented solution using JSON-Pointers.

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