Skip to content

Commit 5deb6f4

Browse files
committed
chore: rename to onMutateResult
1 parent 1c5a820 commit 5deb6f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+633
-423
lines changed

docs/framework/angular/guides/mutations.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,17 @@ mutation = injectMutation(() => ({
9393
onMutate: (variables, context) => {
9494
// A mutation is about to happen!
9595

96-
// Optionally return a scope containing data to use when for example rolling back
96+
// Optionally return a result containing data to use when for example rolling back
9797
return { id: 1 }
9898
},
99-
onError: (error, variables, scope, context) => {
99+
onError: (error, variables, onMutateResult, context) => {
100100
// An error happened!
101-
console.log(`rolling back optimistic update with id ${scope.id}`)
101+
console.log(`rolling back optimistic update with id ${onMutateResult.id}`)
102102
},
103-
onSuccess: (data, variables, scope, context) => {
103+
onSuccess: (data, variables, onMutateResult, context) => {
104104
// Boom baby!
105105
},
106-
onSettled: (data, error, variables, scope, context) => {
106+
onSettled: (data, error, variables, onMutateResult, context) => {
107107
// Error or success... doesn't matter!
108108
},
109109
}))
@@ -130,25 +130,25 @@ mutation = injectMutation(() => ({
130130
```ts
131131
mutation = injectMutation(() => ({
132132
mutationFn: addTodo,
133-
onSuccess: (data, variables, scope, context) => {
133+
onSuccess: (data, variables, onMutateResult, context) => {
134134
// I will fire first
135135
},
136-
onError: (error, variables, scope, context) => {
136+
onError: (error, variables, onMutateResult, context) => {
137137
// I will fire first
138138
},
139-
onSettled: (data, error, variables, scope, context) => {
139+
onSettled: (data, error, variables, onMutateResult, context) => {
140140
// I will fire first
141141
},
142142
}))
143143

144144
mutation.mutate(todo, {
145-
onSuccess: (data, variables, scope, context) => {
145+
onSuccess: (data, variables, onMutateResult, context) => {
146146
// I will fire second!
147147
},
148-
onError: (error, variables, scope, context) => {
148+
onError: (error, variables, onMutateResult, context) => {
149149
// I will fire second!
150150
},
151-
onSettled: (data, error, variables, scope, context) => {
151+
onSettled: (data, error, variables, onMutateResult, context) => {
152152
// I will fire second!
153153
},
154154
})
@@ -161,15 +161,15 @@ mutation.mutate(todo, {
161161
export class Example {
162162
mutation = injectMutation(() => ({
163163
mutationFn: addTodo,
164-
onSuccess: (data, variables, scope, context) => {
164+
onSuccess: (data, variables, onMutateResult, context) => {
165165
// Will be called 3 times
166166
},
167167
}))
168168

169169
doMutations() {
170170
;['Todo 1', 'Todo 2', 'Todo 3'].forEach((todo) => {
171171
this.mutation.mutate(todo, {
172-
onSuccess: (data, variables, scope, context) => {
172+
onSuccess: (data, variables, onMutateResult, context) => {
173173
// Will execute only once, for the last mutation (Todo 3),
174174
// regardless which mutation resolves first
175175
},
@@ -224,19 +224,21 @@ queryClient.setMutationDefaults(['addTodo'], {
224224
// Add optimistic todo to todos list
225225
context.client.setQueryData(['todos'], (old) => [...old, optimisticTodo])
226226

227-
// Return scope with the optimistic todo
227+
// Return result with the optimistic todo
228228
return { optimisticTodo }
229229
},
230-
onSuccess: (result, variables, scope, context) => {
230+
onSuccess: (result, variables, onMutateResult, context) => {
231231
// Replace optimistic todo in the todos list with the result
232232
context.client.setQueryData(['todos'], (old) =>
233-
old.map((todo) => (todo.id === scope.optimisticTodo.id ? result : todo)),
233+
old.map((todo) =>
234+
todo.id === onMutateResult.optimisticTodo.id ? result : todo,
235+
),
234236
)
235237
},
236-
onError: (error, variables, scope, context) => {
238+
onError: (error, variables, onMutateResult, context) => {
237239
// Remove optimistic todo from the todos list
238240
context.client.setQueryData(['todos'], (old) =>
239-
old.filter((todo) => todo.id !== scope.optimisticTodo.id),
241+
old.filter((todo) => todo.id !== onMutateResult.optimisticTodo.id),
240242
)
241243
},
242244
retry: 3,

docs/framework/angular/guides/optimistic-updates.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,16 @@ updateTodo = injectMutation(() => ({
9898
// Optimistically update to the new value
9999
context.client.setQueryData(['todos'], (old) => [...old, newTodo])
100100

101-
// Return a scope object with the snapshotted value
101+
// Return a result object with the snapshotted value
102102
return { previousTodos }
103103
},
104104
// If the mutation fails,
105-
// use the scope returned from onMutate to roll back
106-
onError: (err, newTodo, scope, context) => {
107-
context.client.setQueryData(['todos'], scope.previousTodos)
105+
// use the result returned from onMutate to roll back
106+
onError: (err, newTodo, onMutateResult, context) => {
107+
context.client.setQueryData(['todos'], onMutateResult.previousTodos)
108108
},
109109
// Always refetch after error or success:
110-
onSettled: (data, error, variables, scope, context) => {
110+
onSettled: (data, error, variables, onMutateResult, context) => {
111111
context.client.invalidateQueries({ queryKey: ['todos'] })
112112
},
113113
}))
@@ -133,15 +133,18 @@ updateTodo = injectMutation(() => ({
133133
// Optimistically update to the new value
134134
context.client.setQueryData(['todos', newTodo.id], newTodo)
135135

136-
// Return a scope with the previous and new todo
136+
// Return a result with the previous and new todo
137137
return { previousTodo, newTodo }
138138
},
139-
// If the mutation fails, use the scope we returned above
140-
onError: (err, newTodo, scope, context) => {
141-
context.client.setQueryData(['todos', scope.newTodo.id], scope.previousTodo)
139+
// If the mutation fails, use the result we returned above
140+
onError: (err, newTodo, onMutateResult, context) => {
141+
context.client.setQueryData(
142+
['todos', onMutateResult.newTodo.id],
143+
onMutateResult.previousTodo,
144+
)
142145
},
143146
// Always refetch after error or success:
144-
onSettled: (newTodo, error, variables, scope, context) => {
147+
onSettled: (newTodo, error, variables, onMutateResult, context) => {
145148
context.client.invalidateQueries({ queryKey: ['todos', newTodo.id] })
146149
},
147150
}))
@@ -154,7 +157,7 @@ updateTodo = injectMutation(() => ({
154157
injectMutation({
155158
mutationFn: updateTodo,
156159
// ...
157-
onSettled: (newTodo, error, variables, scope) => {
160+
onSettled: (newTodo, error, variables, onMutateResult, context) => {
158161
if (error) {
159162
// do something
160163
}

docs/framework/angular/reference/functions/injectmutation.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ title: injectMutation
66
# Function: injectMutation()
77

88
```ts
9-
function injectMutation<TData, TError, TVariables, TScope>(
9+
function injectMutation<TData, TError, TVariables, TOnMutateResult>(
1010
injectMutationFn,
1111
options?,
12-
): CreateMutationResult<TData, TError, TVariables, TScope>
12+
): CreateMutationResult<TData, TError, TVariables, TOnMutateResult>
1313
```
1414

1515
Injects a mutation: an imperative function that can be invoked which typically performs server side effects.
@@ -24,13 +24,13 @@ Unlike queries, mutations are not run automatically.
2424

2525
**TVariables** = `void`
2626

27-
**TScope** = `unknown`
27+
**TOnMutateResult** = `unknown`
2828

2929
## Parameters
3030

3131
### injectMutationFn
3232

33-
() => [`CreateMutationOptions`](../../interfaces/createmutationoptions.md)\<`TData`, `TError`, `TVariables`, `TScope`\>
33+
() => [`CreateMutationOptions`](../../interfaces/createmutationoptions.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>
3434

3535
A function that returns mutation options.
3636

@@ -42,7 +42,7 @@ Additional configuration
4242

4343
## Returns
4444

45-
[`CreateMutationResult`](../../type-aliases/createmutationresult.md)\<`TData`, `TError`, `TVariables`, `TScope`\>
45+
[`CreateMutationResult`](../../type-aliases/createmutationresult.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>
4646

4747
The mutation.
4848

docs/framework/angular/reference/functions/mutationoptions.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ title: mutationOptions
66
# Function: mutationOptions()
77

88
```ts
9-
function mutationOptions<TData, TError, TVariables, TScope>(
9+
function mutationOptions<TData, TError, TVariables, TOnMutateResult>(
1010
options,
11-
): CreateMutationOptions<TData, TError, TVariables, TScope>
11+
): CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>
1212
```
1313

1414
Allows to share and re-use mutation options in a type-safe way.
@@ -46,19 +46,19 @@ mutation.mutate({ title: 'New Title' })
4646

4747
**TVariables** = `void`
4848

49-
**TScope** = `unknown`
49+
**TOnMutateResult** = `unknown`
5050

5151
## Parameters
5252

5353
### options
5454

55-
`MutationObserverOptions`\<`TData`, `TError`, `TVariables`, `TScope`\>
55+
`MutationObserverOptions`\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>
5656

5757
The mutation options.
5858

5959
## Returns
6060

61-
[`CreateMutationOptions`](../../interfaces/createmutationoptions.md)\<`TData`, `TError`, `TVariables`, `TScope`\>
61+
[`CreateMutationOptions`](../../interfaces/createmutationoptions.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>
6262

6363
Mutation options.
6464

docs/framework/angular/reference/interfaces/basemutationnarrowing.md

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ id: BaseMutationNarrowing
33
title: BaseMutationNarrowing
44
---
55

6-
# Interface: BaseMutationNarrowing\<TData, TError, TVariables, TScope\>
6+
# Interface: BaseMutationNarrowing\<TData, TError, TVariables, TOnMutateResult\>
77

88
## Type Parameters
99

@@ -13,7 +13,7 @@ title: BaseMutationNarrowing
1313

1414
**TVariables** = `unknown`
1515

16-
**TScope** = `unknown`
16+
**TOnMutateResult** = `unknown`
1717

1818
## Properties
1919

@@ -25,12 +25,19 @@ isError: SignalFunction<
2525
TData,
2626
TError,
2727
TVariables,
28-
TScope,
28+
TOnMutateResult,
2929
Override<
30-
MutationObserverErrorResult<TData, TError, TVariables, TScope>,
31-
{ mutate: CreateMutateFunction<TData, TError, TVariables, TScope> }
30+
MutationObserverErrorResult<TData, TError, TVariables, TOnMutateResult>,
31+
{
32+
mutate: CreateMutateFunction<TData, TError, TVariables, TOnMutateResult>
33+
}
3234
> & {
33-
mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TScope>
35+
mutateAsync: CreateMutateAsyncFunction<
36+
TData,
37+
TError,
38+
TVariables,
39+
TOnMutateResult
40+
>
3441
}
3542
>
3643
>
@@ -50,12 +57,19 @@ isIdle: SignalFunction<
5057
TData,
5158
TError,
5259
TVariables,
53-
TScope,
60+
TOnMutateResult,
5461
Override<
55-
MutationObserverIdleResult<TData, TError, TVariables, TScope>,
56-
{ mutate: CreateMutateFunction<TData, TError, TVariables, TScope> }
62+
MutationObserverIdleResult<TData, TError, TVariables, TOnMutateResult>,
63+
{
64+
mutate: CreateMutateFunction<TData, TError, TVariables, TOnMutateResult>
65+
}
5766
> & {
58-
mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TScope>
67+
mutateAsync: CreateMutateAsyncFunction<
68+
TData,
69+
TError,
70+
TVariables,
71+
TOnMutateResult
72+
>
5973
}
6074
>
6175
>
@@ -75,12 +89,19 @@ isPending: SignalFunction<
7589
TData,
7690
TError,
7791
TVariables,
78-
TScope,
92+
TOnMutateResult,
7993
Override<
80-
MutationObserverLoadingResult<TData, TError, TVariables, TScope>,
81-
{ mutate: CreateMutateFunction<TData, TError, TVariables, TScope> }
94+
MutationObserverLoadingResult<TData, TError, TVariables, TOnMutateResult>,
95+
{
96+
mutate: CreateMutateFunction<TData, TError, TVariables, TOnMutateResult>
97+
}
8298
> & {
83-
mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TScope>
99+
mutateAsync: CreateMutateAsyncFunction<
100+
TData,
101+
TError,
102+
TVariables,
103+
TOnMutateResult
104+
>
84105
}
85106
>
86107
>
@@ -100,12 +121,19 @@ isSuccess: SignalFunction<
100121
TData,
101122
TError,
102123
TVariables,
103-
TScope,
124+
TOnMutateResult,
104125
Override<
105-
MutationObserverSuccessResult<TData, TError, TVariables, TScope>,
106-
{ mutate: CreateMutateFunction<TData, TError, TVariables, TScope> }
126+
MutationObserverSuccessResult<TData, TError, TVariables, TOnMutateResult>,
127+
{
128+
mutate: CreateMutateFunction<TData, TError, TVariables, TOnMutateResult>
129+
}
107130
> & {
108-
mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TScope>
131+
mutateAsync: CreateMutateAsyncFunction<
132+
TData,
133+
TError,
134+
TVariables,
135+
TOnMutateResult
136+
>
109137
}
110138
>
111139
>

docs/framework/angular/reference/interfaces/createmutationoptions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ id: CreateMutationOptions
33
title: CreateMutationOptions
44
---
55

6-
# Interface: CreateMutationOptions\<TData, TError, TVariables, TScope\>
6+
# Interface: CreateMutationOptions\<TData, TError, TVariables, TOnMutateResult\>
77

88
## Extends
99

10-
- `OmitKeyof`\<`MutationObserverOptions`\<`TData`, `TError`, `TVariables`, `TScope`\>, `"_defaulted"`\>
10+
- `OmitKeyof`\<`MutationObserverOptions`\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>, `"_defaulted"`\>
1111

1212
## Type Parameters
1313

@@ -17,4 +17,4 @@ title: CreateMutationOptions
1717

1818
**TVariables** = `void`
1919

20-
**TScope** = `unknown`
20+
**TOnMutateResult** = `unknown`

0 commit comments

Comments
 (0)