Cleaning
This commit is contained in:
38
src/lib/contexts/app-context.ts
Normal file
38
src/lib/contexts/app-context.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { getContext, setContext } from 'svelte';
|
||||
import { ProjectManager } from '../project-system/project-manager';
|
||||
import { createCsoundStore } from '../csound/store';
|
||||
import { createEditorSettingsStore } from '../stores/editorSettings';
|
||||
import { ProjectEditor } from '../stores/projectEditor.svelte';
|
||||
import type { CsoundStore } from '../csound/store';
|
||||
import type { EditorSettingsStore } from '../stores/editorSettings';
|
||||
|
||||
export interface AppContext {
|
||||
projectManager: ProjectManager;
|
||||
csound: CsoundStore;
|
||||
editorSettings: EditorSettingsStore;
|
||||
projectEditor: ProjectEditor;
|
||||
}
|
||||
|
||||
const APP_CONTEXT_KEY = Symbol('app-context');
|
||||
|
||||
export function createAppContext(): AppContext {
|
||||
const projectManager = new ProjectManager();
|
||||
return {
|
||||
projectManager,
|
||||
csound: createCsoundStore(),
|
||||
editorSettings: createEditorSettingsStore(),
|
||||
projectEditor: new ProjectEditor(projectManager)
|
||||
};
|
||||
}
|
||||
|
||||
export function setAppContext(context: AppContext): void {
|
||||
setContext<AppContext>(APP_CONTEXT_KEY, context);
|
||||
}
|
||||
|
||||
export function getAppContext(): AppContext {
|
||||
const context = getContext<AppContext>(APP_CONTEXT_KEY);
|
||||
if (!context) {
|
||||
throw new Error('AppContext not found. Did you forget to call setAppContext?');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
Reference in New Issue
Block a user