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

[Question] Passing actions to next rather than dispatching #221

Open
codfish opened this issue Mar 4, 2019 · 3 comments
Open

[Question] Passing actions to next rather than dispatching #221

codfish opened this issue Mar 4, 2019 · 3 comments
Labels

Comments

@codfish
Copy link

codfish commented Mar 4, 2019

Sorry if you've addressed this already, I searched but came up empty.


Why is it that rather than dispatching a new action for success/failure, you instead just pass it to next? I definitely understand the request one being passed to next but why the other two? It renders previously provided middleware useless for those actions then.

For some context, my use case is that I've got an authentication middleware before redux-api-middleware, which intercepts RSAA actions to add an auth header, but I also wanted said middleware to handle the success action in the case of a login request.

I've never run into an issue outside of this use case so it's not a huge deal, I can work around it, but I was just wondering if there was some reason behind this architecture decision, whether it be a best practice or something else?

I've dispatched a lot from custom middleware when handling side-effects but I'm also not maintaining open source middleware being used by a lot of people, so maybe there's considerations you're taking that I've never thought of. Am I doing it wrong? Is there a wrong/right way here?

@codfish
Copy link
Author

codfish commented Mar 4, 2019

BTW thanks for building & maintaining this, it's great and I use it on all my projects!

@darthrellimnad
Copy link
Contributor

darthrellimnad commented May 19, 2019

Good question :). I ran into this early on as well, but eventually came to appreciate the current functionality, since passing to the next middleware can avoid the previous middleware in the chain, rather than always starting over from the top. We can always attach another middleware after redux-api-middleware to process the resulting FSAs, and dispatch a new action or perform a transform (if necessary) and pass along to next middleware. This avoids having the "request/response" FSAs from being passed to unnecessary middleware, like redux-api-middleware itself.

I often use redux-observable along with redux-api-middleware for larger scale things or with legacy rpc/rest apis, which you might also find useful for these sorts of use-cases :). Can get a little tricky for optimizations, but I added an RFC issue for "callable RSAA" utils which has helped me in my projects. If interested, here is that issue:

#216

@codfish
Copy link
Author

codfish commented May 22, 2019

@darthrellimnad great, appreciate the thorough response

@nason nason added the question label Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants