@@ -13,21 +13,11 @@ import {
13
13
import { getQueryInfo , getItemsFromQueryInfo , Params } from './utils'
14
14
import debounce from 'lodash/debounce'
15
15
16
- const defaults = {
17
- model : null ,
18
- params : null ,
19
- queryWhen : ( ) : boolean => true ,
20
- qid : 'default' ,
21
- local : false ,
22
- lazy : false
23
- }
24
-
25
16
interface UseFindOptions {
26
17
model : Function
27
18
params : Params | Ref < Params >
28
19
fetchParams ?: Params | Ref < Params >
29
- name ?: string
30
- queryWhen ?: Function
20
+ queryWhen ?: Ref < Function >
31
21
qid ?: string
32
22
lazy ?: boolean
33
23
}
@@ -50,15 +40,20 @@ interface UseFindData {
50
40
isLocal : Ref < boolean >
51
41
qid : Ref < string >
52
42
debounceTime : Ref < number >
53
- find : Function
54
- findInStore : Function
55
43
latestQuery : Ref < object >
56
44
paginationData : Ref < object >
57
- queryWhen : Ref < boolean >
58
45
error : Ref < Error >
59
46
}
60
47
61
48
export default function find ( options : UseFindOptions ) : UseFindData {
49
+ const defaults = {
50
+ model : null ,
51
+ params : null ,
52
+ qid : 'default' ,
53
+ queryWhen : computed ( ( ) : boolean => true ) ,
54
+ local : false ,
55
+ lazy : false
56
+ }
62
57
const { model, params, queryWhen, qid, local, lazy } = Object . assign (
63
58
{ } ,
64
59
defaults ,
@@ -122,7 +117,6 @@ export default function find(options: UseFindOptions): UseFindData {
122
117
return model . findInStore ( getterParams ) . data
123
118
}
124
119
} ) ,
125
- queryWhen : computed < boolean > ( ( ) => queryWhen ( ) ) ,
126
120
paginationData : computed ( ( ) => {
127
121
return model . store . state [ model . servicePath ] . pagination
128
122
} ) ,
@@ -131,7 +125,7 @@ export default function find(options: UseFindOptions): UseFindData {
131
125
132
126
function find < T > ( params : Params ) : T {
133
127
params = isRef ( params ) ? params . value : params
134
- if ( computes . queryWhen . value ) {
128
+ if ( queryWhen . value && ! state . isLocal ) {
135
129
state . isFindPending = true
136
130
state . haveBeenRequestedOnce = true
137
131
@@ -181,8 +175,6 @@ export default function find(options: UseFindOptions): UseFindData {
181
175
182
176
return {
183
177
...computes ,
184
- ...toRefs ( state ) ,
185
- find : model . find ,
186
- findInStore : model . findInStore
178
+ ...toRefs ( state )
187
179
}
188
180
}
0 commit comments