actions.js 417 B

12345678910111213141516
  1. import { INCREMENT, DECREMENT } from './mutation-types'
  2. export const increment = ({ dispatch }) => dispatch(INCREMENT)
  3. export const decrement = ({ dispatch }) => dispatch(DECREMENT)
  4. export const incrementIfOdd = ({ dispatch, state }) => {
  5. if ((state.count + 1) % 2 === 0) {
  6. dispatch(INCREMENT)
  7. }
  8. }
  9. export const incrementAsync = ({ dispatch }) => {
  10. setTimeout(() => {
  11. dispatch(INCREMENT)
  12. }, 1000)
  13. }