When I undo this change, events are fired, but the content is the new value (i.e. [0, 1.5, 0] on undo). Is there a way to indicate to Yjs that this modification-in-place should be treated as a real change?
I’m trying to avoid javascript garbage collection by avoiding allocating new arrays.
I need to be more explicit about this. You shouldn’t modify objects that you maintain in Yjs. In order to avoid garbage collection, I reuse the values that you put into Yjs. So when you set ymap.set('position', [0, 0 0]), I’m not going to copy [0,0,0] to a new array and maintain that. Because then, I’d also need to create a new instance of [0, 0, 0] every time you retrieve the value.
Since you modified pos[1], the local Yjs instance thinks that the old value is [0, 1.5, 0].
Instead, you should simply copy/slice the position before you modify it. ymap.get('position').slice() // ready to be modified .
Ok, that’s what I suspected. There is no “dirty” flag to set, it’s just a matter of referential equality under the hood, and I’ll need to make copies. Thanks!