Moving elements in lists

I’m unclear if it is necessary to represent move operations in the event system. I need to be sure that the move semantic that is implemented is robust and can actually do everything that is needed. Move semantic brings in extra complexity as the way I see it now, simple move semantics can easily be implemented using the approach I highlighted before.

Yjs’s arrays have stricter semantics than the fractional indexing implementation. In particular, Y.Arrays do not suffer from interleaving. So this is not an option for Yjs in particular.

Of course, you can represent the array as a map and then convert the map to an array using some kind of sort on the data. This is basically the approach I laid out in the bottom of my answer Moving elements in lists

I suggest not to use maps as the top-level data structure. Deleted properties will always take up space (the key-name can’t be removed). When you store the data in a Y.Array, you can delete data very efficiently.

I’m actually planning a Y.Set implementation for exactly for this use-case. This would allow to implement efficient move-semantics using a sort algorithm on the data.

4 Likes