-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Splitting logic between reducers and action creators. #1773
Comments
This is a usage question, and should really be asked over on Stack Overflow. That said, the question of where "business logic" should live is up to you. There's good reasons to put some of it in reducers, and some of it in action creators. This exact question happens to be in the FAQ: http://redux.js.org/docs/FAQ.html#structure-business-logic |
The link is dead :/ |
@shivam-tripathi : yeah, we updated the docs and the redirects aren't working right. See https://redux.js.org/faq/code-structure#how-should-i-split-my-logic-between-reducers-and-action-creators-where-should-my-%22business-logic%22-go , and #2846 . |
Hi. I am trying to implement async flow with reducers.
And I am hot some kind of problem.
I have a remote resource (subtitles file), and URL to this resource can be changed with time (different languages etc.), also display of subtitles can be toggled.
I ended up with this shape of state:
{ url, isLoading, model, error, isActive, time }
And this list of an events:
URL_CHANGED, TIME_CHANGED, TOGGLED, LOADING_{START, FINISH, ERROR}
And this action creators:
toggle(), updateURL(url), updateTime(time)
Problem lies in business logic of url loading. URL should be loaded when user activate subtitles first time.
So in my
toggle()
andupdateURL(url)
action creators I have similar logic:if (getState().isActive && !getState().isLoading) /* do loading */
This looks like business logic for me, and I cannot find a way to move it to reducer/store level.
Did I model task right? Or it require some separation?
The text was updated successfully, but these errors were encountered: