Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. const { createStore, combineReducers } = require('redux')
  2.  
  3. const ActionType = {
  4. Inc: Symbol(),
  5. Dec: Symbol(),
  6. Pow: Symbol(),
  7. }
  8.  
  9. const inc = () =>
  10. ({ type: ActionType.Inc })
  11.  
  12. const dec = () =>
  13. ({ type: ActionType.Dec })
  14.  
  15. const pow = n =>
  16. ({ type: ActionType.Pow, payload: n })
  17.  
  18.  
  19. const counter = (state = 0, action) => {
  20. switch (action.type) {
  21. case ActionType.Inc:
  22. return state + 1
  23.  
  24. case ActionType.Dec:
  25. return state - 1
  26.  
  27. case ActionType.Pow:
  28. return state ** action.payload
  29.  
  30. default:
  31. return state
  32. }
  33. }
  34.  
  35. const reducer = combineReducers({ counter })
  36.  
  37. const store = createStore(reducer)
  38.  
  39. store.dispatch(inc())
  40.  
  41. store.dispatch(inc())
  42.  
  43. store.dispatch(inc())
  44.  
  45. store.dispatch(pow(3))
  46.  
  47.  
  48.  
  49. console.log(store.getState())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement