feat: add remove workspace by ids
This commit is contained in:
@@ -141,16 +141,10 @@ export class AffineProvider extends BaseProvider {
|
|||||||
addedWorkspaces.push(workspaceUnit);
|
addedWorkspaces.push(workspaceUnit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (addedWorkspaces.length) {
|
// add workspaces
|
||||||
// add workspaces
|
this._workspaces.add(addedWorkspaces);
|
||||||
this._workspaces.add(addedWorkspaces);
|
// remove workspaces
|
||||||
}
|
this._workspaces.remove(removeWorkspaceList);
|
||||||
if (removeWorkspaceList.length) {
|
|
||||||
// remove workspaces
|
|
||||||
removeWorkspaceList.forEach(id => {
|
|
||||||
this._workspaces.remove(id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getWebsocketProvider(workspace: BlocksuiteWorkspace) {
|
private _getWebsocketProvider(workspace: BlocksuiteWorkspace) {
|
||||||
@@ -174,7 +168,7 @@ export class AffineProvider extends BaseProvider {
|
|||||||
blocksuiteWorkspace: BlocksuiteWorkspace,
|
blocksuiteWorkspace: BlocksuiteWorkspace,
|
||||||
published = false
|
published = false
|
||||||
) {
|
) {
|
||||||
const { doc, room: workspaceId } = blocksuiteWorkspace;
|
const { room: workspaceId } = blocksuiteWorkspace;
|
||||||
assert(workspaceId, 'Blocksuite Workspace without room(workspaceId).');
|
assert(workspaceId, 'Blocksuite Workspace without room(workspaceId).');
|
||||||
const updates = await this._apis.downloadWorkspace(workspaceId, published);
|
const updates = await this._apis.downloadWorkspace(workspaceId, published);
|
||||||
await applyUpdate(blocksuiteWorkspace, new Uint8Array(updates));
|
await applyUpdate(blocksuiteWorkspace, new Uint8Array(updates));
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export interface WorkspaceUnitCollectionScope {
|
|||||||
get: (workspaceId: string) => WorkspaceUnit | undefined;
|
get: (workspaceId: string) => WorkspaceUnit | undefined;
|
||||||
list: () => WorkspaceUnit[];
|
list: () => WorkspaceUnit[];
|
||||||
add: (workspace: WorkspaceUnit | WorkspaceUnit[]) => void;
|
add: (workspace: WorkspaceUnit | WorkspaceUnit[]) => void;
|
||||||
remove: (workspaceId: string) => boolean;
|
remove: (workspaceId: string | string[]) => boolean;
|
||||||
clear: () => void;
|
clear: () => void;
|
||||||
update: (
|
update: (
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
@@ -18,7 +18,7 @@ export interface WorkspaceUnitCollectionScope {
|
|||||||
|
|
||||||
export interface WorkspaceUnitCollectionChangeEvent {
|
export interface WorkspaceUnitCollectionChangeEvent {
|
||||||
added?: WorkspaceUnit[];
|
added?: WorkspaceUnit[];
|
||||||
deleted?: WorkspaceUnit;
|
deleted?: WorkspaceUnit[];
|
||||||
updated?: WorkspaceUnit;
|
updated?: WorkspaceUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,16 +62,22 @@ export class WorkspaceUnitCollection {
|
|||||||
const workspaceUnits = Array.isArray(workspaceUnit)
|
const workspaceUnits = Array.isArray(workspaceUnit)
|
||||||
? workspaceUnit
|
? workspaceUnit
|
||||||
: [workspaceUnit];
|
: [workspaceUnit];
|
||||||
|
let added = false;
|
||||||
|
|
||||||
workspaceUnits.forEach(workspaceUnit => {
|
workspaceUnits.forEach(workspaceUnit => {
|
||||||
if (this._workspaceUnitMap.has(workspaceUnit.id)) {
|
if (this._workspaceUnitMap.has(workspaceUnit.id)) {
|
||||||
// FIXME: multiple add same workspace
|
// FIXME: multiple add same workspace
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
added = true;
|
||||||
this._workspaceUnitMap.set(workspaceUnit.id, workspaceUnit);
|
this._workspaceUnitMap.set(workspaceUnit.id, workspaceUnit);
|
||||||
scopedWorkspaceIds.add(workspaceUnit.id);
|
scopedWorkspaceIds.add(workspaceUnit.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!added) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this._events.emit('change', [
|
this._events.emit('change', [
|
||||||
{
|
{
|
||||||
added: workspaceUnits,
|
added: workspaceUnits,
|
||||||
@@ -79,27 +85,39 @@ export class WorkspaceUnitCollection {
|
|||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const remove = (workspaceId: string) => {
|
const remove = (workspaceId: string | string[]) => {
|
||||||
if (!scopedWorkspaceIds.has(workspaceId)) {
|
const workspaceIds = Array.isArray(workspaceId)
|
||||||
return true;
|
? workspaceId
|
||||||
}
|
: [workspaceId];
|
||||||
|
const workspaceUnits: WorkspaceUnit[] = [];
|
||||||
|
|
||||||
const workspaceUnit = this._workspaceUnitMap.get(workspaceId);
|
workspaceIds.forEach(workspaceId => {
|
||||||
if (workspaceUnit) {
|
if (!scopedWorkspaceIds.has(workspaceId)) {
|
||||||
const ret = this._workspaceUnitMap.delete(workspaceId);
|
return;
|
||||||
// If deletion failed, return.
|
|
||||||
if (!ret) {
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
const workspaceUnit = this._workspaceUnitMap.get(workspaceId);
|
||||||
|
if (workspaceUnit) {
|
||||||
|
const ret = this._workspaceUnitMap.delete(workspaceId);
|
||||||
|
// If deletion failed, return.
|
||||||
|
if (!ret) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
scopedWorkspaceIds.delete(workspaceId);
|
workspaceUnits.push(workspaceUnit);
|
||||||
|
scopedWorkspaceIds.delete(workspaceId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this._events.emit('change', [
|
if (!workspaceUnits.length) {
|
||||||
{
|
return false;
|
||||||
deleted: workspaceUnit,
|
|
||||||
} as WorkspaceUnitCollectionChangeEvent,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._events.emit('change', [
|
||||||
|
{
|
||||||
|
deleted: workspaceUnits,
|
||||||
|
} as WorkspaceUnitCollectionChangeEvent,
|
||||||
|
]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user