@@ -141,7 +141,7 @@ export type SearchSourceOptions = {
141141} ;
142142
143143const DEFAULT_SEARCH_SOURCE_OPTIONS : Required < SearchSourceOptions > = {
144- debounceMs : 5000 ,
144+ debounceMs : 300 ,
145145 isActive : false ,
146146 pageSize : 10 ,
147147} as const ;
@@ -224,19 +224,21 @@ export abstract class BaseSearchSource<T> implements SearchSource<T> {
224224 this . state . partialNext ( { isActive : false } ) ;
225225 } ;
226226
227- async executeQuery ( searchQuery : string ) {
228- const hasNewSearchQuery = typeof searchQuery !== 'undefined' ;
229- if ( ! this . isActive || this . isLoading || ! this . hasMore || ! searchQuery ) return ;
227+ async executeQuery ( newSearchString ?: string ) {
228+ const hasNewSearchQuery = typeof newSearchString !== 'undefined' ;
229+ const searchString = newSearchString ?? this . searchQuery ;
230+ if ( ! this . isActive || this . isLoading || ( ! this . hasMore && ! hasNewSearchQuery ) || ! searchString )
231+ return ;
230232
231233 if ( hasNewSearchQuery ) {
232- this . resetState ( { isActive : this . isActive , isLoading : true , searchQuery } ) ;
234+ this . resetState ( { isActive : this . isActive , isLoading : true , searchQuery : newSearchString } ) ;
233235 } else {
234236 this . state . partialNext ( { isLoading : true } ) ;
235237 }
236238
237239 const stateUpdate : Partial < SearchSourceState < T > > = { } ;
238240 try {
239- const results = await this . query ( searchQuery ) ;
241+ const results = await this . query ( searchString ) ;
240242 if ( ! results ) return ;
241243 const { items, next } = results ;
242244
@@ -265,7 +267,7 @@ export abstract class BaseSearchSource<T> implements SearchSource<T> {
265267 search = async ( searchQuery ?: string ) => {
266268 await new Promise ( ( resolve ) => {
267269 this . resolveDebouncedSearch = resolve ;
268- this . searchDebounced ( searchQuery ?? this . searchQuery ) ;
270+ this . searchDebounced ( searchQuery ) ;
269271 } ) ;
270272 } ;
271273
0 commit comments