feat(infra): framework

This commit is contained in:
EYHN
2024-04-17 14:12:29 +08:00
parent ab17a05df3
commit 06fda3b62c
467 changed files with 9996 additions and 8697 deletions

View File

@@ -1 +1,15 @@
export * from './service';
export { CollectionService } from './services/collection';
import {
type Framework,
WorkspaceScope,
WorkspaceService,
} from '@toeverything/infra';
import { CollectionService } from './services/collection';
export function configureCollectionModule(framework: Framework) {
framework
.scope(WorkspaceScope)
.service(CollectionService, [WorkspaceService]);
}

View File

@@ -3,8 +3,8 @@ import type {
DeleteCollectionInfo,
DeletedCollection,
} from '@affine/env/filter';
import type { Workspace } from '@toeverything/infra';
import { LiveData } from '@toeverything/infra';
import type { WorkspaceService } from '@toeverything/infra';
import { LiveData, Service } from '@toeverything/infra';
import { Observable } from 'rxjs';
import { Array as YArray } from 'yjs';
@@ -13,15 +13,19 @@ const SETTING_KEY = 'setting';
const COLLECTIONS_KEY = 'collections';
const COLLECTIONS_TRASH_KEY = 'collections_trash';
export class CollectionService {
constructor(private readonly workspace: Workspace) {}
export class CollectionService extends Service {
constructor(private readonly workspaceService: WorkspaceService) {
super();
}
private get doc() {
return this.workspace.docCollection.doc;
return this.workspaceService.workspace.docCollection.doc;
}
private get setting() {
return this.workspace.docCollection.doc.getMap(SETTING_KEY);
return this.workspaceService.workspace.docCollection.doc.getMap(
SETTING_KEY
);
}
private get collectionsYArray(): YArray<Collection> | undefined {
@@ -105,7 +109,7 @@ export class CollectionService {
return;
}
const set = new Set(ids);
this.workspace.docCollection.doc.transact(() => {
this.workspaceService.workspace.docCollection.doc.transact(() => {
const indexList: number[] = [];
const list: Collection[] = [];
collectionsYArray.forEach((collection, i) => {