import { IElementParams, IRootState, ElementId, ILocator } from "./types"; import { CallbacksManager } from "./CallbacksManager"; import { EventsManager } from "./EventsManager"; import { ElementState } from "./ElementState"; export interface IProcessorConfig { callbacksManager: CallbacksManager; eventsManager: EventsManager; root: IElementParams; } export class Processor { state: IRootState; currentElementId = 0; locator: ILocator; constructor(protected config: IProcessorConfig) { this.state = { elements: {}, rootElementId: 0, }; this.locator = { callbacksManager: config.callbacksManager, eventsManager: config.eventsManager, processor: this, }; const rootElementId = this.createElement(config.root); this.state.rootElementId = rootElementId; } createElement(params: IElementParams) { this.currentElementId++; this.state.elements[this.currentElementId] = { state: new ElementState(params), }; return this.currentElementId; } getElementStateById(id: ElementId) { if (!this.state.elements[id]) { throw new Error("Not found element with id " + id); } return this.state.elements[id].state; } getState() { return this.state; } getRootElementId() { return this.state.rootElementId; } }