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

Create a convention for how to handle async actions and side effects #64

Closed
Aleksion opened this issue Jan 25, 2016 · 2 comments
Closed

Comments

@Aleksion
Copy link
Member

There are a lot discussions going on in the ReduxJs community regarding side effects and how they should be handled. And I think we should incorporate what we think of as best actions into the core project (we don't have an example of how it can be achieved in our docs currently).

From what I've gathered there are currently 3 options:

1: Action Creators
2: Reducers
3: Middleware

1: Dan Abramovs initial suggestion is to implement side effects in Action Creators. However, a lot of people find this to become messy quite quickly.
Personally, I also find it hard to figure out how to structure my application properly. If most actions are simple, and some are huge complex chunks of code, I find it hard to jump into an application and figure out where to find API logic fx.

2: The following discussion highlights why using Reducers for side-effects is a bad idea: reduxjs/redux#291. And personally I agree. Reducers should change state objects, but not dispatch side effects. If we start putting side effects in some reducers and not in others, it will quickly become hard to track how information flow through the application.

3: Middlewares: There are quite a few examples of middlewares handling sideeffects in Redux - one of them is https://github.com/yelouafi/redux-saga. Personally I lean towards this approach. I dislike the name - because it has no semantic meaning ot me. But the idea of having services, that catch actions before they're passed on to reducers, is an appealing one.
Personally I would structure them as services in the application, so that all the side effect logic is located in one place. Disclaimer: I haven't read the Saga documentation in detail, so I might have a different mental picture what it's actually doing.

I'm going to keep updating this thread as I read through the documentation of all the different solutions. But feel free to pitch in in the meantime!

@Ben-G
Copy link
Member

Ben-G commented Mar 18, 2016

Redux Loop looks like an interesting generalization of what we already have in form of AsyncActionCreator: https://github.com/raisemarketplace/redux-loop

Would also play well with Rx frameworks in place of promises.

@DivineDominion
Copy link
Contributor

For posterity: we have https://github.com/ReSwift/ReSwift-Thunk/ that fits the bill

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

3 participants