mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-01 09:30:01 +08:00
feat(infra): framework
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { Entity } from '../../../framework';
|
||||
import { LiveData } from '../../../livedata';
|
||||
import { MemoryMemento } from '../../../storage';
|
||||
import type { DocMode } from '../../doc';
|
||||
|
||||
export class GlobalContext extends Entity {
|
||||
memento = new MemoryMemento();
|
||||
|
||||
workspaceId = this.define<string>('workspaceId');
|
||||
|
||||
docId = this.define<string>('docId');
|
||||
|
||||
docMode = this.define<DocMode>('docMode');
|
||||
|
||||
define<T>(key: string) {
|
||||
this.memento.set(key, null);
|
||||
const livedata$ = LiveData.from(this.memento.watch<T>(key), null);
|
||||
return {
|
||||
get: () => this.memento.get(key) as T | null,
|
||||
set: (value: T | null) => this.memento.set(key, value),
|
||||
$: livedata$,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
export { GlobalContextService } from './services/global-context';
|
||||
|
||||
import type { Framework } from '../../framework';
|
||||
import { GlobalContext } from './entities/global-context';
|
||||
import { GlobalContextService } from './services/global-context';
|
||||
|
||||
export function configureGlobalContextModule(framework: Framework) {
|
||||
framework.service(GlobalContextService).entity(GlobalContext);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Service } from '../../../framework';
|
||||
import { GlobalContext } from '../entities/global-context';
|
||||
|
||||
export class GlobalContextService extends Service {
|
||||
globalContext = this.framework.createEntity(GlobalContext);
|
||||
}
|
||||
Reference in New Issue
Block a user