Skip to content

Commit 539b422

Browse files
committed
Add debounce
1 parent 542e7a3 commit 539b422

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

popgetter-browser/web/src/routes/DownloadMode.svelte

+15-1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,20 @@
198198
console.log(data);
199199
}
200200
201+
// Add debounce to input function so backend search only called after `delay`ms
202+
function debounce(func, delay) {
203+
let timeout;
204+
return function (...args) {
205+
// Clear previous timeout
206+
clearTimeout(timeout);
207+
// Set new timeout
208+
timeout = setTimeout(() => {
209+
func.apply(this, args);
210+
}, delay);
211+
};
212+
}
213+
const debouncedHandleInput = debounce(handleInput, 300);
214+
201215
let min = 0;
202216
let max = 0;
203217
@@ -266,7 +280,7 @@
266280

267281
<!-- Search -->
268282
<section id="query-section">
269-
<Search bind:searchTerm on:input={handleInput} />
283+
<Search bind:searchTerm on:input={debouncedHandleInput} />
270284
</section>
271285

272286
<!-- TODO: convert table for search results into component -->

0 commit comments

Comments
 (0)