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

Splitting logic between reducers and action creators. #1773

Closed
oleksii-demedetskyi opened this issue May 27, 2016 · 3 comments
Closed

Splitting logic between reducers and action creators. #1773

oleksii-demedetskyi opened this issue May 27, 2016 · 3 comments

Comments

@oleksii-demedetskyi
Copy link

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() and updateURL(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?

@markerikson
Copy link
Contributor

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

@shivam-tripathi
Copy link

The link is dead :/

@markerikson
Copy link
Contributor

@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 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants