When to Create a New Flux Store

I was wondering what works best when creating stores in Flux when working with the API

Say we have a list of "projects", an API call will eventually populate a Store called ProjectStore in _projects

Then, when the user selects the project, you want to download the data related to the project. Would you add this to ProjectStore as _activeProject or create a separate store for it?

Same thing when you download Todo inside this project. It would be wise to put them in TodoStore , but what about the specific Todo in Todos in the project?

I hope this makes sense :)

+5
source share
1 answer

I would use ProjectStore to store both _projects and _activeProject .

In my React projects, I made, as a rule, to create a new store for each model. For example: let's say that I have an application that serves messages and accounts. Then I would have a MessageStore and AccountStore . Then use them accordingly in your domain. For example, when I want to receive some messages from the backend (via the API), I store them in a MessageStore . The same goes for AccountStore .

As your project gets bigger and bigger, you may have to rethink the reorganization of something in the new store. For example, if you want to add ads to your site, you can create an AdsStore .

My rule is to try to separate stores by their domain, but does not make the structure more complex than it should be.

Hope this helps.

+4
source

Source: https://habr.com/ru/post/1213594/


All Articles