Guest User

Untitled

a guest
Jul 16th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. const INCREMENT = 'INCREMENT';
  2. const DECREMENT = 'DECREMENT';
  3.  
  4. const counterReducer = (state = 0, action) => { //A reducer function to add/sub counter
  5. switch(action.type) {
  6. case INCREMENT:
  7. return state + 1;
  8. case DECREMENT:
  9. return state - 1;
  10. default:
  11. return state;
  12. }
  13. };
  14.  
  15. const LOGIN = 'LOGIN';
  16. const LOGOUT = 'LOGOUT';
  17.  
  18. const authReducer = (state = {authenticated: false}, action) => { //A reducer function to authenticate
  19. switch(action.type) {
  20. case LOGIN:
  21. return {
  22. authenticated: true
  23. }
  24. case LOGOUT:
  25. return {
  26. authenticated: false
  27. }
  28. default:
  29. return state;
  30. }
  31. };
  32.  
  33. const rootReducer = Redux.combineReducers({ //this combines the individual reducer functions into a root function that has the keys, and then the other reducer functions assiciated with that key.
  34. count: counterReducer,
  35. auth: authReducer
  36. });
  37.  
  38. const store = Redux.createStore(rootReducer);
Add Comment
Please, Sign In to add comment