How to use Flux stores

Most Flux examples use the todo or chat example. In all of these examples, the dataset you store is somewhat small and stored locally, so it's not entirely accurate if my intended use of stores follows the flow path method.

The way I intend to use stores is similar to ORM repositories. A way to access data in multiple ways and store the data in a data service, whatever it is.

Let's say I am building a project management system. I would probably have methods like this to fetch data:

  • getIssueById
  • getIssuesByProject
  • getIssuesByAssignedUser
  • getIssueComments
  • getIssueCommentById
  • etc...

I would also have methods like this for persisting data in a data service:

  • addIssue
  • updateIssue
  • removeIssue
  • addIssueComment
  • etc...

The only thing I don't need to do is store any problem data locally (and most importantly, store data store related data). Most of the data is important to keep up to date because the status of the issue may have been updated since the last time I received this issue. My whole method of fetching data will probably always make API requests to the latest data.

Is it against the "path" of the flow? Are there any problems with flowing this way?

+3


source to share


1 answer


I wouldn't be too dependent on the term "shop". You need to create application state in some way if you want your components to render something. If you need to clear this state every time another request is made, no problem. Here's how in a thread with getIssueById () as an example:

  • component calls store.getIssueById (id)
  • returns an empty object since the problem is not stored in the cache
  • store calls action.fetchIssue (id)
  • component displays empty state
  • the server responds with data about the problems and calls action.receiveIssue (data)
  • stores data caches and dispatches a change event
  • responds to the event by calling store.getIssueById (id)
  • problem data is returned
  • component displays data

The persisting changes would be similar, with only the most recent server response stored in the repository.



  • user interaction in component triggers action.updateIssue (modifiedIssue)
  • Saves actions with descriptors, sends changes to the server
  • the server responds with an updated issue and calls action.receiveIssue (data)

... etc. with the last 4 steps from the top.

As you can see, it's not really about modeling your data, just controlling how it goes and goes.

+5


source







All Articles