You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.
I have a scenario where an action is to be dispatched however I need to perform some logic dependent on the state of certain stores to determine what actions to dispatch. Since a store cannot dispatch while already dispatching I cannot create a store which handles this logic. Note that this logic is non trivial.
Basically I need to perform an action which says "Calculate and apply a route which brings this resource to that target". The route that the resource has to take depends on available resources provided by the different stores. So I need to query all the stores and perform some logic to figure out what route is the best one and then dispatch the corresponding actions to the stores to make it happen.
Should I put the logic in the ActionCreator? Although that does not quite follow the guidelines which explicitly state the ActionCreators should just be helper methods to create and dispatch the actions.
The text was updated successfully, but these errors were encountered:
ronag
changed the title
Should I put logic into the ActionCreator?
Should I put logic into the ActionCreators?
Oct 25, 2014
ronag
changed the title
Should I put logic into the ActionCreators?
Should I put logic into ActionCreators?
Oct 25, 2014
You can put logic in an ActionCreator, but often there is a better design.
"Calculate and apply a route which brings this resource to that target"
Is this in response to a user interaction with the UI?
If so, I would try to do as much logic as possible in the stores, perhaps utilizing Dispatcher.waitFor(), and pass those values down as props to the view. In an event handler, the view would only apply the user-driven variables against those precalculated values that were passed down, and then call the appropriate ActionCreator with the parameters it needs.
If this is in response to another action, I would back up and look at how I am handling that action. I would gather all the required information, again possibly with waitFor(), to "apply a route..." in response to that original action.
I have a scenario where an action is to be dispatched however I need to perform some logic dependent on the state of certain stores to determine what actions to dispatch. Since a store cannot dispatch while already dispatching I cannot create a store which handles this logic. Note that this logic is non trivial.
Basically I need to perform an action which says "Calculate and apply a route which brings this resource to that target". The route that the resource has to take depends on available resources provided by the different stores. So I need to query all the stores and perform some logic to figure out what route is the best one and then dispatch the corresponding actions to the stores to make it happen.
Should I put the logic in the ActionCreator? Although that does not quite follow the guidelines which explicitly state the ActionCreators should just be helper methods to create and dispatch the actions.
The text was updated successfully, but these errors were encountered: