Skip to content

Commit a7c62ca

Browse files
committed
allow enable to be function
1 parent ed9539c commit a7c62ca

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

examples/svelte/svelte-melt/src/routes/paginate.svelte

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
import { createQuery, useQueryClient } from 'svelte-query/dev';
33
import { bookFilterStore } from './store.svelte';
44
import { unstate } from 'svelte';
5+
import { useQuery } from './external';
6+
import { useSvelteExtensionQuery } from './external.svelte';
57
let a = { a: 1 };
68
let b = ['hi', bookFilterStore];
79
const data = createQuery(() => {
810
return {
911
queryKey: ['paginate', bookFilterStore],
1012
queryFn: async () => {
11-
debugger;
1213
const s = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'].map((v) => {
1314
return { title: v };
1415
});
@@ -21,6 +22,8 @@
2122
enabled: bookFilterStore.paginate.page % 2 == 1
2223
};
2324
});
25+
const external = useQuery(bookFilterStore);
26+
const externalsv = useSvelteExtensionQuery(bookFilterStore);
2427
/* const querycache = useQueryClient().getQueryCache();
2528
$effect(() => {
2629
if (data.fetchStatus) {
@@ -53,3 +56,8 @@
5356
{#each data?.data ?? [] as item}
5457
<div>{item.title}</div>
5558
{/each}
59+
60+
-------------
61+
{external.data}
62+
-------------
63+
{externalsv.data}

packages/svelte-query-runes/src/createBaseQuery.svelte.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ export function createBaseQuery<
3939
const defaultedOptions = client.defaultQueryOptions({
4040
...optionsStore(),
4141
//@ts-ignore
42-
queryKey: queryKey, // prevent reactive query in devTools
42+
queryKey: queryKey, // prevent reactive query in devTools,
43+
enabled:
44+
typeof optionsStore().enabled == 'function'
45+
? optionsStore().enabled()
46+
: optionsStore().enabled,
4347
})
4448

4549
defaultedOptions._optimisticResults == isRestoring

0 commit comments

Comments
 (0)