mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 02:56:23 +08:00
feat(infra): framework
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
export { GlobalCache, GlobalState } from './providers/global';
|
||||
export { GlobalCacheService, GlobalStateService } from './services/global';
|
||||
|
||||
import type { Framework } from '../../framework';
|
||||
import { MemoryMemento } from '../../storage';
|
||||
import { GlobalCache, GlobalState } from './providers/global';
|
||||
import { GlobalCacheService, GlobalStateService } from './services/global';
|
||||
|
||||
export const configureGlobalStorageModule = (framework: Framework) => {
|
||||
framework.service(GlobalStateService, [GlobalState]);
|
||||
framework.service(GlobalCacheService, [GlobalCache]);
|
||||
};
|
||||
|
||||
export const configureTestingGlobalStorage = (framework: Framework) => {
|
||||
framework.impl(GlobalCache, MemoryMemento);
|
||||
framework.impl(GlobalState, MemoryMemento);
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
import { createIdentifier } from '../../../framework';
|
||||
import type { Memento } from '../../../storage';
|
||||
|
||||
/**
|
||||
* A memento object that stores the entire application state.
|
||||
*
|
||||
* State is persisted, even the application is closed.
|
||||
*/
|
||||
export interface GlobalState extends Memento {}
|
||||
|
||||
export const GlobalState = createIdentifier<GlobalState>('GlobalState');
|
||||
|
||||
/**
|
||||
* A memento object that stores the entire application cache.
|
||||
*
|
||||
* Cache may be deleted from time to time, business logic should not rely on cache.
|
||||
*/
|
||||
export interface GlobalCache extends Memento {}
|
||||
|
||||
export const GlobalCache = createIdentifier<GlobalCache>('GlobalCache');
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Service } from '../../../framework';
|
||||
import type { GlobalCache, GlobalState } from '../providers/global';
|
||||
|
||||
export class GlobalStateService extends Service {
|
||||
constructor(public readonly globalState: GlobalState) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
export class GlobalCacheService extends Service {
|
||||
constructor(public readonly globalCache: GlobalCache) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user