Commit 539b422 1 parent 542e7a3 commit 539b422 Copy full SHA for 539b422
File tree 1 file changed +15
-1
lines changed
popgetter-browser/web/src/routes
1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 198
198
console .log (data );
199
199
}
200
200
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
+
201
215
let min = 0 ;
202
216
let max = 0 ;
203
217
266
280
267
281
<!-- Search -->
268
282
<section id =" query-section" >
269
- <Search bind:searchTerm on:input ={handleInput } />
283
+ <Search bind:searchTerm on:input ={debouncedHandleInput } />
270
284
</section >
271
285
272
286
<!-- TODO: convert table for search results into component -->
You can’t perform that action at this time.
0 commit comments