Skip to content

Commit

Permalink
allow enable to be function
Browse files Browse the repository at this point in the history
  • Loading branch information
zhihengGet committed Feb 28, 2024
1 parent ed9539c commit a7c62ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 9 additions & 1 deletion examples/svelte/svelte-melt/src/routes/paginate.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import { createQuery, useQueryClient } from 'svelte-query/dev';
import { bookFilterStore } from './store.svelte';
import { unstate } from 'svelte';
import { useQuery } from './external';
import { useSvelteExtensionQuery } from './external.svelte';
let a = { a: 1 };
let b = ['hi', bookFilterStore];
const data = createQuery(() => {
return {
queryKey: ['paginate', bookFilterStore],
queryFn: async () => {
debugger;
const s = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'].map((v) => {
return { title: v };
});
Expand All @@ -21,6 +22,8 @@
enabled: bookFilterStore.paginate.page % 2 == 1
};
});
const external = useQuery(bookFilterStore);
const externalsv = useSvelteExtensionQuery(bookFilterStore);
/* const querycache = useQueryClient().getQueryCache();
$effect(() => {
if (data.fetchStatus) {
Expand Down Expand Up @@ -53,3 +56,8 @@
{#each data?.data ?? [] as item}
<div>{item.title}</div>
{/each}

-------------
{external.data}
-------------
{externalsv.data}
6 changes: 5 additions & 1 deletion packages/svelte-query-runes/src/createBaseQuery.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ export function createBaseQuery<
const defaultedOptions = client.defaultQueryOptions({
...optionsStore(),
//@ts-ignore
queryKey: queryKey, // prevent reactive query in devTools
queryKey: queryKey, // prevent reactive query in devTools,
enabled:
typeof optionsStore().enabled == 'function'
? optionsStore().enabled()
: optionsStore().enabled,
})

defaultedOptions._optimisticResults == isRestoring
Expand Down

0 comments on commit a7c62ca

Please sign in to comment.