mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
refactor(core): refactor atom to use di (#5831)
To support multiple instances, this PR removes some atoms and implements them using the new DI system. removed atom - `pageSettingsAtom` - `currentPageIdAtom` - `currentModeAtom`
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
import { WorkspaceFactory, WorkspaceListProvider } from '@toeverything/infra';
|
||||
import type { ServiceCollection } from '@toeverything/infra/di';
|
||||
import type { ServiceCollection } from '@toeverything/infra';
|
||||
import {
|
||||
GlobalState,
|
||||
Workspace,
|
||||
WorkspaceFactory,
|
||||
WorkspaceListProvider,
|
||||
WorkspaceLocalState,
|
||||
WorkspaceScope,
|
||||
} from '@toeverything/infra';
|
||||
|
||||
import { CloudWorkspaceFactory, CloudWorkspaceListProvider } from './cloud';
|
||||
import {
|
||||
@@ -7,6 +14,7 @@ import {
|
||||
LocalWorkspaceFactory,
|
||||
LocalWorkspaceListProvider,
|
||||
} from './local';
|
||||
import { WorkspaceLocalStateImpl } from './local-state';
|
||||
|
||||
export * from './cloud';
|
||||
export * from './local';
|
||||
@@ -16,7 +24,12 @@ export function configureWorkspaceImplServices(services: ServiceCollection) {
|
||||
.addImpl(WorkspaceListProvider('affine-cloud'), CloudWorkspaceListProvider)
|
||||
.addImpl(WorkspaceFactory('affine-cloud'), CloudWorkspaceFactory)
|
||||
.addImpl(WorkspaceListProvider('local'), LocalWorkspaceListProvider)
|
||||
.addImpl(WorkspaceFactory('local'), LocalWorkspaceFactory);
|
||||
.addImpl(WorkspaceFactory('local'), LocalWorkspaceFactory)
|
||||
.scope(WorkspaceScope)
|
||||
.addImpl(WorkspaceLocalState, WorkspaceLocalStateImpl, [
|
||||
Workspace,
|
||||
GlobalState,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
31
packages/frontend/workspace-impl/src/local-state.ts
Normal file
31
packages/frontend/workspace-impl/src/local-state.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type {
|
||||
GlobalState,
|
||||
Workspace,
|
||||
WorkspaceLocalState,
|
||||
} from '@toeverything/infra';
|
||||
|
||||
export class WorkspaceLocalStateImpl implements WorkspaceLocalState {
|
||||
constructor(
|
||||
private readonly workspace: Workspace,
|
||||
private readonly globalState: GlobalState
|
||||
) {}
|
||||
|
||||
get<T>(key: string): T | null {
|
||||
return this.globalState.get<T>(
|
||||
`workspace-state:${this.workspace.id}:${key}`
|
||||
);
|
||||
}
|
||||
|
||||
watch<T>(key: string) {
|
||||
return this.globalState.watch<T>(
|
||||
`workspace-state:${this.workspace.id}:${key}`
|
||||
);
|
||||
}
|
||||
|
||||
set<T>(key: string, value: T | null): void {
|
||||
return this.globalState.set<T>(
|
||||
`workspace-state:${this.workspace.id}:${key}`,
|
||||
value
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user