Guest User

Untitled

a guest
May 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. const initialState = {
  2. "routines": {
  3. "1": {
  4. "id": 1,
  5. "name": "Routine 1",
  6. },
  7. "2": {
  8. "id": 2,
  9. "name": "Routine 2",
  10. }
  11. }
  12. }
  13.  
  14. import { ADD_ROUTINE } from '../actions/routineActions'
  15.  
  16. function routineReducer(state={}, action) {
  17. switch (action.type) {
  18. case ADD_ROUTINE:
  19. newState = {...state}
  20. number_of_keys = Object.keys(newState).length
  21. new_id = number_of_keys + 1
  22. return {
  23. ...state,
  24. new_id: {
  25. id: new_id,
  26. name: action.name,
  27. days: []
  28. }
  29. }
  30. default:
  31. return state
  32. }
  33. }
  34.  
  35. export default routineReducer
Add Comment
Please, Sign In to add comment