Skip to content

how to update other store states from reducers? #562

Closed
@bchenSyd

Description

@bchenSyd

let's say my react application has 10 business pages and one error page; each page has its own store state , action creators, reducers..etc. Any unexpected result will lead user to the error page, with error message read from error store state. The store state at run-time is like below

{
   page1 : { key1: val1, key2:val2 },
   page2 : { key1: val1, key2:val2 },
   page3 : { key1: val1, key2:val2 },
   ............
   error: { error_msg:' unexpected error: specified user doesn\'t exist   '}
}

Now the question is how to set the error_msg in error state across the application.

If you use api frameworks like saga or CALL_API, the REQUEST_BEGIN/REQUEST_SUCCEEDED/REQUEST_FAILURE actions are dispatched within the api framework and therefore the first user code invoked after a failure is actually reducer code.
Since reducers are localised, they don't have access to other store states, so another action is needed to update error state. This isn't effective and looks a bit clumsy.

I was wondering if we can have a shared/communal store state, so that it can be updated directly from all reducers, or do we have better solutions?

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