mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-27 05:33:10 +03:00
refactor: datacenter only export workspaceUnit
This commit is contained in:
parent
122cce042c
commit
db74706eca
@ -100,7 +100,8 @@ export class DataCenter {
|
||||
const workspace = createBlocksuiteWorkspace(workspaceMeta.id);
|
||||
|
||||
await this._mainProvider.createWorkspace(workspace, workspaceMeta);
|
||||
return workspace;
|
||||
const workspaceUnit = this._workspaceUnitCollection.find(workspaceMeta.id);
|
||||
return workspaceUnit;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,18 +155,23 @@ export class DataCenter {
|
||||
* @returns {Promise<BlocksuiteWorkspace>}
|
||||
*/
|
||||
public async loadWorkspace(workspaceId: string) {
|
||||
const workspaceInfo = this._workspaceUnitCollection.find(workspaceId);
|
||||
assert(workspaceInfo, 'Workspace not found');
|
||||
const currentProvider = this.providerMap.get(workspaceInfo.provider);
|
||||
const workspaceUnit = this._workspaceUnitCollection.find(workspaceId);
|
||||
assert(workspaceUnit, 'Workspace not found');
|
||||
const currentProvider = this.providerMap.get(workspaceUnit.provider);
|
||||
if (currentProvider) {
|
||||
currentProvider.closeWorkspace(workspaceId);
|
||||
}
|
||||
const provider = this.providerMap.get(workspaceInfo.provider);
|
||||
assert(provider, `provide '${workspaceInfo.provider}' is not registered`);
|
||||
this._logger(`Loading ${workspaceInfo.provider} workspace: `, workspaceId);
|
||||
const provider = this.providerMap.get(workspaceUnit.provider);
|
||||
assert(provider, `provide '${workspaceUnit.provider}' is not registered`);
|
||||
this._logger(`Loading ${workspaceUnit.provider} workspace: `, workspaceId);
|
||||
const workspace = this._getBlocksuiteWorkspace(workspaceId);
|
||||
this._workspaceInstances.set(workspaceId, workspace);
|
||||
return await provider.warpWorkspace(workspace);
|
||||
await provider.warpWorkspace(workspace);
|
||||
this._workspaceUnitCollection.workspaces.forEach(workspaceUnit => {
|
||||
workspaceUnit.setBlocksuiteWorkspace(null);
|
||||
});
|
||||
workspaceUnit.setBlocksuiteWorkspace(workspace);
|
||||
return workspaceUnit;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,7 +30,7 @@ export class WorkspaceUnit {
|
||||
public provider!: string;
|
||||
public syncMode: 'all' | 'core' = 'core';
|
||||
|
||||
private _blocksuiteWorkspace?: BlocksuiteWorkspace;
|
||||
private _blocksuiteWorkspace?: BlocksuiteWorkspace | null;
|
||||
|
||||
constructor(params: WorkspaceUnitCtorParams) {
|
||||
this.id = params.id;
|
||||
@ -41,7 +41,7 @@ export class WorkspaceUnit {
|
||||
return this._blocksuiteWorkspace;
|
||||
}
|
||||
|
||||
setBlocksuiteWorkspace(blocksuiteWorkspace: BlocksuiteWorkspace) {
|
||||
setBlocksuiteWorkspace(blocksuiteWorkspace: BlocksuiteWorkspace | null) {
|
||||
if (blocksuiteWorkspace?.room !== this.id) {
|
||||
throw new Error('Workspace id inconsistent.');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user