onChange function ✓ 100.0%

Last updated: 2026-03-05T11:49:57.418Z

Metrics

LOC: 46 Complexity: 17 Params: 1 Coverage: 100.0% (14/14 lines, 0x executed)

Signature

onChange(e: Event): : void

Architecture violations

View all

  • [warning] max-cyclomatic-complexity: 'onChange' has cyclomatic complexity 17 (max 10)

Source Code

function onChange(e: Event): void {
  const el = e.target;
  if (!session || session.status !== "recording") return;
  if (isExtensionUI(el as Element)) return;

  // Checkbox and radio: `change` is the reliable event across all browsers.
  // Deduplicate with onInput in case the browser also fires `input` (Chrome 74+).
  if (el instanceof HTMLInputElement) {
    const lastStep = session.steps[session.steps.length - 1];
    if (el.type === "checkbox") {
      const action = el.checked ? "check" : "uncheck";
      if (
        lastStep?.type === action &&
        lastStep.selector === buildQuickSelector(el) &&
        now() - lastStep.timestamp < 500
      )
        return;
      addStep(buildStep(action, el));
      return;
    }
    if (el.type === "radio") {
      if (
        lastStep?.type === "check" &&
        lastStep.selector === buildQuickSelector(el) &&
        now() - lastStep.timestamp < 500
      )
        return;
      addStep(buildStep("check", el, { value: el.value }));
      return;
    }
  }

  if (!(el instanceof HTMLSelectElement)) return;

  // Select changes are captured here if not caught by input
  const lastStep = session.steps[session.steps.length - 1];
  if (
    lastStep?.type === "select" &&
    lastStep.selector === buildQuickSelector(el)
  ) {
    lastStep.value = el.value;
    return;
  }

  addStep(buildStep("select", el, { value: el.value }));
}

Dependencies (Outgoing)

graph LR onChange["onChange"] isExtensionUI["isExtensionUI"] buildQuickSelector["buildQuickSelector"] now["now"] addStep["addStep"] buildStep["buildStep"] onChange -->|calls| isExtensionUI onChange -->|calls| buildQuickSelector onChange -->|calls| now onChange -->|calls| addStep onChange -->|calls| buildStep style onChange fill:#dbeafe,stroke:#2563eb,stroke-width:2px click onChange "63739279f8aaa1aa.html" click isExtensionUI "d32bf4175ca1ff44.html" click buildQuickSelector "077a2e134af1a6be.html" click now "b0f01bcc017e0081.html" click addStep "012da91201f9487b.html" click buildStep "6d1088fe63d8f4bc.html"
TargetType
isExtensionUI calls
buildQuickSelector calls
now calls
addStep calls
buildStep calls

No incoming dependencies.