Skip to content

Basic diffing broken #38

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

Closed
nhandyal opened this issue Jul 26, 2018 · 1 comment
Closed

Basic diffing broken #38

nhandyal opened this issue Jul 26, 2018 · 1 comment

Comments

@nhandyal
Copy link

Description
Basic diff functionality seems to be broken.

const detailedDiff = require("deep-object-diff").detailedDiff;

const lhs = {
  'a': 1,
  'b': 2
};

const rhs = {
  'a': 1
};

diff = detailedDiff(lhs, rhs);
console.log(JSON.stringify(diff, null, 2));
// Expected
{
  "added": {},
  "deleted": {
    "b": 2
  },
  "updated": {}
}
// Actual
{
  "added": {},
  "deleted": {},
  "updated": {}
}

https://repl.it/repls/ThankfulFumblingOpenlook

@mattphillips
Copy link
Owner

Hey @nhandyal the problem you are seeing is because of JSON.stringify which strips out any undefined values.

undefined is used to represent the value that has been deleted, or rather is now undefined.

If you try this it should work as expected:

const detailedDiff = require("deep-object-diff").detailedDiff;

const lhs = {
  'a': 1,
  'b': 2
};

const rhs = {
  'a': 1
};

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

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

2 participants