Guest User

Untitled

a guest
Feb 25th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. import { createStore } from 'redux'
  2.  
  3. /**
  4. * This is a reducer, a pure function with (state, action) => state signature.
  5. * It describes how an action transforms the state into the next state.
  6. *
  7. */
  8. function counter(state = 0, action) {
  9. switch (action.type) {
  10. case 'INCREMENT':
  11. return state + 1
  12. case 'DECREMENT':
  13. return state - 1
  14. default:
  15. return state
  16. }
  17. }
  18.  
  19. // Create the store
  20. let store = createStore(counter);
  21.  
  22. /**
  23. * Actions
  24. *
  25. */
  26. store.dispatch({ type: 'INCREMENT' })
  27. // 1
  28. store.dispatch({ type: 'INCREMENT' })
  29. // 2
  30. store.dispatch({ type: 'DECREMENT' })
  31. // 1
Add Comment
Please, Sign In to add comment