Skip to content

Commit a31b4ce

Browse files
committed
fix useFind to return empty array when null params
1 parent 2cf2f5c commit a31b4ce

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/useFind.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,27 @@ export default function find(options: UseFindOptions): UseFindData {
9797
items: computed<any[]>(() => {
9898
const getterParams = unwrapParams(params)
9999

100-
if (getterParams && getterParams.paginate) {
101-
const serviceState = model.store.state[model.servicePath]
102-
const { defaultSkip, defaultLimit } = serviceState.pagination
103-
const skip = getterParams.query.$skip || defaultSkip
104-
const limit = getterParams.query.$limit || defaultLimit
105-
const pagination =
106-
computes.paginationData.value[getterParams.qid || state.qid] || {}
107-
const response = skip != null && limit != null ? { limit, skip } : {}
108-
const queryInfo = getQueryInfo(getterParams, response)
109-
const items = getItemsFromQueryInfo(
110-
pagination,
111-
queryInfo,
112-
serviceState.keyedById
113-
)
114-
return items
100+
if (getterParams) {
101+
if (getterParams.paginate) {
102+
const serviceState = model.store.state[model.servicePath]
103+
const { defaultSkip, defaultLimit } = serviceState.pagination
104+
const skip = getterParams.query.$skip || defaultSkip
105+
const limit = getterParams.query.$limit || defaultLimit
106+
const pagination =
107+
computes.paginationData.value[getterParams.qid || state.qid] || {}
108+
const response = skip != null && limit != null ? { limit, skip } : {}
109+
const queryInfo = getQueryInfo(getterParams, response)
110+
const items = getItemsFromQueryInfo(
111+
pagination,
112+
queryInfo,
113+
serviceState.keyedById
114+
)
115+
return items
116+
} else {
117+
return model.findInStore(getterParams).data
118+
}
115119
} else {
116-
return model.findInStore(getterParams).data
120+
return []
117121
}
118122
}),
119123
paginationData: computed(() => {
@@ -128,7 +132,7 @@ export default function find(options: UseFindOptions): UseFindData {
128132
state.isPending = true
129133
state.haveBeenRequested = true
130134

131-
return model.find(params).then((response) => {
135+
return model.find(params).then(response => {
132136
// To prevent thrashing, only clear error on response, not on initial request.
133137
state.error = null
134138
state.haveLoaded = true

0 commit comments

Comments
 (0)