Skip to content

Array moves can sometimes be hard to understand #146

@thorning

Description

@thorning

The longest common sequence used in array moves makes some deltas quite confusing to understand.

Take for example a change from [1,2,3] => [3,2,1], which result in the following delta:
{ _t: 'a', _1: [ '', 1, 3 ], _2: [ '', 0, 3 ] }

Here the 1 is not "moved" and the 2 and 3 is "moved" in front of it. This is right, but hard to wrap your head around at first sight.

I made a pullrequst, #145 , that accepts an option to explicitly state all differences between arrays. The above delta will then become
{ _t: 'a', _0: [ '', 2, 3 ], _2: [ '', 0, 3 ] }

The disadvantage is obviously that an insert at the start of the array causes every other element to shift, and results in some rather large deltas.

It might be possible fo add a new delta types for arrays, group-moves, which specifies groups that are moved together. This would mean an insert at the start of an array would have a delta of one insert and one group move.

I have not looked enough through the code to know how much impact this would have on I.e. formaters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions