-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Why not using the action to do update the stores? (higher compling) #67
Comments
Open license; you're free to do whatever you want. Personally, I'm finding the trick with React & Flux is how to model some particular state change such that you don't find yourself trying/needing/wanting to issue dispatches from inside component life cycle functions or otherwise circumvent the dispatch flow as you are doing here. |
@sterpe I'm not dispatching from the component. This code is an action from flux. So instead of making a global dispatch that stores listen to and do stuff, I do the stuff needed in the action and in this particular order, which is easier to read IMO. No need for waitFor. I'm only asking what are the benefits of using a strict flux architecture vs my version.
I'm only skipping the dispatcher from the view. |
eh, stores should be event emitters and that should be their mechanism to notify the views listening to them of updated, I guess that was typo? |
Yes, isn't that what I've said?
Store->dispatches->then the views update |
Sorry I read it as another action being dispatched, which seemed wrong. |
@totty90, As the application grows, say you add ten more stores for planetary defense, ship drive efficiency, etc you will have to modify each "action" fn to call & update the particular store. Compare with using the dispatcher where you would only declare what actions this store updates against within the store itself. |
Please take questions about variations on Flux or quasi-Flux experiments to the React Google Group, rather than this repo. |
@fisherwebdev Ok. Continue here: https://groups.google.com/forum/#!topic/reactjs/krY5aiMk540 |
No one sits down to just read an entire codebase, normally you want to focus on one concern and with stores that one concern should be in one place.
Exactly. Not real at all, what you are describing is a God object not a well factored store. |
@briandipalma even with my game example above, putting everything in each store is harder to maintain.
Normally you don't need to read it all, but for example I would like to know what exactly happens when I click on a button. If you have unexpected behaviour you have to check all the stores for that particular action. If you have an action you read it all there. I can't see any use case / making my life easier about storing that logic in each store. But this is me. Have you developed any app with pure flux? Show me your code or part of it. |
Following that logic you should put all your code in one file so you don't have to look at any other files.
Personally I wouldn't do it that way, I'd open up the view and then the store/stores that provide data to the view that appears incorrect and debug in that order. What you are doing in your pattern is making the stores mutable from outside. This negates one of the advantages of flux, as long as you are dealing with manageable interactions this seems fine but it's more difficult to scale with increasing complexity. By the way I believe the action is simply an object literal with a type property, the action creator is the module/class with the API on it. I think it's quite handy to decouple the action creator and the store processing the action as it allows users of your flux component to easy add their own stores without having to modify the action creator code. All they do is register to the dispatcher, while in your pattern they would have to register to the dispatcher and modify the action creator code. Also if you wanted to see what action a store responds to you would have to look at all action creators and see if they call the store. In essence the reverse of your "what stores are notified by what action" problem. |
This is not the same logic. I've said to only keep in an action the whole flow. So when I look at an action I can see everything it does. Is not the same as putting all the code in the same file, as you can think.
No, just change the action creator code.
That's also true. So the final question is: do you want to see what an action does or what a store responds to. Normally you want to know the flow other times you want to see what changes a store. Both can't be done together. For me is more useful to see what happens when an something triggers an action than knowing what changes a store. |
Hy!
Currently I have an app that has a changed version of flux in which the action manages all the stores changes:
I don't need to wait for stores (anyway flux's
waitFor()
is synchronous), I just put the things in the order. For now is scaling well, but I might wonder what would be the benefits of implementing a strict flux architecture (where the stuff is done in the register callback in each model)?The first thing that can go wrong is having a lot of stuff in each action. But you have the benefit of knowing in one glance what is going on each action. In the strict flux architecture you would have to open each store and check it's relative action listener.
This is the real action, without any modification:
The text was updated successfully, but these errors were encountered: