Răsfoiți Sursa

impl getPersistedYdoc

Shun Miyazawa 1 an în urmă
părinte
comite
1f3e5046a4
1 a modificat fișierele cu 7 adăugiri și 2 ștergeri
  1. 7 2
      apps/app/src/server/service/yjs-connection-manager.ts

+ 7 - 2
apps/app/src/server/service/yjs-connection-manager.ts

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