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?
I faced the same exact issue re. Y.Array of Y.Map and need to get YMap on delete. As @dmonad has pointed out no data is kept that enables this. An approach like yours does work, however as it is undocumented and unsupported it isn’t a route I want to take.
In then end I’m used pEvent inside the observerDeep() Y.Map event handler to wait for the Y.Array delete event and when pEvent() resolves I still have access to the Y.Map item. Problem solved.
pEvent() has been a life saver for me in async situations like this. HTH.