Skip to content

Splitting logic between reducers and action creators. #1773

@oleksii-demedetskyi

Description

@oleksii-demedetskyi

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions