function debounce(fn, wait = 250) { let timer; const run = (...args) => { clearTimeout(timer); timer = setTimeout(() => fn(...args), wait); }; run.cancel = () => clearTimeout(timer); return run; }