-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat(svelte-query): add 'mutationOptions' #10175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sukvvon
wants to merge
9
commits into
TanStack:main
Choose a base branch
from
sukvvon:feat/svelte-query-mutationOptions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+792
−0
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
39e5552
feat(svelte-query/mutationOptions): add 'mutationOptions' identity fu…
sukvvon fcb54ce
test(svelte-query/mutationOptions): add type and runtime tests for 'm…
sukvvon 7043b32
docs(svelte-query/mutationOptions): add reference documentation for '…
sukvvon 361ae41
chore(svelte-query): add changeset for 'mutationOptions'
sukvvon 0cf934c
ci: apply automated fixes
autofix-ci[bot] 5048011
test(svelte-query/mutationOptions): use 'Accessor' type for props in …
sukvvon 0e027fe
style(svelte-query/mutationOptions): remove blank lines between 'fire…
sukvvon ce75bf2
refactor(svelte-query/mutationOptions): split BaseExample into BaseEx…
sukvvon 3383e4c
ci: apply automated fixes
autofix-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| '@tanstack/svelte-query': minor | ||
| --- | ||
|
|
||
| feat(svelte-query): add 'mutationOptions' |
This file contains hidden or 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
78 changes: 78 additions & 0 deletions
78
docs/framework/svelte/reference/functions/mutationOptions.md
This file contains hidden or 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,78 @@ | ||
| --- | ||
| id: mutationOptions | ||
| title: mutationOptions | ||
| --- | ||
|
|
||
| # Function: mutationOptions() | ||
|
|
||
| ## Call Signature | ||
|
|
||
| ```ts | ||
| function mutationOptions<TData, TError, TVariables, TOnMutateResult>(options): WithRequired<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, 'mutationKey'> | ||
| ``` | ||
|
|
||
| Defined in: [packages/svelte-query/src/mutationOptions.ts](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/mutationOptions.ts) | ||
|
|
||
| ### Type Parameters | ||
|
|
||
| #### TData | ||
|
|
||
| `TData` = `unknown` | ||
|
|
||
| #### TError | ||
|
|
||
| `TError` = `Error` | ||
|
|
||
| #### TVariables | ||
|
|
||
| `TVariables` = `void` | ||
|
|
||
| #### TOnMutateResult | ||
|
|
||
| `TOnMutateResult` = `unknown` | ||
|
|
||
| ### Parameters | ||
|
|
||
| #### options | ||
|
|
||
| `WithRequired`\<[`CreateMutationOptions`](../type-aliases/CreateMutationOptions.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>, `'mutationKey'`\> | ||
|
|
||
| ### Returns | ||
|
|
||
| `WithRequired`\<[`CreateMutationOptions`](../type-aliases/CreateMutationOptions.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>, `'mutationKey'`\> | ||
|
|
||
| ## Call Signature | ||
|
|
||
| ```ts | ||
| function mutationOptions<TData, TError, TVariables, TOnMutateResult>(options): Omit<CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, 'mutationKey'> | ||
| ``` | ||
|
|
||
| Defined in: [packages/svelte-query/src/mutationOptions.ts](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/mutationOptions.ts) | ||
|
|
||
| ### Type Parameters | ||
|
|
||
| #### TData | ||
|
|
||
| `TData` = `unknown` | ||
|
|
||
| #### TError | ||
|
|
||
| `TError` = `Error` | ||
|
|
||
| #### TVariables | ||
|
|
||
| `TVariables` = `void` | ||
|
|
||
| #### TOnMutateResult | ||
|
|
||
| `TOnMutateResult` = `unknown` | ||
|
|
||
| ### Parameters | ||
|
|
||
| #### options | ||
|
|
||
| `Omit`\<[`CreateMutationOptions`](../type-aliases/CreateMutationOptions.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>, `'mutationKey'`\> | ||
|
|
||
| ### Returns | ||
|
|
||
| `Omit`\<[`CreateMutationOptions`](../type-aliases/CreateMutationOptions.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>, `'mutationKey'`\> | ||
This file contains hidden or 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 hidden or 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,41 @@ | ||
| import type { DefaultError, WithRequired } from '@tanstack/query-core' | ||
| import type { CreateMutationOptions } from './types.js' | ||
|
|
||
| export function mutationOptions< | ||
| TData = unknown, | ||
| TError = DefaultError, | ||
| TVariables = void, | ||
| TOnMutateResult = unknown, | ||
| >( | ||
| options: WithRequired< | ||
| CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, | ||
| 'mutationKey' | ||
| >, | ||
| ): WithRequired< | ||
| CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, | ||
| 'mutationKey' | ||
| > | ||
| export function mutationOptions< | ||
| TData = unknown, | ||
| TError = DefaultError, | ||
| TVariables = void, | ||
| TOnMutateResult = unknown, | ||
| >( | ||
| options: Omit< | ||
| CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, | ||
| 'mutationKey' | ||
| >, | ||
| ): Omit< | ||
| CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, | ||
| 'mutationKey' | ||
| > | ||
| export function mutationOptions< | ||
| TData = unknown, | ||
| TError = DefaultError, | ||
| TVariables = void, | ||
| TOnMutateResult = unknown, | ||
| >( | ||
| options: CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>, | ||
| ): CreateMutationOptions<TData, TError, TVariables, TOnMutateResult> { | ||
| return options | ||
| } |
57 changes: 57 additions & 0 deletions
57
packages/svelte-query/tests/mutationOptions/BaseExample.svelte
This file contains hidden or 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,57 @@ | ||
| <script lang="ts"> | ||
| import { QueryClient } from '@tanstack/query-core' | ||
| import { | ||
| createMutation, | ||
| setQueryClientContext, | ||
| useIsMutating, | ||
| useMutationState, | ||
| } from '../../src/index.js' | ||
| import type { | ||
| Accessor, | ||
| CreateMutationOptions, | ||
| MutationStateOptions, | ||
| } from '../../src/index.js' | ||
| import type { MutationFilters } from '@tanstack/query-core' | ||
| let { | ||
| mutationOpts, | ||
| isMutatingFilters, | ||
| mutationStateOpts, | ||
| }: { | ||
| mutationOpts: Accessor<CreateMutationOptions<string, Error, void, unknown>> | ||
| isMutatingFilters?: MutationFilters | ||
| mutationStateOpts?: MutationStateOptions | ||
| } = $props() | ||
| const queryClient = new QueryClient() | ||
| setQueryClientContext(queryClient) | ||
| const mutation = createMutation(mutationOpts) | ||
| const isMutating = useIsMutating(isMutatingFilters) | ||
| const mutationState = useMutationState(mutationStateOpts) | ||
| let clientIsMutating = $state(0) | ||
| $effect(() => { | ||
| const mutationCache = queryClient.getMutationCache() | ||
| clientIsMutating = isMutatingFilters | ||
| ? queryClient.isMutating(isMutatingFilters) | ||
| : queryClient.isMutating() | ||
| const unsubscribe = mutationCache.subscribe(() => { | ||
| clientIsMutating = isMutatingFilters | ||
| ? queryClient.isMutating(isMutatingFilters) | ||
| : queryClient.isMutating() | ||
| }) | ||
| return unsubscribe | ||
| }) | ||
| </script> | ||
|
|
||
| <button onclick={() => mutation.mutate()}>mutate</button> | ||
|
|
||
| <div>isMutating: {isMutating.current}</div> | ||
| <div>clientIsMutating: {clientIsMutating}</div> | ||
| <div> | ||
| mutationState: {JSON.stringify(mutationState.map((state) => state.data))} | ||
| </div> |
61 changes: 61 additions & 0 deletions
61
packages/svelte-query/tests/mutationOptions/MultiExample.svelte
This file contains hidden or 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,61 @@ | ||
| <script lang="ts"> | ||
| import { QueryClient } from '@tanstack/query-core' | ||
| import { | ||
| createMutation, | ||
| setQueryClientContext, | ||
| useIsMutating, | ||
| useMutationState, | ||
| } from '../../src/index.js' | ||
| import type { | ||
| Accessor, | ||
| CreateMutationOptions, | ||
| MutationStateOptions, | ||
| } from '../../src/index.js' | ||
| import type { MutationFilters } from '@tanstack/query-core' | ||
|
|
||
| let { | ||
| mutationOpts1, | ||
| mutationOpts2, | ||
| isMutatingFilters, | ||
| mutationStateOpts, | ||
| }: { | ||
| mutationOpts1: Accessor<CreateMutationOptions<string, Error, void, unknown>> | ||
| mutationOpts2: Accessor<CreateMutationOptions<string, Error, void, unknown>> | ||
| isMutatingFilters?: MutationFilters | ||
| mutationStateOpts?: MutationStateOptions | ||
| } = $props() | ||
|
|
||
| const queryClient = new QueryClient() | ||
| setQueryClientContext(queryClient) | ||
|
|
||
| const mutation1 = createMutation(mutationOpts1) | ||
| const mutation2 = createMutation(mutationOpts2) | ||
| const isMutating = useIsMutating(isMutatingFilters) | ||
| const mutationState = useMutationState(mutationStateOpts) | ||
|
|
||
| let clientIsMutating = $state(0) | ||
|
|
||
| $effect(() => { | ||
| const mutationCache = queryClient.getMutationCache() | ||
| clientIsMutating = isMutatingFilters | ||
| ? queryClient.isMutating(isMutatingFilters) | ||
| : queryClient.isMutating() | ||
|
|
||
| const unsubscribe = mutationCache.subscribe(() => { | ||
| clientIsMutating = isMutatingFilters | ||
| ? queryClient.isMutating(isMutatingFilters) | ||
| : queryClient.isMutating() | ||
| }) | ||
|
|
||
| return unsubscribe | ||
| }) | ||
| </script> | ||
|
|
||
| <button onclick={() => mutation1.mutate()}>mutate1</button> | ||
| <button onclick={() => mutation2.mutate()}>mutate2</button> | ||
|
|
||
| <div>isMutating: {isMutating.current}</div> | ||
| <div>clientIsMutating: {clientIsMutating}</div> | ||
| <div> | ||
| mutationState: {JSON.stringify(mutationState.map((state) => state.data))} | ||
| </div> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolve duplicate "Call Signature" headings (MD024 warning).
Rename the headings to distinguish the overloads and avoid markdownlint warnings.
📝 Suggested heading tweak
🧰 Tools
🪛 LanguageTool
[grammar] ~18-~18: Ensure spelling is correct
Context: ...nOptions.ts) ### Type Parameters #### TData
TData=unknown#### TErrorTError= `E...(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
[grammar] ~26-~26: Ensure spelling is correct
Context: ... #### TError
TError=Error#### TVariablesTVariables=void#### TOnMutateResult `TOnMut...(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
[grammar] ~30-~30: Ensure spelling is correct
Context: ...TVariables
TVariables=void#### TOnMutateResultTOnMutateResult=unknown### Parameters #### optio...(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
🪛 markdownlint-cli2 (0.21.0)
[warning] 44-44: Multiple headings with the same content
(MD024, no-duplicate-heading)
🤖 Prompt for AI Agents