UNPKG

@c11/engine.types

Version:

Typescript types for everything engine related

68 lines (67 loc) 2.26 kB
import { MacroProducerType } from "./macro"; import { ProducerConfig, ProducerInstance } from "./producer"; import { ViewConfig } from "./view"; import { EventContext, Event, EventNames, EventPayload } from "./events"; import { DatastoreInstance } from "./db"; export declare type ExternalProducerContext = { props?: any; debug?: boolean; }; export declare type UpdateSourceFn = (config: ProducerConfig | ViewConfig) => void; export declare type UnsubscribeSourceUpdateFn = () => void; export declare enum EngineStatus { RUNNING = "RUNNING", NOT_RUNNING = "NOT_RUNNING" } export declare type EngineContext = { engineId: string; db: DatastoreInstance; emit: (name: EventNames, payload?: EventPayload, context?: EventContext) => void; }; export declare enum ModuleNames { ENGINE_PRODUCERS = "ENGINE_PRODUCERS", REACT_RENDER = "REACT_RENDER" } export declare type ModuleContext = { emit: EngineContext["emit"]; onSourceUpdate: (sourceId: string, cb: UpdateSourceFn) => UnsubscribeSourceUpdateFn; addProducer: (config: MacroProducerType, context?: ExternalProducerContext) => ProducerInstance; }; export declare type EngineModuleInstance = { unmount(): void; }; export declare type EngineModuleSource = { name: ModuleNames; bootstrap?: () => void | Promise<void>; mount: (context: ModuleContext) => void | Promise<void>; unmount: (context: ModuleContext) => void | Promise<void>; }; export declare type EventListener = (event: Event) => void; export declare type EventListenerMap = Partial<{ [k in EventNames]: EventListener; }>; export declare type EngineConfig = { onEvents?: EventListener | EventListenerMap; state?: { [key: string]: any; }; use?: EngineModuleSource[]; }; export declare type EngineState = { [key: string]: any; }; export interface EngineApi { start(): void; stop(): void; state(state: EngineState): void; use(bundle: EngineModuleSource): void; } export declare enum EngineModuleState { NOT_BOOTSTRAPPED = "NOT_BOOTSTRAPPED", BOOTSTRAPING = "BOOTSTRAPING", NOT_MOUNTED = "NOT_MOUNTED", MOUNTED = "MOUNTED", UNMOUNTING = "UNMOUNTING", UPDATING = "UPDATING", SKIP_BECAUSE_BROKEN = "SKIP_BECAUSE_BROKEN" }