Prioritize offline delete over offline edit

Hello Everyone!

Sorry, for the noob question, but I just started trying to implement YJS in my project and was having some questions.
I tried searching this in other questions but couldn’t find an answer.

I created an editable list and added a button to connect/disconnect to the y-websocket provider to test losing connection. When I delete an item while disconnected and another user edits that item at the same time, the moment I come back online the item reappears. It does not matter in what order the changes are made.
Is there a way to prioritise the changes made by the user that went offline?
If not, how could I prioritise latests changes? If the item is deleted while offline after someone else edits it, I think the item should be deleted for everyone.

Thanks!

Hi, welcome.

What shared type are you using to store the editable list? If you are using a Y.Array, try using a Y.Map instead, where each item is keyed by a uuid.

Hi, thanks for your answer!

I already tried with both actually. I created 2 lists, one using Y.array and the other using Y.Map, so I can see how they work and how I can manipulate each of them.

Hmmm I’m not sure then. It’s not possible to alter the conflict resolution algorithm, which uses an arbitrary but deterministic priority based on clientID.

You could try marking deleted items and then hiding them in the UI rather than actually deleting them. Of course then you don’t get the benefits of garbage collection, so that doesn’t seem right.

1 Like

@raine
Thanks for your help.

Do you know if we can add a parentSub value or any other information to the structs array that comes from getting the Y.decodeUpdate() function?
I’m trying to create a merge conflicts resolution where, if a user goes offline and comes back, before applying all the updates, the offline user can choose what updates to apply if there are any conflicts. The problem is that the only information I get from the struct content is an array with the value changed, but I have no way to get where was that value changed.

Fo now, in my Y.Doc I’m using a Y.Map() with a uuid as a key and a value of Y.Map().
When I change one of the values of the ‘sub-map’, I only get the updated value, for example ‘false’
I would like to know if there is a way I can get the key of that value changed and the key of the top Map (in my case the uuid).

Try observeDeep. You should be able to get the changed map and key from the event object.

1 Like