json0-ot-diff icon indicating copy to clipboard operation
json0-ot-diff copied to clipboard

Could support object array item move?

Open bakso opened this issue 1 year ago • 4 comments

Every item has an uuid, like

[{ id: 1 }, { id: 2 }, { id: 3 } ]

if move item idx.3 to idx.2 ,then looks like:

[{ id: 1 }, { id: 3 }, { id: 2 } ]

diff should produce

[ [ 1, { p: 0 } ], [ 2, { d: 0 } ] ]

and:

{ 
  a: [{ id: 1 }, { id: 2 }, { id: 3 }],
  b: [{ id: 4 }]
}

move a.idx2 to b, just like:

{
  a: [{ id: 1 }, { id: 3 }],
  b: [{ id: 2 }, { id: 4 }]
}

diff should produce

[ [ 'a', 1, { p: 0 } ], [ 'b', 0, { d: 0 } ] ]

bakso avatar Nov 21 '23 03:11 bakso

Awesome! Would you be able to add a failing unit test? That would help immensely in implementing this.

curran avatar Nov 21 '23 17:11 curran

Awesome! Would you be able to add a failing unit test? That would help immensely in implementing this.

I think first diff api should support a parameters to specifiy which key is uuid, am i right?

bakso avatar Nov 22 '23 13:11 bakso

just like https://github.com/benjamine/jsondiffpatch which support objectHash function parameter

bakso avatar Nov 23 '23 13:11 bakso

I suppose that API definition could come from the unit test. I like test-driven development, where first we show what we want to invocation to look like, then build support for that test.

curran avatar Nov 25 '23 02:11 curran