Sha256: 2da9b5abedfc37ea6144afaf664bf20e02600381979cc98f9f06fd2bc26b7204
Contents?: true
Size: 1.15 KB
Versions: 12
Compression:
Stored size: 1.15 KB
Contents
import { claptonChannel } from "../channel/clapton-channel"; export const handleAction = async (target: HTMLElement, stateName: string, fn: string) => { const targetComponent = target.closest(`[data-component="${stateName.replace("State", "Component")}"]`) as HTMLElement; if (!targetComponent) return; const component = target.closest(`[data-component]`) as HTMLElement; const attribute = target.getAttribute("data-attribute"); if (attribute) { const state = JSON.parse(component.getAttribute("data-state") || "{}"); if (target.tagName === "INPUT") { state[attribute] = (target as HTMLInputElement).value; component.setAttribute("data-state", JSON.stringify(state)); } }; claptonChannel.perform( "action", { data: { component: { name: stateName.replace("State", "Component"), id: targetComponent.getAttribute("data-id"), }, state: { name: stateName, action: fn, attributes: JSON.parse(targetComponent.getAttribute("data-state") || "{}"), }, params: JSON.parse(component.getAttribute("data-state") || "{}") } } ); };
Version data entries
12 entries across 12 versions & 1 rubygems