// // 4 different ways to write actions: ES7 Async/Await, Promises, Async Function, Synchronous. // import {createActions, asyncAction} from './helpers.js' export const CounterActions = createActions({ async incrementAsync() { const promise = new Promise((resolve, reject) => { setTimeout(() => { resolve() }, 1000) }) let result = await promise return result }, // Use decorator to mark action that returns promise @asyncAction() incrementPromise() { // Debug const promise = new Promise( (resolve, reject) => { setTimeout(() => { resolve() }, 1000) }) return promise; }, incrementFunctionWithState() { return (dispatch, getState) => { const {counter} = getState() console.log(dispatch) if (counter % 2 === 0) return dispatch(CounterActions.increment()) } }, incrementFunction()) { return dispatch => { setTimeout(() => { dispatch(CounterActions.increment()) }, 1000) } }, increment() { return {} }, })