Skip to content

Commit 5ad9859

Browse files
feat: unref useQueries options (#230)
1 parent c0fde8b commit 5ad9859

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

examples/basic/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"dependencies": {
1010
"vue": "3.2.27",
11-
"vue-query": ">=1.0.0"
11+
"vue-query": "^1.25.2"
1212
},
1313
"devDependencies": {
1414
"@vitejs/plugin-vue": "2.0.1",

examples/nuxt-simple/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"@nuxtjs/composition-api": "^0.28.0",
1313
"nuxt": "^2.0.0",
14-
"vue-query": ">=1.0.0"
14+
"vue-query": "^1.25.2"
1515
},
1616
"devDependencies": {
1717
"babel-eslint": "^10.0.1",

src/vue/useQueries.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
reactive,
66
readonly,
77
watch,
8-
unref,
98
Ref,
109
isRef,
1110
isReactive,
@@ -18,6 +17,7 @@ import type {
1817

1918
import { useQueryClient } from "./useQueryClient";
2019
import { UseQueryOptions } from "./useQuery";
20+
import { cloneDeepUnref } from "./utils";
2121

2222
// Avoid TS depth-limit error in case of large array literal
2323
type MAXIMUM_DEPTH = 20;
@@ -138,28 +138,28 @@ type UseQueriesOptionsArg<T extends any[]> = readonly [...UseQueriesOptions<T>];
138138
export function useQueries<T extends any[]>(
139139
queries: Ref<UseQueriesOptionsArg<T>> | UseQueriesOptionsArg<T>
140140
): Readonly<UseQueriesResults<T>> {
141-
const queryClientKey = (unref(queries) as UseQueriesOptionsArg<T>)[0]
142-
?.queryClientKey;
141+
const unreffedQueries = cloneDeepUnref(queries) as UseQueriesOptionsArg<T>;
142+
143+
const queryClientKey = unreffedQueries[0]?.queryClientKey;
143144
const queryClient = useQueryClient(queryClientKey);
144-
const defaultedQueries = (unref(queries) as UseQueriesOptionsArg<T>).map(
145-
(options) => {
146-
return queryClient.defaultQueryObserverOptions(options);
147-
}
148-
);
145+
const defaultedQueries = unreffedQueries.map((options) => {
146+
return queryClient.defaultQueryObserverOptions(options);
147+
});
149148

150149
const observer = new QueriesObserver(queryClient, defaultedQueries);
151150
const state = reactive(observer.getCurrentResult());
151+
152152
const unsubscribe = observer.subscribe((result) => {
153153
state.splice(0, state.length, ...result);
154154
});
155155

156156
if (isRef(queries) || isReactive(queries)) {
157157
watch(queries, () => {
158-
const defaulted = (unref(queries) as UseQueriesOptionsArg<T>).map(
159-
(options) => {
160-
return queryClient.defaultQueryObserverOptions(options);
161-
}
162-
);
158+
const defaulted = (
159+
cloneDeepUnref(queries) as UseQueriesOptionsArg<T>
160+
).map((options) => {
161+
return queryClient.defaultQueryObserverOptions(options);
162+
});
163163
observer.setQueries(defaulted);
164164
});
165165
}

0 commit comments

Comments
 (0)