Sha256: e44c974140623861aa876a1d5c9905dd3ff4f4d5df33338cdd7ac9363586aedb
Contents?: true
Size: 1.2 KB
Versions: 6
Compression:
Stored size: 1.2 KB
Contents
import { splitActionAttribute } from "./html/split-action-attribute" import { updateComponent } from "./dom/update-component" import { handleAction } from "./actions/handle-action" import { initializeActions } from "actions/initialize-actions"; import { initializeInputs } from "inputs/initialize-inputs"; interface ComponentDefinition { component: new (state: any) => ComponentInstance; state: any; id: string; } interface ComponentInstance { render: string; [key: string]: any; } const initializeComponents = () => { const components = document.querySelector("#clapton")?.getAttribute("data-clapton") || "[]"; JSON.parse(components).forEach(createAndAppendComponent); }; const createAndAppendComponent = (component: ComponentDefinition) => { const componentDom = document.createElement('div'); const instance = new (window[component.component as any] as any)(component.state); componentDom.innerHTML = instance.render; const firstChild = componentDom.firstChild as HTMLElement; if (firstChild) { document.querySelector("#clapton")?.appendChild(firstChild); } }; document.addEventListener("DOMContentLoaded", () => { initializeComponents(); initializeActions(); initializeInputs(); });
Version data entries
6 entries across 6 versions & 1 rubygems