How do you work with side effects?
See original GitHub issuefor example I have three actions that fetch data via HTTP: fetch, fetchSuccess, fetchError
is something like the following “ok”?
const actions = store => ({
fetch: state => {
const stateUpdate = { ...state, loading: true };
fetchFromApi().then(data => store.fetchSuccess(stateUpdate, data), err => store.fetchError(stateUpdate, err));
return stateUpdate;
},
fetchSuccess: (state, payload) => ({ ...state, data: payload, loading: false }),
fetchError: (state, payload) => ({ ...state, loading: false, error: payload }),
});
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
How to Deal With Side Effects of Medicine - WebMD
WebMD has tips to keep medication side effects from putting a damper on your life.
Read more >Finding and Learning about Side Effects (adverse reactions)
Learning about Side Effects -- From Minor to Life Threatening -- Unwanted or Unexpected Drug Reactions.
Read more >How to Deal With Employees on Medication
Ask the employee about the medication and its side effects. Take notes. Ask about the drug's warnings and when you should call emergency...
Read more >Side effects: Medication, types of effect, cancer treatment
Many treatments and medical procedures can cause side effects, which can be positive but more ... According to the website, this is within...
Read more >What Are The Side Effects Of Working For Your Organization?
The first step is to recognize what the side effects are of working for the organization. Then, take steps to address the side...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Although thinking about this example, maybe it would be nice to perform something like this:
And this kind of action, probably have a better testability. It could be done roughly like this:
@matheusml, your opinion please.
exactly the point! Rule of thumb is: if your action is async use the store methods, otherwise just use the state parameter from the action.