feat(infra): framework

This commit is contained in:
EYHN
2024-04-17 14:12:29 +08:00
parent ab17a05df3
commit 06fda3b62c
467 changed files with 9996 additions and 8697 deletions

View File

@@ -1,7 +1,6 @@
import { describe, expect, test } from 'vitest';
import { ServiceCollection } from '../../di';
import { GlobalCache, GlobalState, MemoryMemento } from '..';
import { MemoryMemento } from '..';
describe('memento', () => {
test('memory', () => {
@@ -23,18 +22,4 @@ describe('memento', () => {
memento.set('foo', 'hello');
expect(subscribed).toEqual('baz');
});
test('service', () => {
const services = new ServiceCollection();
services
.addImpl(GlobalCache, MemoryMemento)
.addImpl(GlobalState, MemoryMemento);
const provider = services.provider();
const cache = provider.get(GlobalCache);
expect(cache).toBeInstanceOf(MemoryMemento);
const state = provider.get(GlobalState);
expect(state).toBeInstanceOf(MemoryMemento);
});
});

View File

@@ -1,6 +1,5 @@
import type { Observable } from 'rxjs';
import { createIdentifier } from '../di';
import { LiveData } from '../livedata';
/**
@@ -15,24 +14,6 @@ export interface Memento {
keys(): string[];
}
/**
* 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');
/**
* A simple implementation of Memento. Used for testing.
*/