-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7c62ca
commit 4974ba8
Showing
11 changed files
with
2,352 additions
and
1,408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
export const csr = true; | ||
|
||
export const ssr = false; |
53 changes: 53 additions & 0 deletions
53
examples/svelte/svelte-melt/src/routes/derivedQuery.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<script lang="ts"> | ||
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]; | ||
let p = $derived({ derived_state: bookFilterStore.paginate.page + 1 }); | ||
function query(p) { | ||
const data = createQuery({ | ||
queryKey: () => ['paginate', b], | ||
queryFn: async () => { | ||
const s = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'].map((v) => { | ||
return { title: v }; | ||
}); | ||
if (Math.abs(bookFilterStore.paginate.page % 2) == 1) { | ||
return s.slice(0, 5); | ||
} | ||
return s.slice(5, 6); | ||
}, | ||
staleTime: 5000, | ||
enabled: bookFilterStore.paginate.page % 2 == 1 | ||
}); | ||
return data; | ||
} | ||
let data = query(p); | ||
</script> | ||
|
||
<h2>testing derived query with list</h2> | ||
|
||
{data.fetchStatus} | ||
{data.isLoading} | ||
{data.isFetching} | ||
{data.isRefetching} | ||
<button | ||
onclick={() => { | ||
console.log('click +1'); | ||
bookFilterStore.paginate.page += 1; | ||
// p += 1; | ||
}}>next</button | ||
> | ||
<button | ||
onclick={() => { | ||
console.log('click -1'); | ||
bookFilterStore.paginate.page -= 1; | ||
// p += 1; | ||
}}>prev</button | ||
> | ||
{bookFilterStore.paginate.page} | ||
{#each data?.data ?? [] as item} | ||
<div>{item.title}</div> | ||
{/each} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { createQuery } from 'svelte-query/dev'; | ||
export function useSvelteExtensionQuery(props) { | ||
const enabled = $derived({ | ||
queryKey: ['sv-externel', props], | ||
queryFn: () => { | ||
return Date.now(); | ||
}, | ||
enabled: () => props.paginate.page > 0 | ||
}); | ||
return createQuery(enabled); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createQuery } from 'svelte-query'; | ||
export function useQuery(props) { | ||
return createQuery({ | ||
queryKey: ['eternal', props], | ||
queryFn: () => { | ||
return Date.now(); | ||
}, | ||
enabled: props.paginate.page > 0 | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.