|
|
@@ -54,13 +54,13 @@ class YjsConnectionManager {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const persistedYdoc = await this.mdb.getYDoc(pageId);
|
|
|
+ const persistedYdoc = await this.getPersistedYdoc(pageId);
|
|
|
const persistedStateVector = Y.encodeStateVector(persistedYdoc);
|
|
|
|
|
|
await this.mdb.flushDocument(pageId);
|
|
|
|
|
|
// If no write operation has been performed, insert initial value
|
|
|
- const clientsSize = currentYdoc.store.clients.size;
|
|
|
+ const clientsSize = persistedYdoc.store.clients.size;
|
|
|
if (clientsSize === 0) {
|
|
|
currentYdoc.getText('codemirror').insert(0, initialValue);
|
|
|
}
|
|
|
@@ -103,6 +103,11 @@ class YjsConnectionManager {
|
|
|
return currentYdoc;
|
|
|
}
|
|
|
|
|
|
+ public async getPersistedYdoc(pageId: string): Promise<Y.Doc> {
|
|
|
+ const persistedYdoc = await this.mdb.getYDoc(pageId);
|
|
|
+ return persistedYdoc;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
export const instantiateYjsConnectionManager = (io: Server): YjsConnectionManager => {
|