Search code examples
reduxflux

Responsibility of store in flux


In flux I'm wondering, is it okay to

  • make async operation
  • change multiple values (by different keys) in state
  • trigger actions

in a single store? If I need to update 2 keys of store, should I create another store to separate concerns and make store responsible for a single first level property in state?

E.g. in Redux reducer is responsible for a single first level key on resulted object, asaik


Solution

  • Make async operations:

    Typically it is better to keep your stores synchronous... they should be dumb and just receive data. Makes everything easier and testable! The action creator should dispatch the appropriate action once it has resolved.

    Change multiple values (by different keys) in state:

    This isn't that bad, but as you eluded too, perhaps you need to rethink how your app state is structured. It depends on the action though... hard to say without knowing the context.

    Trigger actions:

    Your views are responsible for triggering actions... So stores should not trigger actions!

    Some links:

    Async requests with React.js and Flux, revisited.

    Using a Redux store in your React.js application