From 4b5e209eccf5e9d3d354ada52356203e0399031b Mon Sep 17 00:00:00 2001 From: DarkSky Date: Tue, 3 Jan 2023 21:03:27 +0800 Subject: [PATCH] chore: improve docs --- packages/data-center/src/datacenter.ts | 5 +++-- packages/data-center/src/provider/affine/index.ts | 7 ++----- packages/data-center/src/provider/local/index.ts | 6 ++---- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/data-center/src/datacenter.ts b/packages/data-center/src/datacenter.ts index b43a7c7b61..fc836c19ac 100644 --- a/packages/data-center/src/datacenter.ts +++ b/packages/data-center/src/datacenter.ts @@ -83,7 +83,7 @@ export class DataCenter { return provider; } - async setConfig(workspace: string, config: Record) { + private async _setConfig(workspace: string, config: Record) { const values = Object.entries(config); if (values.length) { const configure = getKVConfigure(workspace); @@ -101,7 +101,7 @@ export class DataCenter { if (!this._workspaces.has(workspaceId)) { this._workspaces.set( workspaceId, - this.setConfig(workspaceId, config).then(() => + this._setConfig(workspaceId, config).then(() => this._getWorkspace(workspaceId, providerId) ) ); @@ -122,6 +122,7 @@ export class DataCenter { } } + // reload new workspace instance to memory to refresh config async reload( workspaceId: string, config: LoadConfig = {} diff --git a/packages/data-center/src/provider/affine/index.ts b/packages/data-center/src/provider/affine/index.ts index e203606d2b..fef7a4d0a9 100644 --- a/packages/data-center/src/provider/affine/index.ts +++ b/packages/data-center/src/provider/affine/index.ts @@ -51,9 +51,7 @@ export class AffineProvider extends LocalProvider { if (this._onTokenRefresh) { token.offChange(this._onTokenRefresh); } - if (this._ws) { - this._ws.disconnect(); - } + this._ws?.disconnect(); } async initData() { @@ -72,9 +70,8 @@ export class AffineProvider extends LocalProvider { doc.once('update', resolve); applyUpdate(doc, new Uint8Array(updates)); }); - // TODO: wait util data loaded - this._ws = new WebsocketProvider('/', workspace.room, doc); // Wait for ws synchronization to complete, otherwise the data will be modified in reverse, which can be optimized later + this._ws = new WebsocketProvider('/', workspace.room, doc); await new Promise((resolve, reject) => { // TODO: synced will also be triggered on reconnection after losing sync // There needs to be an event mechanism to emit the synchronization state to the upper layer diff --git a/packages/data-center/src/provider/local/index.ts b/packages/data-center/src/provider/local/index.ts index 5c3a89f23a..363b50b89e 100644 --- a/packages/data-center/src/provider/local/index.ts +++ b/packages/data-center/src/provider/local/index.ts @@ -36,14 +36,12 @@ export class LocalProvider extends BaseProvider { async clear() { await super.clear(); await this._blobs.clear(); - this._idb?.clearData(); + await this._idb?.clearData(); } async destroy(): Promise { super.destroy(); - if (this._idb) { - await this._idb.destroy(); - } + await this._idb?.destroy(); } async getBlob(id: string): Promise {