AsyncBanana / microdiff

A fast, zero dependency object and array comparison library. Significantly faster than most other deep comparison libraries and has full TypeScript support.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ineficient change detection

Zombobot1 opened this issue · comments

I need to detect as few changes as possible, however instead of one change I get a couple.

const changes = diff(['0', { a: 1 }], ['0', '1', { a: 1 }])

const expected = [ { type: 'CREATE', path: [ 1 ], value: '1' }]

const actual = [
  { path: [ 1 ], type: 'CHANGE', value: '1', oldValue: { a: 1 } },
  { type: 'CREATE', path: [ 2 ], value: { a: 1 } }
]

Is it expected behaviour? I have to use a double for loop to merge these changes back - that is not good for performance

That is expected behavior. Unfortunately, I do not know of any way to do more advanced array diffing in a performant way. If you have any ideas, feel free to create a PR.