@@ -2373,12 +2373,16 @@ export class DeepClient<L extends Link<Id> = Link<Id>> implements DeepClientInst
2373
2373
const o = { remote : true , count : false , sort : true , ...options } ;
2374
2374
const query = this . searchQuery ( value , o ) ;
2375
2375
let results ;
2376
- if ( o . remote ) {
2376
+ if ( o . skip ) {
2377
+ results = { data : [ ] } ;
2378
+ } if ( o . remote ) {
2377
2379
results = await this . select ( query , { apply : o . apply , ...( o . count ? { aggregate : 'count' } : { } ) } ) ;
2378
2380
} else {
2379
2381
results = { data : this . minilinks . select ( query , { ...( o . count ? { aggregate : 'count' } : { } ) } ) , query } ;
2380
2382
}
2381
- if ( o . sort ) {
2383
+ if ( o . skip ) {
2384
+ results . ids = { } ;
2385
+ } if ( o . sort ) {
2382
2386
const sorted = sort ( results . data , value ) ;
2383
2387
results . data = sorted . data ;
2384
2388
results . ids = sorted . ids ;
@@ -2729,16 +2733,16 @@ export function useDeepQuery<Table extends 'links'|'numbers'|'strings'|'objects'
2729
2733
originalData : o ?. aggregate ? result ?. data ?. q0 ?. aggregate : result ?. data ?. q0 ,
2730
2734
data : generated . data ,
2731
2735
loading : generated . loading ,
2732
- options : o ,
2736
+ options : o , //
2733
2737
deep,
2734
- links : [ ] ,
2735
- plainLinks : [ ] ,
2738
+ links : [ ] , //
2739
+ plainLinks : [ ] , //
2736
2740
// @ts -ignore
2737
2741
return : q ?. return ,
2738
2742
name : miniName ,
2739
2743
} ;
2740
2744
const { data : minilinksResults , plainLinks } = useMinilinksApply ( deep . minilinks , miniName , toReturn ) ;
2741
- toReturn . data = o ?. aggregate || o ?. table !== 'links' ? toReturn . data || [ ] : minilinksResults ;
2745
+ toReturn . data = o ?. aggregate || o ?. table !== 'links' ? toReturn . data || [ ] : minilinksResults ; //
2742
2746
toReturn . links = minilinksResults ;
2743
2747
toReturn . plainLinks = plainLinks ;
2744
2748
useMemo ( ( ) => {
@@ -2856,23 +2860,29 @@ export function sort(links, value) {
2856
2860
} ;
2857
2861
}
2858
2862
2863
+ const defaultEmptyResults = { ids : { } , data : [ ] } ;
2859
2864
export function useSearch ( value : string , options : DeepSearchOptions = { } ) {
2860
2865
const deep = useDeep ( ) ;
2861
- const o = useMemo ( ( ) => ( { skip : false , remote : true , count : false , sort : true , ...options } ) , [ options ] ) ;
2866
+ const prevOptionsRef = useRef < any > ( ) ;
2867
+ const o = useMemo ( ( ) => {
2868
+ const newPrev = { skip : false , remote : true , count : false , sort : true , ...options } ;
2869
+ if ( ! isEqual ( prevOptionsRef . current , newPrev ) ) prevOptionsRef . current = newPrev ;
2870
+ return prevOptionsRef . current ;
2871
+ } , [ options ] ) ;
2862
2872
const query = useMemo ( ( ) => this . searchQuery ( value , o ) , [ value , o ] ) ;
2863
2873
const qo = useMemo ( ( ) => ( { ...( o . count ? { aggregate : 'count' } : { } ) , skip : o . skip } ) , [ o . count , o . skip ] ) ;
2864
2874
const useHook = useMemo ( ( ) => o . remote ? o . subscription ? deep . useSubscription : deep . useQuery : deep . useLocalQuery , [ o . remote , o . subscription ] ) ;
2865
2875
const { _q, _o } = useDebouncedInput ( query , qo , options ?. debounce ) ;
2866
2876
const _results : any = useHook ( _q , _o as any ) ;
2867
- const results = o . remote ? _results : { data : _results } ;
2877
+ const results = useMemo ( ( ) => o . remote ? _results : { data : _results } , [ _results ] ) ;
2868
2878
if ( o . sort ) {
2869
- const sorted = useMemo ( ( ) => sort ( results . data , value ) , [ results . data ] ) ;
2879
+ const sorted = useMemo ( ( ) => o . skip ? defaultEmptyResults : sort ( results . data , value ) , [ results . data ] ) ;
2870
2880
results . data = sorted . data ;
2871
2881
results . ids = sorted . ids ;
2872
2882
} else {
2873
2883
results . ids = useMemo ( ( ) => {
2874
2884
const ids = { } ;
2875
- if ( results ?. data ?. length ) for ( let i = 0 ; i < results . data . length ; i ++ ) ids [ results ?. data ?. [ i ] ?. id ] = results ?. data ?. [ i ] ;
2885
+ if ( o . skip && results ?. data ?. length ) for ( let i = 0 ; i < results . data . length ; i ++ ) ids [ results ?. data ?. [ i ] ?. id ] = results ?. data ?. [ i ] ;
2876
2886
return ids ;
2877
2887
} , [ results . data ] ) ;
2878
2888
}
0 commit comments