Skip to content

Commit

Permalink
feat: optimize code
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Aug 15, 2023
1 parent 7682ba1 commit c317dd9
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/plugins/workspace/public/workspace_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,34 @@ export class WorkspaceClient {
this.http = http;
this.workspaces = workspaces;

combineLatest([workspaces.workspaceList$, workspaces.currentWorkspaceId$]).subscribe(
([workspaceList, currentWorkspaceId]) => {
if (this.workspaces.hasFetchedWorkspaceList$.getValue()) {
const currentWorkspace = this.findWorkspace([workspaceList, currentWorkspaceId]);
combineLatest([
workspaces.hasFetchedWorkspaceList$,
workspaces.workspaceList$,
workspaces.currentWorkspaceId$,
]).subscribe(([hasFetchedWorkspaceList, workspaceList, currentWorkspaceId]) => {
if (hasFetchedWorkspaceList) {
const currentWorkspace = this.findWorkspace([workspaceList, currentWorkspaceId]);

/**
* Do a simple idempotent verification here
*/
if (!isEqual(currentWorkspace, workspaces.currentWorkspace$.getValue())) {
workspaces.currentWorkspace$.next(currentWorkspace);
}

if (currentWorkspaceId && !currentWorkspace?.id) {
/**
* Do a simple idempotent verification here
* Current workspace is staled
*/
if (!isEqual(currentWorkspace, workspaces.currentWorkspace$.getValue())) {
workspaces.currentWorkspace$.next(currentWorkspace);
}

if (currentWorkspaceId && !currentWorkspace?.id) {
/**
* Current workspace is staled
*/
workspaces.currentWorkspaceId$.error({
reason: WORKSPACE_ERROR_REASON_MAP.WORKSPACE_STALED,
});
workspaces.currentWorkspace$.error({
reason: WORKSPACE_ERROR_REASON_MAP.WORKSPACE_STALED,
});
}
workspaces.currentWorkspaceId$.error({
reason: WORKSPACE_ERROR_REASON_MAP.WORKSPACE_STALED,
});
workspaces.currentWorkspace$.error({
reason: WORKSPACE_ERROR_REASON_MAP.WORKSPACE_STALED,
});
}
}
);
});
}

/**
Expand Down

0 comments on commit c317dd9

Please sign in to comment.