refactor: using unified nanoid (#4519)
This commit is contained in:
1 parent
56f75160f3
commit
603f82ffc2
38 files changed
+258
-183
No files matched your search
@@ -9,7 +9,7 @@
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blocksuite/store": "0.0.0-20230921103931-38d8f07a-nightly"
|
||||
"@blocksuite/store": "0.0.0-20230926212737-6d4b1569-nightly"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"yjs": "^13.5.51"
|
||||
|
||||
@@ -97,6 +97,42 @@ export const createLazyProvider = (
|
||||
|
||||
async function syncDoc(doc: Doc) {
|
||||
const guid = doc.guid;
|
||||
{
|
||||
// backport from `@blocksuite/store`
|
||||
const prefixId = guid.startsWith('space:') ? guid.slice(6) : guid;
|
||||
const possible1 = `${rootDoc.guid}:space:${prefixId}`;
|
||||
const possible2 = `space:${prefixId}`;
|
||||
const update1 = await datasource.queryDocState(possible1);
|
||||
const update2 = await datasource.queryDocState(possible2);
|
||||
let hasUpdate = false;
|
||||
if (
|
||||
update1 &&
|
||||
update1.missing.length !== 2 &&
|
||||
update1.missing[0] !== 0 &&
|
||||
update1.missing[1] !== 0
|
||||
) {
|
||||
applyUpdate(doc, update1.missing, origin);
|
||||
hasUpdate = true;
|
||||
}
|
||||
if (
|
||||
update2 &&
|
||||
update2.missing.length !== 2 &&
|
||||
update2.missing[0] !== 0 &&
|
||||
update2.missing[1] !== 0
|
||||
) {
|
||||
applyUpdate(doc, update2.missing, origin);
|
||||
hasUpdate = true;
|
||||
}
|
||||
if (hasUpdate) {
|
||||
await datasource.sendDocUpdate(
|
||||
guid,
|
||||
encodeStateAsUpdate(
|
||||
doc,
|
||||
update1 ? update1.state : update2 ? update2.state : undefined
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!connected) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user