mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-28 12:52:57 +03:00
feat: change the order of load workspaces
This commit is contained in:
parent
b4571539ac
commit
104693916f
@ -46,6 +46,10 @@ export class DataCenter {
|
||||
dc.registerProvider(new LocalProvider(getInitParams()));
|
||||
dc.registerProvider(new AffineProvider(getInitParams()));
|
||||
|
||||
for (const provider of dc.providerMap.values()) {
|
||||
await provider.loadWorkspaces();
|
||||
}
|
||||
|
||||
return dc;
|
||||
}
|
||||
|
||||
@ -181,8 +185,14 @@ export class DataCenter {
|
||||
* @param {Function} callback callback function
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ import { BaseProvider } from '../base.js';
|
||||
import type {
|
||||
ProviderConstructorParams,
|
||||
CreateWorkspaceInfoParams,
|
||||
UpdateWorkspaceMetaParams,
|
||||
WorkspaceMeta0,
|
||||
} from '../base';
|
||||
import type { User } from '../../types';
|
||||
@ -34,11 +33,6 @@ export class AffineProvider extends BaseProvider {
|
||||
constructor({ apis, ...params }: AffineProviderConstructorParams) {
|
||||
super(params);
|
||||
this._apis = apis || getApis();
|
||||
this.init().then(() => {
|
||||
if (this._apis.token.isLogin) {
|
||||
this.loadWorkspaces();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
override async init() {
|
||||
|
@ -19,7 +19,6 @@ export class LocalProvider extends BaseProvider {
|
||||
|
||||
constructor(params: ProviderConstructorParams) {
|
||||
super(params);
|
||||
this.loadWorkspaces();
|
||||
}
|
||||
|
||||
private _storeWorkspaces(workspaces: WorkspaceMeta0[]) {
|
||||
|
@ -18,7 +18,7 @@ export interface WorkspaceUnitCollectionScope {
|
||||
}
|
||||
|
||||
export interface WorkspaceUnitCollectionChangeEvent {
|
||||
added?: WorkspaceUnit;
|
||||
added?: WorkspaceUnit[];
|
||||
deleted?: WorkspaceUnit;
|
||||
updated?: WorkspaceUnit;
|
||||
}
|
||||
@ -71,7 +71,7 @@ export class WorkspaceUnitCollection {
|
||||
|
||||
this._events.emit('change', [
|
||||
{
|
||||
added: workspaceUnit,
|
||||
added: [workspaceUnit],
|
||||
} as WorkspaceUnitCollectionChangeEvent,
|
||||
]);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user