Skip to content
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

resetOn does not work for mutations #308

Closed
ManuelHaag opened this issue Jan 23, 2020 · 3 comments
Closed

resetOn does not work for mutations #308

ManuelHaag opened this issue Jan 23, 2020 · 3 comments

Comments

@ManuelHaag
Copy link

We have multiple screens which use the same (mutation) action (let's call it UPDATE) and want to clear any error on unmounting of the screen by dispatching a RESET action.
Although the meta of UPDATE contains resetOn: [RESET], the mutation state does not get cleared properly.

Checking the code of src/reducers/network-reducer.js:34, only the queries object is being checked for reset actions via src/reducers/requests-reducer.js:128.

@klis87
Copy link
Owner

klis87 commented Jan 23, 2020

I implemented onReset with data clearing in mind, but you made a valid point that we could clear error too.

I will add this to the ROADMAP. Also I will take this into account implementing dedicated reset action type, which could be just used to reset any request(query or mutation), multiple of those or even the whole store.

Sadly I cannot work on it immediately as I am very busy on next release which will be very huge #306

For now you could cheat a little. Mutation error is cleared on mutation request, see https://github.com/klis87/redux-saga-requests/blob/master/packages/redux-saga-requests/src/reducers/mutations-reducer.js#L36

So to clear error you can dispatch UPDATE request (but with a dummy driver, or mockDriver, so that you wont hit server and immediately then abort(UPDATE). Note that you can use multiple drivers, even for the same action creator, depending on action creator param. I know, ulgy workaround, but I dont have any better idea apart from just forking this library for now until it is built in the core.

@klis87
Copy link
Owner

klis87 commented Jan 25, 2020

@ManuelHaag After thinking for a bit longer, I could accept PR with this, even though it will create merge conflicts for me on dev branch. This won't be hard to solve though so if my workaround won't solve this issue for now and you will need this done properly, I will merge PR on master.

@klis87
Copy link
Owner

klis87 commented Mar 22, 2020

@ManuelHaag see resetRequests action in v0.27.0

@klis87 klis87 closed this as completed Mar 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants