feat: change the order of load workspaces

This commit is contained in:
MingLiang Wang 2023-01-10 20:11:46 +08:00
parent b4571539ac
commit 104693916f
4 changed files with 13 additions and 10 deletions

View File

@ -46,6 +46,10 @@ export class DataCenter {
dc.registerProvider(new LocalProvider(getInitParams())); dc.registerProvider(new LocalProvider(getInitParams()));
dc.registerProvider(new AffineProvider(getInitParams())); dc.registerProvider(new AffineProvider(getInitParams()));
for (const provider of dc.providerMap.values()) {
await provider.loadWorkspaces();
}
return dc; return dc;
} }
@ -181,8 +185,14 @@ export class DataCenter {
* @param {Function} callback callback function * @param {Function} callback callback function
*/ */
public async onWorkspacesChange( public async onWorkspacesChange(
callback: (workspaces: WorkspaceUnitCollectionChangeEvent) => void callback: (workspaces: WorkspaceUnitCollectionChangeEvent) => void,
{ immediate = true }: { immediate?: boolean }
) { ) {
if (immediate) {
callback({
added: this._workspaceUnitCollection.workspaces,
});
}
this._workspaceUnitCollection.on('change', callback); this._workspaceUnitCollection.on('change', callback);
} }

View File

@ -2,7 +2,6 @@ import { BaseProvider } from '../base.js';
import type { import type {
ProviderConstructorParams, ProviderConstructorParams,
CreateWorkspaceInfoParams, CreateWorkspaceInfoParams,
UpdateWorkspaceMetaParams,
WorkspaceMeta0, WorkspaceMeta0,
} from '../base'; } from '../base';
import type { User } from '../../types'; import type { User } from '../../types';
@ -34,11 +33,6 @@ export class AffineProvider extends BaseProvider {
constructor({ apis, ...params }: AffineProviderConstructorParams) { constructor({ apis, ...params }: AffineProviderConstructorParams) {
super(params); super(params);
this._apis = apis || getApis(); this._apis = apis || getApis();
this.init().then(() => {
if (this._apis.token.isLogin) {
this.loadWorkspaces();
}
});
} }
override async init() { override async init() {

View File

@ -19,7 +19,6 @@ export class LocalProvider extends BaseProvider {
constructor(params: ProviderConstructorParams) { constructor(params: ProviderConstructorParams) {
super(params); super(params);
this.loadWorkspaces();
} }
private _storeWorkspaces(workspaces: WorkspaceMeta0[]) { private _storeWorkspaces(workspaces: WorkspaceMeta0[]) {

View File

@ -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;
} }
@ -71,7 +71,7 @@ export class WorkspaceUnitCollection {
this._events.emit('change', [ this._events.emit('change', [
{ {
added: workspaceUnit, added: [workspaceUnit],
} as WorkspaceUnitCollectionChangeEvent, } as WorkspaceUnitCollectionChangeEvent,
]); ]);
}; };