chore: improve docs

This commit is contained in:
DarkSky 2023-01-03 21:03:27 +08:00
parent 2ee99a37fb
commit 4b5e209ecc
3 changed files with 7 additions and 11 deletions

View File

@ -83,7 +83,7 @@ export class DataCenter {
return provider; return provider;
} }
async setConfig(workspace: string, config: Record<string, any>) { private async _setConfig(workspace: string, config: Record<string, any>) {
const values = Object.entries(config); const values = Object.entries(config);
if (values.length) { if (values.length) {
const configure = getKVConfigure(workspace); const configure = getKVConfigure(workspace);
@ -101,7 +101,7 @@ export class DataCenter {
if (!this._workspaces.has(workspaceId)) { if (!this._workspaces.has(workspaceId)) {
this._workspaces.set( this._workspaces.set(
workspaceId, workspaceId,
this.setConfig(workspaceId, config).then(() => this._setConfig(workspaceId, config).then(() =>
this._getWorkspace(workspaceId, providerId) this._getWorkspace(workspaceId, providerId)
) )
); );
@ -122,6 +122,7 @@ export class DataCenter {
} }
} }
// reload new workspace instance to memory to refresh config
async reload( async reload(
workspaceId: string, workspaceId: string,
config: LoadConfig = {} config: LoadConfig = {}

View File

@ -51,9 +51,7 @@ export class AffineProvider extends LocalProvider {
if (this._onTokenRefresh) { if (this._onTokenRefresh) {
token.offChange(this._onTokenRefresh); token.offChange(this._onTokenRefresh);
} }
if (this._ws) { this._ws?.disconnect();
this._ws.disconnect();
}
} }
async initData() { async initData() {
@ -72,9 +70,8 @@ export class AffineProvider extends LocalProvider {
doc.once('update', resolve); doc.once('update', resolve);
applyUpdate(doc, new Uint8Array(updates)); 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 // 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<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {
// TODO: synced will also be triggered on reconnection after losing sync // 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 // There needs to be an event mechanism to emit the synchronization state to the upper layer

View File

@ -36,14 +36,12 @@ export class LocalProvider extends BaseProvider {
async clear() { async clear() {
await super.clear(); await super.clear();
await this._blobs.clear(); await this._blobs.clear();
this._idb?.clearData(); await this._idb?.clearData();
} }
async destroy(): Promise<void> { async destroy(): Promise<void> {
super.destroy(); super.destroy();
if (this._idb) { await this._idb?.destroy();
await this._idb.destroy();
}
} }
async getBlob(id: string): Promise<string | null> { async getBlob(id: string): Promise<string | null> {