refactor: rename BlocksuiteWorkspace and WorkspaceInfo

This commit is contained in:
alt0
2023-01-09 21:10:04 +08:00
parent 72a39f67c0
commit 0a4a9fcdb1
7 changed files with 60 additions and 53 deletions
@@ -1,25 +1,25 @@
import { Observable } from 'lib0/observable';
import type { Workspace, WorkspaceMeta } from '../types';
import type { WorkspaceInfo, WorkspaceMeta } from '../types';
export interface WorkspacesScope {
get: (workspaceId: string) => Workspace | undefined;
list: () => Workspace[];
add: (workspace: Workspace) => void;
get: (workspaceId: string) => WorkspaceInfo | undefined;
list: () => WorkspaceInfo[];
add: (workspace: WorkspaceInfo) => void;
remove: (workspaceId: string) => boolean;
clear: () => void;
update: (workspaceId: string, workspaceMeta: Partial<WorkspaceMeta>) => void;
}
export interface WorkspacesChangeEvent {
added?: Workspace;
deleted?: Workspace;
updated?: Workspace;
added?: WorkspaceInfo;
deleted?: WorkspaceInfo;
updated?: WorkspaceInfo;
}
export class Workspaces extends Observable<'change'> {
private _workspacesMap = new Map<string, Workspace>();
private _workspacesMap = new Map<string, WorkspaceInfo>();
get workspaces(): Workspace[] {
get workspaces(): WorkspaceInfo[] {
return Array.from(this._workspacesMap.values());
}
@@ -37,7 +37,7 @@ export class Workspaces extends Observable<'change'> {
return this._workspacesMap.get(workspaceId);
};
const add = (workspace: Workspace) => {
const add = (workspace: WorkspaceInfo) => {
if (this._workspacesMap.has(workspace.id)) {
throw new Error(`Duplicate workspace id.`);
}
@@ -105,7 +105,7 @@ export class Workspaces extends Observable<'change'> {
// TODO: need to optimize
const list = () => {
const workspaces: Workspace[] = [];
const workspaces: WorkspaceInfo[] = [];
scopedWorkspaceIds.forEach(id => {
const workspace = this._workspacesMap.get(id);
if (workspace) {