Skip to content

Commit

Permalink
Simplify range onChange handler
Browse files Browse the repository at this point in the history
  • Loading branch information
kurgm committed Jan 7, 2024
1 parent 5c2ff4f commit b070939
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions interactive/src/slim_ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,16 @@ const controlnames: (keyof InputParam)[] = [
];
const controls: HTMLInputElement[] = [];
const controlr: (HTMLInputElement | null)[] = [];
const controlf = {} as Record<keyof InputParam, () => void>;
const anonchgf = controlchgf_maker();
controlnames.forEach((controlname, i) => {
controls[i] = pform.elements.namedItem(controlname) as HTMLInputElement;
controlr[i] = pform.elements.namedItem(`range_${controlname}`) as HTMLInputElement | null;
const f = controlf[controlname] = controlchgf_maker(controlname);
const f = controlchgf_maker(controlname);
controls[i].addEventListener("change", f);
controlr[i]?.addEventListener("change", rangechgf_maker(controlname));
controlr[i]?.addEventListener("change", () => {
controls[i].value = controlr[i]!.value;
f();
});
});
(pform.elements.namedItem("text") as HTMLInputElement).addEventListener("keyup", anonchgf);
(pform.elements.namedItem("autosubmit") as HTMLInputElement).addEventListener("change", () => {
Expand Down Expand Up @@ -138,12 +140,6 @@ function controlchgf_maker(name?: keyof InputParam) {
formsubfunc();
};
}
function rangechgf_maker(name: keyof InputParam) {
return () => {
(pform.elements.namedItem(name) as HTMLInputElement).value = (pform.elements.namedItem(`range_${name}`) as HTMLInputElement).value;
controlf[name]();
}
}
const formsubfunc = () => {
const map = limForm();
setValues({
Expand Down

0 comments on commit b070939

Please sign in to comment.