mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-11 05:58:56 +08:00
refactor(infra): migrate to new infra (#5565)
This commit is contained in:
@@ -17,7 +17,7 @@ export function configurePageServices(services: ServiceCollection) {
|
||||
services
|
||||
.scope(WorkspaceScope)
|
||||
.add(PageListService, [Workspace])
|
||||
.add(PageManager, [Workspace, ServiceProvider]);
|
||||
.add(PageManager, [Workspace, PageListService, ServiceProvider]);
|
||||
services
|
||||
.scope(PageScope)
|
||||
.add(CleanupService)
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { PageMeta } from '@blocksuite/store';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { LiveData } from '../livedata';
|
||||
import type { Workspace } from '../workspace';
|
||||
import { SyncEngineStep, type Workspace } from '../workspace';
|
||||
|
||||
export class PageListService {
|
||||
constructor(private readonly workspace: Workspace) {}
|
||||
@@ -25,4 +25,26 @@ export class PageListService {
|
||||
}),
|
||||
[]
|
||||
);
|
||||
|
||||
public readonly isReady = LiveData.from<boolean>(
|
||||
new Observable(subscriber => {
|
||||
subscriber.next(
|
||||
this.workspace.engine.status.sync.step === SyncEngineStep.Synced
|
||||
);
|
||||
|
||||
const dispose = this.workspace.engine.onStatusChange.on(() => {
|
||||
subscriber.next(
|
||||
this.workspace.engine.status.sync.step === SyncEngineStep.Synced
|
||||
);
|
||||
}).dispose;
|
||||
return () => {
|
||||
dispose();
|
||||
};
|
||||
}),
|
||||
false
|
||||
);
|
||||
|
||||
public getPageMetaById(id: string) {
|
||||
return this.pages.value.find(page => page.id === id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import type { PageMeta } from '@blocksuite/store';
|
||||
|
||||
import type { ServiceProvider } from '../di';
|
||||
import { ObjectPool, type RcRef } from '../utils/object-pool';
|
||||
import { ObjectPool } from '../utils/object-pool';
|
||||
import type { Workspace } from '../workspace';
|
||||
import { configurePageContext } from './context';
|
||||
import type { PageListService } from './list';
|
||||
import { Page } from './page';
|
||||
import { PageScope } from './service-scope';
|
||||
|
||||
@@ -12,10 +13,20 @@ export class PageManager {
|
||||
|
||||
constructor(
|
||||
private readonly workspace: Workspace,
|
||||
private readonly pageList: PageListService,
|
||||
private readonly serviceProvider: ServiceProvider
|
||||
) {}
|
||||
|
||||
open(pageMeta: PageMeta): RcRef<Page> {
|
||||
openByPageId(pageId: string) {
|
||||
const pageMeta = this.pageList.getPageMetaById(pageId);
|
||||
if (!pageMeta) {
|
||||
throw new Error('Page not found');
|
||||
}
|
||||
|
||||
return this.open(pageMeta);
|
||||
}
|
||||
|
||||
open(pageMeta: PageMeta) {
|
||||
const blockSuitePage = this.workspace.blockSuiteWorkspace.getPage(
|
||||
pageMeta.id
|
||||
);
|
||||
@@ -25,7 +36,7 @@ export class PageManager {
|
||||
|
||||
const exists = this.pool.get(pageMeta.id);
|
||||
if (exists) {
|
||||
return exists;
|
||||
return { page: exists.obj, release: exists.release };
|
||||
}
|
||||
|
||||
const serviceCollection = this.serviceProvider.collection
|
||||
@@ -41,6 +52,8 @@ export class PageManager {
|
||||
|
||||
const page = provider.get(Page);
|
||||
|
||||
return this.pool.put(pageMeta.id, page);
|
||||
const { obj, release } = this.pool.put(pageMeta.id, page);
|
||||
|
||||
return { page: obj, release };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user