Support for Async Mutations / Component Callbacks #133
-
Firstly, I am in love with this library and it is greatly reducing the size of my service layer when syncing with Firebase's Firestore. With that said, I cannot find any references to async mutators. I have a use case where I want to trigger a mutator then navigate to a different route after onSuccess is called and completes, but I do not want to write this routing directly into the injectMutation call because more than one page uses this mutation but only one page redirects to a new route after the mutation; the rest do not react to the mutation at all. So my question is: are there currently any ways to achieve this in Angular Query? From the TanStack documentation I would expect either mutateAsync or adding an onSuccess callback would allow me to achieve this but it does not look like this has been implemented yet. I understand this is still a growing project and I greatly appreciate all the work that has been done to get this where it is now. Just curious how I might be able to solve this problem :) |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 25 replies
-
You can do this: this.addTodo.result$.subscribe((result => {
if(result.isSuccess) {
//
}
}) |
Beta Was this translation helpful? Give feedback.
-
@DakotaP22 you can use the first suggestion or the new mutateAsync function in the latest version. |
Beta Was this translation helpful? Give feedback.
-
My use case with mutateAsync is working beautifully now but I am having an issue with the component callbacks. Here is a snippet from this.bucketsQuery.archiveBucket().mutate(bucketId, {
onSuccess: () => {
console.log('Component Success Triggered!');
},
onSettled: () => {
console.log("Component Settled Triggered!")
}
}); I am not getting any logs in the console here but the mutation is at least partially working as my workbucket succesfully archives in the database. I am probably doing something wrong here and hoping its a simple issue. Also feel bad you are digging into this on the holiday, so please do not feel the need to look into this today on my behalf (forgive me if you do not celebrate, I don't like to assume anything). Absolutely wonderful work here and I am loving it regardless. |
Beta Was this translation helpful? Give feedback.
-
But to answer this question @DakotaP22 , yes this would be a good way to utilize the mutation side-effect ( |
Beta Was this translation helpful? Give feedback.
-
Hello, https://stackblitz.com/edit/stackblitz-starters-vjtv4b?file=src%2Fapp%2Fapp.component.ts Am i missing something? |
Beta Was this translation helpful? Give feedback.
@DakotaP22 you can use the first suggestion or the new mutateAsync function in the latest version.