From dacfdfa57f16cd90c907e6490675af65f22d87af Mon Sep 17 00:00:00 2001 From: alt0 Date: Mon, 9 Jan 2023 17:15:19 +0800 Subject: [PATCH] refactor: remove unused files --- .../src/provider/{ => local}/indexeddb.ts | 0 .../data-center/src/provider/local/local.ts | 2 +- .../src/workspaces/workspaces.ts.bak | 101 ------------------ 3 files changed, 1 insertion(+), 102 deletions(-) rename packages/data-center/src/provider/{ => local}/indexeddb.ts (100%) delete mode 100644 packages/data-center/src/workspaces/workspaces.ts.bak diff --git a/packages/data-center/src/provider/indexeddb.ts b/packages/data-center/src/provider/local/indexeddb.ts similarity index 100% rename from packages/data-center/src/provider/indexeddb.ts rename to packages/data-center/src/provider/local/indexeddb.ts diff --git a/packages/data-center/src/provider/local/local.ts b/packages/data-center/src/provider/local/local.ts index 10df43148..82ffe7774 100644 --- a/packages/data-center/src/provider/local/local.ts +++ b/packages/data-center/src/provider/local/local.ts @@ -3,7 +3,7 @@ import type { ProviderConstructorParams } from '../base'; import { varStorage as storage } from 'lib0/storage'; import { Workspace as WS, WorkspaceMeta } from '../../types'; import { Workspace, uuidv4 } from '@blocksuite/store'; -import { IndexedDBProvider } from '../indexeddb.js'; +import { IndexedDBProvider } from './indexeddb.js'; import assert from 'assert'; import { getDefaultHeadImgBlob } from '../../utils/index.js'; diff --git a/packages/data-center/src/workspaces/workspaces.ts.bak b/packages/data-center/src/workspaces/workspaces.ts.bak deleted file mode 100644 index f813f6b16..000000000 --- a/packages/data-center/src/workspaces/workspaces.ts.bak +++ /dev/null @@ -1,101 +0,0 @@ -import { Workspace as WS } from '../types'; - -import { Observable } from 'lib0/observable'; -import { uuidv4 } from '@blocksuite/store'; -import { DataCenter } from '../datacenter'; - -export class Workspaces extends Observable { - private _workspaces: WS[]; - private readonly _dc: DataCenter; - - constructor(dc: DataCenter) { - super(); - this._workspaces = []; - this._dc = dc; - } - - public init() { - this._loadWorkspaces(); - } - - get workspaces() { - return this._workspaces; - } - - /** - * emit when workspaces changed - * @param {(workspace: WS[]) => void} cb - */ - onWorkspacesChange(cb: (workspace: WS[]) => void) { - this.on('change', cb); - } - - private async _loadWorkspaces() { - const providers = this._dc.providers; - let workspaces: WS[] = []; - providers.forEach(async p => { - const pWorkspaces = await p.loadWorkspaces(); - workspaces = [...workspaces, ...pWorkspaces]; - this._updateWorkspaces([...workspaces, ...pWorkspaces]); - }); - } - - /** - * focus load all workspaces list - */ - public async refreshWorkspaces() { - this._loadWorkspaces(); - } - - private _updateWorkspaces(workspaces: WS[]) { - this._workspaces = workspaces; - this.emit('change', this._workspaces); - } - - private _getDefaultWorkspace(name: string): WS { - return { - name, - id: uuidv4(), - isPublish: false, - avatar: '', - owner: undefined, - isLocal: true, - memberCount: 1, - provider: 'local', - }; - } - - /** add a local workspaces */ - public addLocalWorkspace(name: string) { - const workspace = this._getDefaultWorkspace(name); - this._updateWorkspaces([...this._workspaces, workspace]); - return workspace; - } - - /** delete a workspaces by id */ - public delete(id: string) { - const index = this._workspaces.findIndex(w => w.id === id); - if (index >= 0) { - this._workspaces.splice(index, 1); - this._updateWorkspaces(this._workspaces); - } - } - - /** get workspace info by id */ - public getWorkspace(id: string) { - return this._workspaces.find(w => w.id === id); - } - - /** check if workspace exists */ - public hasWorkspace(id: string) { - return this._workspaces.some(w => w.id === id); - } - - public updateWorkspaceInfo(id: string, info: Partial) { - const index = this._workspaces.findIndex(w => w.id === id); - if (index >= 0) { - this._workspaces[index] = { ...this._workspaces[index], ...info }; - this._updateWorkspaces(this._workspaces); - } - } -}