y-crdt/ypy

Add `YArray.__set_item__`

davidbrochart opened this issue · 4 comments

It looks like a YArray has a __get_item__ but no __set_item__, which would be useful.

Using __set_item__ isn't possible because a transaction is required to change the YArray. But I could add a method that functionally does the same thing:

y_array.set(txn, index, value)

Currently I'm doing a delete followed by an insert, but yes a set would be a nice one-liner.

Talked about this with @Horusiath and @dmonad. A set operation is slightly different than a get + delete and isn't currently supported by yrs or yjs. Simultaneous set operations create something like a last writer wins relationship, with the new value being mutually exclusive to other concurrent sets. Get + delete allows for both users to add values and those to coexist.

I don't think there's a plan currently to add the set operation into yrs. If there is underlying support for set in the future, I'd definitely add it to the API.

Thanks for the details, closing.