import Conquer from '@burguillosinfo/conquer' export default abstract class ConquerInterface { private alreadyGenerated = false private nodes: HTMLElement[] private callbacks: Record void>> = {} public getNodes(): HTMLElement[] { if (!this.alreadyGenerated) { this.nodes = this.generateNodes() this.alreadyGenerated = true } return this.nodes } protected abstract generateNodes(): HTMLElement[] public run(): void { return } public prune(): void { return } protected getNodeFromTemplateId(id: string): HTMLElement { const template = document.getElementById(id) if (template === null) { Conquer.fail(`Unable to find template id ${id}.`) } const finalNode = template.cloneNode(true) if (!(finalNode instanceof HTMLElement)) { Conquer.fail('The node is not an Element.') } return finalNode } public on(eventName: string, callback: () => void): void { if (this.callbacks[eventName] === undefined) { this.callbacks[eventName] = [] } this.callbacks[eventName].push(callback) } protected runCallbacks(eventName: string) { const callbacks = this.callbacks[eventName]; if (callbacks === undefined) { return } for (const callback of callbacks) { callback() } } }