fix: remove usage of mergeUpdates (#3687)

This commit is contained in:
Alex Yang
2023-08-11 02:09:33 -04:00
committed by GitHub
parent 52f01a71d2
commit 42b90e1d8d
8 changed files with 62 additions and 28 deletions
+2 -2
View File
@@ -24,11 +24,11 @@
"jotai": "^2.2.2",
"js-base64": "^3.7.5",
"ky": "^0.33.3",
"lib0": "^0.2.78",
"lib0": "^0.2.80",
"react": "18.2.0",
"react-dom": "18.2.0",
"y-protocols": "^1.0.5",
"yjs": "^13.6.6",
"yjs": "^13.6.7",
"zod": "^3.21.4"
},
"devDependencies": {
+14 -9
View File
@@ -9,7 +9,7 @@ import { Workspace } from '@blocksuite/store';
import { createBroadcastChannelProvider } from '@blocksuite/store/providers/broadcast-channel';
import {
createIndexedDBProvider as create,
downloadBinary,
downloadBinaries,
EarlyDisconnectError,
} from '@toeverything/y-indexeddb';
import type { Doc } from 'yjs';
@@ -61,7 +61,7 @@ const createIndexedDBBackgroundProvider: DocProviderCreator = (
};
};
const cache: WeakMap<Doc, Uint8Array> = new WeakMap();
const cache: WeakMap<Doc, Uint8Array[]> = new WeakMap();
const createIndexedDBDownloadProvider: DocProviderCreator = (
id,
@@ -75,15 +75,20 @@ const createIndexedDBDownloadProvider: DocProviderCreator = (
});
async function downloadBinaryRecursively(doc: Doc) {
if (cache.has(doc)) {
const binary = cache.get(doc) as Uint8Array;
Y.applyUpdate(doc, binary);
} else {
const binary = await downloadBinary(doc.guid);
if (binary) {
const binaries = cache.get(doc) as Uint8Array[];
binaries.forEach(binary => {
Y.applyUpdate(doc, binary);
cache.set(doc, binary);
}
});
return;
}
const binaries = await downloadBinaries(doc.guid);
if (!binaries) {
return;
}
cache.set(doc, binaries);
binaries.forEach(binary => {
Y.applyUpdate(doc, binary);
});
await Promise.all([...doc.subdocs].map(downloadBinaryRecursively));
}
return {