In observeDeep, can I learn about what was deleted?


I’m trying to use observeDeep() to synchronize our view model with our yjs document.

In our document, we have a Y.Array of Y.Map. When a Y.Map is deleted from the Y.Array, I want to delete the corresponding objects in our view model.

I know I can use the event.changes.deleted to get a list of items deleted from the Y.Array, and that I can do a item.content.getContent() to get to the Y.Map instance that was removed.

My problem is, I want to be able to do a Y.Map.get(“_id”) field of the Y.Map so I can correlate it against our view model.

Unfortunately, since the Y.Map is no longer a member of the Y.Doc, I can’t read any of its fields.

Is there any work around to be able to identify which Y.Map was deleted?

Thank you!


It looks like I can do something like the below, but seems a bit fragile?

If order doesn’t matter, you could model it as a Y.Map of Y.Map. Then you would have access to the deleted id through event.changes.keys.

It’s unfortunate that you have to do a workaround rather than the yarray observe just passing the deleted values.

Thank you for replying!

In this case, order does matter, but your suggestion is great and one, and one that I’m using already in the case of Y.Maps of Y.Maps.