-
Notifications
You must be signed in to change notification settings - Fork 45
fix: assign properties of mutations in withMutation
#288
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,14 +118,25 @@ function createMutationsFeature<Result extends MutationsDictionary>( | |
| keys.reduce( | ||
| (acc, key) => ({ | ||
| ...acc, | ||
| [key]: async (params: never) => { | ||
| const mutation = mutations[key]; | ||
| if (!mutation) { | ||
| throw new Error(`Mutation ${key} not found`); | ||
| } | ||
| const result = await mutation(params); | ||
| return result; | ||
| }, | ||
| [key]: Object.assign( | ||
| async (params: never) => { | ||
| const mutation = mutations[key]; | ||
| if (!mutation) { | ||
| throw new Error(`Mutation ${key} not found`); | ||
| } | ||
| const result = await mutation(params); | ||
|
|
||
| return result; | ||
| }, | ||
| { | ||
| status: mutations[key].status, | ||
| value: mutations[key].value, | ||
| isPending: mutations[key].isPending, | ||
| isSuccess: mutations[key].isSuccess, | ||
| error: mutations[key].error, | ||
| hasValue: mutations[key].hasValue, | ||
| }, | ||
|
Comment on lines
+121
to
+138
|
||
| ), | ||
|
Comment on lines
+121
to
+139
|
||
| }), | ||
| {} as MethodsDictionary, | ||
| ), | ||
|
|
||
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.
This change is intended to make
store.<mutation>usable as a fullMutationobject (e.g.store.increment.isPending()), but the existingwith-mutations.spec.tssuite only asserts the derived<mutation>IsPending/<mutation>Statussignals and does not cover property access on the method itself. Add a regression test that callsstore.increment.isPending()/status()(and ideallyhasValue()), so the runtime shape is verified.