Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. export const initialState = { count: 0 };
  2.  
  3. function reducer(state, action) {
  4. return new Promise(resolve => {
  5. setTimeout(() => {
  6. switch (action.type) {
  7. case 'up':
  8. resolve({ ...state, count: state.count + 1 });
  9. break;
  10. case 'down':
  11. resolve({ ...state, count: state.count - 1 });
  12. break;
  13. case 'reset':
  14. resolve({ ...initialState });
  15. break;
  16. default:
  17. resolve(state);
  18. break;
  19. }
  20. }, 1000);
  21. });
  22. }
  23.  
  24. export default reducer;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement