feat(core): remember backlink open/close state (#9073)

fix AF-1850, AF-1883
This commit is contained in:
pengx17
2024-12-10 02:28:20 +00:00
parent 4335b0dc79
commit ec140da0d9
7 changed files with 132 additions and 25 deletions

View File

@@ -1,17 +1,35 @@
export { GlobalCache, GlobalState } from './providers/global';
export { GlobalCacheService, GlobalStateService } from './services/global';
export {
GlobalCache,
GlobalSessionState,
GlobalState,
} from './providers/global';
export {
GlobalCacheService,
GlobalSessionStateService,
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';
import {
GlobalCache,
GlobalSessionState,
GlobalState,
} from './providers/global';
import {
GlobalCacheService,
GlobalSessionStateService,
GlobalStateService,
} from './services/global';
export const configureGlobalStorageModule = (framework: Framework) => {
framework.service(GlobalStateService, [GlobalState]);
framework.service(GlobalCacheService, [GlobalCache]);
framework.service(GlobalSessionStateService, [GlobalSessionState]);
};
export const configureTestingGlobalStorage = (framework: Framework) => {
framework.impl(GlobalCache, MemoryMemento);
framework.impl(GlobalState, MemoryMemento);
framework.impl(GlobalSessionState, MemoryMemento);
};

View File

@@ -16,5 +16,13 @@ export const GlobalState = createIdentifier<GlobalState>('GlobalState');
* 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');
/**
* A memento object that stores session state.
*
* Session state is not persisted, it will be cleared when the application is closed. (thinking about sessionStorage)
*/
export interface GlobalSessionState extends Memento {}
export const GlobalSessionState =
createIdentifier<GlobalSessionState>('GlobalSessionState');

View File

@@ -1,5 +1,9 @@
import { Service } from '../../../framework';
import type { GlobalCache, GlobalState } from '../providers/global';
import type {
GlobalCache,
GlobalSessionState,
GlobalState,
} from '../providers/global';
export class GlobalStateService extends Service {
constructor(public readonly globalState: GlobalState) {
@@ -12,3 +16,9 @@ export class GlobalCacheService extends Service {
super();
}
}
export class GlobalSessionStateService extends Service {
constructor(public readonly globalSessionState: GlobalSessionState) {
super();
}
}