Comments (4)
Thanks for the note! Perhaps this isn't as clear as it could be in the documentation.
Stores contain the logic for manipulating the application state that is used to build the UI and otherwise provide useful data to the application; this is what I generally refer to as "business logic" in a flux system, but perhaps a more accurate term would be "global state management logic." No other part of a flux application should manipulate the global app state. Async client interactions happen in the action creators, but these (in my mind anyway) don't contain what I'd consider "business logic"βthey're generally just thin calls to an API endpoint that invokes the proper server business logic to act on the data on the back end (database, etc.) and return the data to the client when the operation has succeeded or failed. All the logic about how that interaction changes global application state happens in the store in response to an action dispatch.
For example, in the BuzzwordClient example, the addBuzz
action creator function doesn't contain any client-side state management, it just takes the parameters given to it and contacts the (fake) server endpoint that corresponds with "add buzzword" with it. When the server responds with the success or failure to actually add the word, the action creator notifies the store with the ADD_BUZZ_SUCCESS
and ADD_BUZZ_FAIL
, and it's the store's job to manage the internal state that the UI is ultimately based on.
Does that help or make sense? I'm totally open to ideas on how to make this more clear in the docs.
from fluxxor.
Thanks for the feedback.
I see what you are saying, and it makes sense. I still think the line between what a store does and what an action does is blurry in Flux, in general, and I'm always interested in hearing another take on things. Another pattern I've seen used is one in which a model fetches its data and then updates a store via an action. (This always feels wrong to me.) Then there is the argument that the asynchronous call itself could go into the store action handlers.
In any case, I'll muse on this some more, but also looking forward to putting Fluxxor into practice in an application soon.
from fluxxor.
I think a lot of that doesn't matter so much as long as you're consistent. In my opinion, the two big "rules" (that help make flux apps easier to reason about and debug) are:
- All global app state lives in the stores, and only a store is allowed to modify that store's state
- All store state updates must be synchronous updates triggered by handling actions
These two rules mean that any issue with global app state can be traced back to a single action or action handler.
from fluxxor.
Makes sense, thanks for the clarifications.
from fluxxor.
Related Issues (20)
- resetting stores HOT 2
- Question: asynchronous route transition HOT 1
- Fluxxor and React Router 1.x and ES6 HOT 7
- this.isMounted is not a function HOT 2
- Best practices for nested models HOT 1
- React warning after update to 1.7.2 HOT 1
- fluxxor with react router 1rc HOT 16
- Can one use Fluxxor with React Native? HOT 2
- Use instanceOf or shape in context types and add propTypes
- Wait until async request completes HOT 2
- Routing examples no longer work with latest version of React Router HOT 3
- Lost events with StoreWatchMixin during ComponentWillMount -> ComponentDidMount HOT 1
- Documentation for setting dispatch interceptor is out of date HOT 3
- In the Async Example not clear how to support add action which needed to call out to server HOT 1
- React-Router v4 and Fluxxor
- Current lodash dependency has a CVE
- Compatibility with React 16 HOT 2
- Typo in a link on the "What is Flux" page
- sdasdasdas
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluxxor.