fix: a possible double connect issue (#3552)

This commit is contained in:
Peng Xiao 2023-08-03 21:45:00 +08:00 committed by GitHub
parent 8face25bdf
commit 6f488d963b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -111,8 +111,11 @@ export const createIndexedDBProvider = (
let datasource: ReturnType<typeof createDatasource> | null = null;
let provider: ReturnType<typeof createLazyProvider> | null = null;
return {
const apis = {
connect: () => {
if (apis.connected) {
apis.disconnect();
}
datasource = createDatasource({ dbName, mergeCount });
provider = createLazyProvider(doc, datasource, { origin: 'idb' });
provider.connect();
@ -130,4 +133,6 @@ export const createIndexedDBProvider = (
return provider?.connected || false;
},
};
return apis;
};