deep-object-diff icon indicating copy to clipboard operation
deep-object-diff copied to clipboard

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

Open seanonthenet opened this issue 3 years ago • 3 comments

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

seanonthenet avatar Feb 23 '22 13:02 seanonthenet

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

guillett avatar Oct 04 '22 22:10 guillett

@guillett sorry, no

seanonthenet avatar Oct 04 '22 22:10 seanonthenet

@guillett, @seanonthenet as a dirty workaround:

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

TurningTide avatar Nov 24 '22 10:11 TurningTide