refactor: replace debounce/throttle deps with first-party code (#38610)

Adds `web_src/js/utils/func.ts` with `debounce` and `throttle`, dropping
`throttle-debounce` and `perfect-debounce` dependencies. Both were
needed before: the former has no promise-returning debounce, which
`TextExpander` requires, and the latter no `throttle`.

Signature follows lodash and es-toolkit: `(func, wait, {leading,
trailing})` plus `cancel`, so argument order flips at the migrated call
sites.
This commit is contained in:
silverwind
2026-07-24 18:39:15 +02:00
committed by GitHub
parent 1e42317b66
commit 66794e0549
12 changed files with 173 additions and 44 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
import {debounce} from 'throttle-debounce';
import {debounce} from '../utils/func.ts';
import {GET} from './fetch.ts';
import {errorName} from './errors.ts';
import {html, htmlRaw} from '../utils/html.ts';
@@ -69,7 +69,7 @@ export function attachSearchBox<T = unknown>(container: HTMLElement, url: string
hide();
};
const search = debounce(200, async (query: string) => {
const search = debounce(async (query: string) => {
fetchController?.abort();
if (query.length < minCharacters) return hide();
const ctrl = (fetchController = new AbortController());
@@ -82,7 +82,7 @@ export function attachSearchBox<T = unknown>(container: HTMLElement, url: string
} catch (err) {
if (errorName(err) !== 'AbortError') hide();
}
});
}, 200);
// cancel + hide ensures a debounced fetch scheduled before any of these can't fire afterwards
const dismiss = () => { search.cancel(); hide() };