1const GET_CURRENT_USER = 'GET_CURRENT_USER';
2const GET_CURRENT_USER_SUCCESS = 'GET_CURRENT_USER_SUCCESS';
3const GET_CURRENT_USER_FAILURE = 'GET_CURRENT_USER_FAILURE';
4
5const getUser = () => {
6 return (dispatch) => { //nameless functions
7 // Initial action dispatched
8 dispatch({ type: GET_CURRENT_USER });
9 // Return promise with success and failure actions
10 return axios.get('/api/auth/user').then(
11 user => dispatch({ type: GET_CURRENT_USER_SUCCESS, user }),
12 err => dispatch({ type: GET_CURRENT_USER_FAILURE, err })
13 );
14 };
15};
1const INCREMENT_COUNTER = 'INCREMENT_COUNTER';
2
3function increment() {
4 return {
5 type: INCREMENT_COUNTER
6 };
7}
8
9function incrementAsync() {
10 return dispatch => {
11 setTimeout(() => {
12 // You can invoke sync or async actions with `dispatch`
13 dispatch(increment());
14 }, 1000);
15 };
16}