Guest User

Untitled

a guest
Jul 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. const ADD = 'ADD';
  2.  
  3. const reducer = (state = 0, action) => {
  4. switch(action.type) {
  5. case ADD:
  6. return state + 1;
  7. default:
  8. return state;
  9. }
  10. };
  11.  
  12. const store = Redux.createStore(reducer);
  13.  
  14. // global count variable:
  15. let count = 0;
  16.  
  17. // change code below this line
  18. store.subscribe(function() { //this callback function will run every time that the store receives an action. In this case, it would also change the global variable.
  19. count += 1;
  20. })
  21.  
  22. // change code above this line
  23.  
  24. store.dispatch({type: ADD});
  25. console.log(count);
  26. store.dispatch({type: ADD});
  27. console.log(count);
  28. store.dispatch({type: ADD});
  29. console.log(count);
Add Comment
Please, Sign In to add comment