Search code examples
reactjsreactjs-fluxflux

How to handle a Flux store for single / multiple data rows - according to read permissions?


For example - a simple user can read its own data but an admin can read all users data.

Can I use a single Flux store, called 'UserStore', that will hold an array which will sometimes contain a single data object and sometimes multiple data objects (depend on the current logged in user permission), OR, this is a case for 2 separate stores (although, in the bottom line, it reads/writes to the same DB table)?

What do you guys suggest?


Solution

  • Simple answer: single store.

    If the store can contain one primary object for a user, or an array of users if the user is an admin that's fine to have in one store, just write your logic accordingly.

    If there is no shared data, no shared logic, and do dependencies between two stores (and there never will be) then split them out into two stores if you feel you get some benefit out of it.

    The readme for redux makes an interesting case for only ever using a single store: https://github.com/rackt/redux