Sha256: 3151a5e6fb8658e6650ea1bd29da03decf4fd04d77d6b2e515bcdc344c50507f
Contents?: true
Size: 1.22 KB
Versions: 11
Compression:
Stored size: 1.22 KB
Contents
import { claptonChannel } from "../channel/clapton-channel"; export const handleAction = async (target: HTMLElement, stateName: string, fn: string) => { let targetComponent = target; if (target.dataset.component === stateName.replace("State", "Component")) { targetComponent = target } else { 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.dataset.attribute; if (attribute) { const state = JSON.parse(component.dataset.state || "{}"); if (target.tagName === "INPUT") { state[attribute] = (target as HTMLInputElement).value; component.dataset.state = JSON.stringify(state); } }; claptonChannel.perform( "action", { data: { component: { name: stateName.replace("State", "Component"), id: targetComponent.dataset.id, }, state: { name: stateName, action: fn, attributes: JSON.parse(targetComponent.dataset.state || "{}"), }, params: JSON.parse(component.dataset.state || "{}") } } ); };
Version data entries
11 entries across 11 versions & 1 rubygems