Sha256: 66076423acdd471c023bcc4efa03bc40ec901cbf926c1f6b831828c3e42dfb83
Contents?: true
Size: 1.13 KB
Versions: 12
Compression:
Stored size: 1.13 KB
Contents
import { splitActionAttribute } from "../html/split-action-attribute"; import { handleAction } from "./handle-action"; import { debounce } from "../utils/debounce"; export const initializeActions = () => { const actionElements = document.querySelectorAll("[data-action]"); actionElements.forEach((element) => initializeActionsForElement(element as HTMLElement)); }; const initializeActionsForElement = (element: HTMLElement) => { if (element.getAttribute("data-set-event-handler")) return; const actions = element.getAttribute("data-action")?.split(" ") || []; actions.forEach(action => { const { eventType, componentName, stateName, fnName, bounceTime } = splitActionAttribute(action); if (!eventType || !componentName || !fnName) return; if (bounceTime > 0) { element.addEventListener(eventType, debounce((event) => handleAction(event.target as HTMLElement, stateName, fnName), bounceTime) ); } else { element.addEventListener(eventType, (event) => handleAction(event.target as HTMLElement, stateName, fnName) ); } element.setAttribute("data-set-event-handler", "true"); }); };
Version data entries
12 entries across 12 versions & 1 rubygems