mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +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,8 +1,8 @@
|
||||
import type { GlobalCache } from '@toeverything/infra';
|
||||
import type { GlobalCache, GlobalState, Memento } from '@toeverything/infra';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
export class LocalStorageGlobalCache implements GlobalCache {
|
||||
prefix = 'cache:';
|
||||
export class LocalStorageMemento implements Memento {
|
||||
constructor(private readonly prefix: string) {}
|
||||
|
||||
get<T>(key: string): T | null {
|
||||
const json = localStorage.getItem(this.prefix + key);
|
||||
@@ -30,3 +30,21 @@ export class LocalStorageGlobalCache implements GlobalCache {
|
||||
channel.close();
|
||||
}
|
||||
}
|
||||
|
||||
export class LocalStorageGlobalCache
|
||||
extends LocalStorageMemento
|
||||
implements GlobalCache
|
||||
{
|
||||
constructor() {
|
||||
super('global-cache:');
|
||||
}
|
||||
}
|
||||
|
||||
export class LocalStorageGlobalState
|
||||
extends LocalStorageMemento
|
||||
implements GlobalState
|
||||
{
|
||||
constructor() {
|
||||
super('global-state:');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import {
|
||||
GlobalCache,
|
||||
GlobalState,
|
||||
type ServiceCollection,
|
||||
Workspace,
|
||||
WorkspaceScope,
|
||||
} from '@toeverything/infra';
|
||||
|
||||
import { CollectionService } from './collection';
|
||||
import { LocalStorageGlobalCache } from './infra-web/storage';
|
||||
import {
|
||||
LocalStorageGlobalCache,
|
||||
LocalStorageGlobalState,
|
||||
} from './infra-web/storage';
|
||||
import { CurrentPageService } from './page';
|
||||
import {
|
||||
CurrentWorkspaceService,
|
||||
@@ -25,5 +29,7 @@ export function configureBusinessServices(services: ServiceCollection) {
|
||||
}
|
||||
|
||||
export function configureWebInfraServices(services: ServiceCollection) {
|
||||
services.addImpl(GlobalCache, LocalStorageGlobalCache);
|
||||
services
|
||||
.addImpl(GlobalCache, LocalStorageGlobalCache)
|
||||
.addImpl(GlobalState, LocalStorageGlobalState);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user