flitbit / diff

Javascript utility for calculating deep difference, capturing changes, and applying changes across objects; for nodejs and the browser.
MIT License
2.99k stars 213 forks source link

Unexpected results! #87

Closed ketansp closed 7 years ago

ketansp commented 7 years ago

I am trying to implement this library in my project, but I do not get expected results. Herewith sharing a sample of the data for your understanding

lhs { region: 'string', state: 'string', country: 'string', mdmId: null, isActive: true, createdDate: '2017-01-07T07:30:47.000Z', lastModifiedDate: '2017-01-07T07:37:39.075Z', id: 14 }

rhs { region: 'string', state: 'string', country: 'string', mdmId: null, isActive: true, createdDate: 2017-01-07T07:30:47.000Z, lastModifiedDate: 2017-01-07T07:39:02.072Z, id: 14 }

diff [ DiffDeleted { kind: 'D', path: [ 'region' ], lhs: 'string' }, DiffDeleted { kind: 'D', path: [ 'state' ], lhs: 'string' }, DiffDeleted { kind: 'D', path: [ 'country' ], lhs: 'string' }, DiffDeleted { kind: 'D', path: [ 'mdmId' ], lhs: null }, DiffDeleted { kind: 'D', path: [ 'isActive' ], lhs: true }, DiffDeleted { kind: 'D', path: [ 'createdDate' ], lhs: '2017-01-07T07:30:47.000Z' }, DiffDeleted { kind: 'D', path: [ 'lastModifiedDate' ], lhs: '2017-01-07T07:37:39.075Z' }, DiffDeleted { kind: 'D', path: [ 'id' ], lhs: 14 }, DiffNew { kind: 'N', path: [ '__cachedRelations' ], rhs: {} }, DiffNew { kind: 'N', path: [ '__data' ], rhs: { region: 'string', state: 'string', country: 'string', mdmId: null, isActive: true, createdDate: 2017-01-07T07:30:47.000Z, lastModifiedDate: 2017-01-07T07:39:02.072Z, id: 14 } }, DiffNew { kind: 'N', path: [ '__strict' ], rhs: false }, DiffNew { kind: 'N', path: [ '__persisted' ], rhs: true } ]

Am I missing out on something?

DingoEatingFuzz commented 7 years ago

Formatting this a little better you get this, which tells a story:

[
  DiffDeleted { kind: 'D', path: [ 'region' ], lhs: 'string' },
  DiffDeleted { kind: 'D', path: [ 'state' ], lhs: 'string' },
  DiffDeleted { kind: 'D', path: [ 'country' ], lhs: 'string' },
  DiffDeleted { kind: 'D', path: [ 'mdmId' ], lhs: null },
  DiffDeleted { kind: 'D', path: [ 'isActive' ], lhs: true },
  DiffDeleted { kind: 'D', path: [ 'createdDate' ], lhs: '2017-01-07T07:30:47.000Z' },
  DiffDeleted { kind: 'D', path: [ 'lastModifiedDate' ], lhs: '2017-01-07T07:37:39.075Z' },
  DiffDeleted { kind: 'D', path: [ 'id' ], lhs: 14 },

  DiffNew { kind: 'N', path: [ '__cachedRelations' ], rhs: {} },
  DiffNew { kind: 'N', path: [ '__data' ], rhs: {
    region: 'string',
    state: 'string',
    country: 'string',
    mdmId: null,
    isActive: true,
    createdDate: '2017-01-07T07:30:47.000Z',
    lastModifiedDate: '2017-01-07T07:39:02.072Z',
    id: 14 
  } },
  DiffNew { kind: 'N', path: [ '__strict' ], rhs: false },
  DiffNew { kind: 'N', path: [ '__persisted' ], rhs: true }
]

Looks like you are diffing an object and a wrapper object.

flitbit commented 7 years ago

Take a look at the tests, there is a prefilter option that helps you ignore the state-keeping features of your chosen framework.

Also, reference issue #34 which dealt with the same.