Closed vincent911001 closed 2 years ago
Hi and welcome!
The way to go is indeed to register an update listener, and persist those updates to a database (perhaps batched, depending on how often updates happen). This thread can help you to determine whether an update was local or not: https://discuss.yjs.dev/t/determining-whether-a-transaction-is-local/361.
However, I'd recommend registering a sync provider that's specialized in persisting updates to a backend. Examples of these are Hocuspocus, y-redis , or y-websocket.
Hi Yousef,
Good day,
Is it possible for you to give me some pointers around document updates in SyncedStore for persistence?
Currently, I am thinking of computing the the diff of YDoc by getting the previous state before editing and current state after editing. The diff will then be persisted to database for future retrieval.
However, the diff have to happen in every functions that are going to be used for editing.
The second option is to listen for the
update
event on YDoc:FYI, the connection provider is WebRTCProvider. Thus, if I am able to determine origin, I could persist the updates to database if the updates happens locally. Is there a way to get to know the origin to differentiate oneself from other peers?
The document updates would then be retrieved from database and merged locally in each of the clients if needed.
Can I know whether my understanding and ideas is correct?
Thanks, Vincent