refactor: move throttling to filter function

This commit is contained in:
H1ghBre4k3r 2024-06-19 12:48:09 +02:00
parent d82685a74e
commit 02e2a56cf5
No known key found for this signature in database

View File

@ -42,7 +42,7 @@
let filterText: string | undefined = undefined; let filterText: string | undefined = undefined;
let filteredItems: Selectable[] = items; let filteredItems: Selectable[] = items;
function filterItems(items: Selectable[], filterText: string | undefined) { const filterItems = throttle((items: Selectable[], filterText: string | undefined) => {
if (!filterText) { if (!filterText) {
return items; return items;
} }
@ -52,7 +52,7 @@
if (!isStr(property)) return false; if (!isStr(property)) return false;
return property.includes(filterText); return property.includes(filterText);
}); });
} }, INPUT_THROTTLE_TIME);
$: filteredItems = filterItems(items, filterText); $: filteredItems = filterItems(items, filterText);
@ -111,13 +111,13 @@
} }
} }
const handleChar = throttle((char: string) => { function handleChar(char: string) {
highlightIndex = undefined; highlightIndex = undefined;
filterText ??= ''; filterText ??= '';
filterText += char; filterText += char;
}, INPUT_THROTTLE_TIME); }
const handleDelete = throttle(() => { function handleDelete() {
if (filterText === undefined) return; if (filterText === undefined) return;
if (filterText.length === 1) { if (filterText.length === 1) {
@ -126,7 +126,7 @@
} }
filterText = filterText.slice(0, -1); filterText = filterText.slice(0, -1);
}, INPUT_THROTTLE_TIME); }
function handleKeyDown(e: CustomEvent<KeyboardEvent>) { function handleKeyDown(e: CustomEvent<KeyboardEvent>) {
if (!listOpen) { if (!listOpen) {