Extract some common Yjs code into Vault class

This commit is contained in:
2025-09-07 00:02:24 -07:00
parent 77d04c99a0
commit d65d1307e2
4 changed files with 36 additions and 8 deletions
+3 -2
View File
@@ -2,6 +2,7 @@ import _ from 'lodash';
import * as Y from 'yjs';
import { openDB } from 'idb';
import { generateId } from './util';
import { Vault } from './vault';
const DB_NAME = 'synced-docs';
const LOCAL_UPDATE_STORE = 'local-updates';
@@ -95,12 +96,12 @@ async function getOrCreateVaultDoc() {
if (!vaultMap.has('docs')) {
vaultMap.set('docs', new Y.Map());
}
return vault;
return new Vault(vault);
}
export const defaultVault = await getOrCreateVaultDoc();
const docsMap = defaultVault.doc.getMap().get('docs') as Y.Map<any>;
const docsMap = defaultVault.getDocsMap();
if (docsMap.size === 0) {
console.log('Running vault migration...');
for (const oldKey of ['foo', 'bar', 'baz']) {