Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/framework/react/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function App() {

### Options

- `initialIsOpen: Boolean`
- `initialIsOpen: boolean`
- Set this `true` if you want the dev tools to default to being open
- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | "relative"`
- Defaults to `bottom-right`
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/solid/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function App() {

### Options

- `initialIsOpen: Boolean`
- `initialIsOpen: boolean`
- Set this `true` if you want the dev tools to default to being open
- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right"`
- Defaults to `bottom-right`
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/svelte/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Place the following code as high in your Svelte app as you can. The closer it is

### Options

- `initialIsOpen: Boolean`
- `initialIsOpen: boolean`
- Set this `true` if you want the dev tools to default to being open
- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | "relative"`
- Defaults to `bottom-right`
Expand Down
8 changes: 2 additions & 6 deletions docs/framework/svelte/reactivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ In the below example, the `refetchInterval` option is set from the variable `int
<script lang="ts">
import { createQuery } from '@tanstack/svelte-query'

const endpoint = 'http://localhost:5173/api/data'

let intervalMs = 1000

const query = createQuery({
queryKey: ['refetch'],
queryFn: async () => await fetch(endpoint).then((r) => r.json()),
queryFn: async () => await fetch('/api/data').then((r) => r.json()),
refetchInterval: intervalMs,
})
</script>
Expand All @@ -32,14 +30,12 @@ To solve this, we can convert `intervalMs` into a writable store. The query opti
import { derived, writable } from 'svelte/store'
import { createQuery } from '@tanstack/svelte-query'

const endpoint = 'http://localhost:5173/api/data'

const intervalMs = writable(1000)

const query = createQuery(
derived(intervalMs, ($intervalMs) => ({
queryKey: ['refetch'],
queryFn: async () => await fetch(endpoint).then((r) => r.json()),
queryFn: async () => await fetch('/api/data').then((r) => r.json()),
refetchInterval: $intervalMs,
})),
)
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/vue/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import { VueQueryDevtools } from '@tanstack/vue-query-devtools'

### Options

- `initialIsOpen: Boolean`
- `initialIsOpen: boolean`
- Set this `true` if you want the dev tools to default to being open.
- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right"`
- Defaults to `bottom-right`.
Expand Down
8 changes: 5 additions & 3 deletions examples/svelte/auto-refetching/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

const client = useQueryClient()

const endpoint = 'http://localhost:5173/api/data'
const endpoint = '/api/data'

$: todos = createQuery<{ items: string[] }>({
queryKey: ['refetch'],
Expand All @@ -21,7 +21,9 @@

const addMutation = createMutation({
mutationFn: (value: string) =>
fetch(`${endpoint}?add=${value}`).then((r) => r.json()),
fetch(`${endpoint}?add=${encodeURIComponent(value)}`).then((r) =>
r.json(),
),
onSuccess: () => client.invalidateQueries({ queryKey: ['refetch'] }),
})

Expand All @@ -31,7 +33,7 @@
})
</script>

<h1>Auto Refetch with stale-time set to 1s</h1>
<h1>Auto Refetch with stale-time set to {intervalMs}ms</h1>

<p>
This example is best experienced on your own machine, where you can open
Expand Down
3 changes: 0 additions & 3 deletions examples/svelte/auto-refetching/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'

/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: vitePreprocess(),

kit: {
adapter: adapter(),
},
Expand Down
3 changes: 0 additions & 3 deletions examples/svelte/basic/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'

/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: vitePreprocess(),

kit: {
adapter: adapter(),
},
Expand Down
2 changes: 1 addition & 1 deletion examples/svelte/optimistic-updates/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

const client = useQueryClient()

const endpoint = 'http://localhost:5173/api/data'
const endpoint = '/api/data'

const fetchTodos = async (): Promise<Todos> =>
await fetch(endpoint).then((r) => r.json())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Todo = {
text: string
}

const items: Todo[] = []
const items: Array<Todo> = []

/** @type {import('./$types').RequestHandler} */
export const GET: RequestHandler = async (req) => {
Expand Down
3 changes: 0 additions & 3 deletions examples/svelte/optimistic-updates/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'

/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: vitePreprocess(),

kit: {
adapter: adapter(),
},
Expand Down
1 change: 0 additions & 1 deletion examples/svelte/playground/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: vitePreprocess(),

kit: {
adapter: adapter(),
},
Expand Down
2 changes: 0 additions & 2 deletions examples/svelte/simple/svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'

export default {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: vitePreprocess(),
}
2 changes: 1 addition & 1 deletion examples/svelte/ssr/src/routes/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { browser } from '$app/environment'
import { QueryClient } from '@tanstack/svelte-query'
import type { LayoutLoad } from './$types'

export const load: LayoutLoad = async () => {
export const load: LayoutLoad = () => {
const queryClient = new QueryClient({
defaultOptions: {
queries: {
Expand Down
3 changes: 0 additions & 3 deletions examples/svelte/ssr/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'

/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: vitePreprocess(),

kit: {
adapter: adapter(),
},
Expand Down
3 changes: 1 addition & 2 deletions examples/svelte/star-wars/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<h2 class="text-4xl">React Query Demo</h2>
<p>Using the Star Wars API</p>
<p>
(Built by <a href="https://twitter.com/Brent_m_Clark">@Brent_m_Clark</a>
)
(Built by <a href="https://twitter.com/Brent_m_Clark">@Brent_m_Clark</a>)
</p>
<section>
<h5 class="text-2xl">Why React Query?</h5>
Expand Down
1 change: 0 additions & 1 deletion examples/svelte/star-wars/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: vitePreprocess(),

kit: {
adapter: adapter(),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@

<div>Data: {$mutation.data?.count ?? 'undefined'}</div>
<div>Status: {$mutation.status}</div>
<div>Failure Count: {$mutation.failureCount ?? 'undefined'}</div>
<div>Failure Reason: {$mutation.failureReason ?? 'null'}</div>
<div>Failure Count: {$mutation.failureCount}</div>
<div>Failure Reason: {$mutation.failureReason ?? 'undefined'}</div>
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ describe('createMutation', () => {
expect(rendered.getByText('Status: success')).toBeInTheDocument()
expect(rendered.getByText('Data: 2')).toBeInTheDocument()
expect(rendered.getByText('Failure Count: 0')).toBeInTheDocument()
expect(rendered.getByText('Failure Reason: null')).toBeInTheDocument()
expect(rendered.getByText('Failure Reason: undefined')).toBeInTheDocument()
})
})
11 changes: 5 additions & 6 deletions packages/svelte-query/tests/useMutationState/BaseExample.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
const errorMutation = createMutation(errorMutationOpts)

const mutationState = useMutationState(mutationStateOpts)
$: statuses = $mutationState.map((state) => state.status)
</script>

<div data-testid="result">
{JSON.stringify(statuses)}
</div>
<button on:click={() => $successMutation.mutate()}>Success</button>
<button on:click={() => $errorMutation.mutate()}>Error</button>

<button on:click={() => $successMutation.mutate()}>success</button>
<button on:click={() => $errorMutation.mutate()}>error</button>
<div>
Data: {JSON.stringify($mutationState.map((state) => state.status))}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ describe('useMutationState', () => {
},
})

fireEvent.click(rendered.getByText('success'))
fireEvent.click(rendered.getByRole('button', { name: /Success/i }))
await vi.advanceTimersByTimeAsync(11)
expect(successMutationFn).toHaveBeenCalledTimes(1)
expect(rendered.getByText('["success"]')).toBeInTheDocument()
expect(rendered.getByText('Data: ["success"]')).toBeInTheDocument()

fireEvent.click(rendered.getByText('error'))
fireEvent.click(rendered.getByRole('button', { name: /Error/i }))
await vi.advanceTimersByTimeAsync(21)
expect(errorMutationFn).toHaveBeenCalledTimes(1)
expect(rendered.getByText('["success","error"]')).toBeInTheDocument()
expect(rendered.getByText('Data: ["success","error"]')).toBeInTheDocument()
})

test('Can select specific type of mutation ( i.e: error only )', async () => {
Expand All @@ -68,15 +68,15 @@ describe('useMutationState', () => {
},
})

fireEvent.click(rendered.getByText('success'))
fireEvent.click(rendered.getByRole('button', { name: /Success/i }))
await vi.advanceTimersByTimeAsync(11)
expect(successMutationFn).toHaveBeenCalledTimes(1)
expect(rendered.getByText('[]')).toBeInTheDocument()
expect(rendered.getByText('Data: []')).toBeInTheDocument()

fireEvent.click(rendered.getByText('error'))
fireEvent.click(rendered.getByRole('button', { name: /Error/i }))
await vi.advanceTimersByTimeAsync(21)
expect(errorMutationFn).toHaveBeenCalledTimes(1)
expect(rendered.getByText('["error"]')).toBeInTheDocument()
expect(rendered.getByText('Data: ["error"]')).toBeInTheDocument()
})

test('Can select specific mutation using mutation key', async () => {
Expand All @@ -103,14 +103,14 @@ describe('useMutationState', () => {
},
})

fireEvent.click(rendered.getByText('success'))
fireEvent.click(rendered.getByRole('button', { name: /Success/i }))
await vi.advanceTimersByTimeAsync(11)
expect(successMutationFn).toHaveBeenCalledTimes(1)
expect(rendered.getByText('["success"]')).toBeInTheDocument()
expect(rendered.getByText('Data: ["success"]')).toBeInTheDocument()

fireEvent.click(rendered.getByText('error'))
fireEvent.click(rendered.getByRole('button', { name: /Error/i }))
await vi.advanceTimersByTimeAsync(21)
expect(errorMutationFn).toHaveBeenCalledTimes(1)
expect(rendered.getByText('["success"]')).toBeInTheDocument()
expect(rendered.getByText('Data: ["success"]')).toBeInTheDocument()
})
})
Loading