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

Wrong Output when something is added at front and deleted in between #44

Open
siddharth232 opened this issue Nov 18, 2022 · 0 comments
Open

Comments

@siddharth232
Copy link

const oldValue = [
    {
      Details: [{
        Amount: 100,
        CurrencyCode: 'USD',
        Quantity: 2,
        RegisteredPrice: 20,
        id: 10,
      }],
      Type: 'Variable',
      Product: 'NaN',
      id: 10,
    },
    {
      Details: [{
        Amount: 110,
        CurrencyCode: 'USD',
        Quantity: 16,
        RegisteredPrice: 20,
        id: 20,
      }],
      Type: 'Type-11',
      Product: 'Product-11',
      id: 20,
    },
    {
      Details: [{
        Amount: 120,
        CurrencyCode: 'USD',
        Quantity: 17,
        RegisteredPrice: 20,
        id: 30,
      }],
      Type: 'Type-12',
      Product: 'Product-12',
      id: 30,
    },
  ];
  const newValue = [
    {
      Details: [{
        Amount: 100,
        CurrencyCode: 'USD',
        Quantity: 2,
        RegisteredPrice: 20,
        id: 40,
      }],
      Type: 'Variable',
      Product: 'NaN',
      id: 40,
    },
    {
      Details: [{
        Amount: 100,
        CurrencyCode: 'USD',
        Quantity: 2,
        RegisteredPrice: 20,
        id: 10,
      }],
      Type: 'Variable',
      Product: 'NaN',
      id: 10,
    },
    {
      Details: [{
        Amount: 120,
        CurrencyCode: 'USD',
        Quantity: 17,
        RegisteredPrice: 20,
        id: 30,
      }],
      Type: 'Type-12',
      Product: 'Product-12',
      id: 30,
    },
  ];
function hashFn(x) {
    return x.id;
}
console.log(jiff.diff(oldValue,newValue,{hash: hashFn,invertible:false}));

Output:
[ { op: 'add', path: '/0', value: { Details: [Array], Type: 'Variable', Product: 'NaN', id: 40 }, context: undefined }, { op: 'remove', path: '/2', context: undefined } ]

Expected:
[ { op: 'add', path: '/0', value: { Details: [Array], Type: 'Variable', Product: 'NaN', id: 40 }, context: undefined }, { op: 'remove', path: '/1', context: undefined } ]

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

1 participant