mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-02 20:19:41 +00:00
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:
@@ -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() };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user