Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import { Action, Reducer, ApplicationState } from "./store.types";
  2. import { ActionType } from "./store.actions";
  3. import * as Reducers from "./reducers";
  4.  
  5. /**
  6. * Create an initial state.
  7. * This will be the initial state of the application
  8. */
  9. const initialState: ApplicationState = {
  10. posts: {},
  11. deletingPosts: {}
  12. };
  13.  
  14. /**
  15. * The Application Reducer
  16. * @param state: current application state
  17. * @param action: the current action fired in the application
  18. * @returns state: the new application state
  19. */
  20. const reducer: Reducer = (
  21. prevState: ApplicationState = initialState,
  22. action: Action
  23. ): ApplicationState => {
  24. console.log("reducer", action);
  25.  
  26. switch (action.type) {
  27. case ActionType.GET_POSTS_SUCCESS:
  28. return Reducers.getPostsSuccessReducer(prevState, action);
  29.  
  30. case ActionType.DELETE_POST_REQUEST:
  31. return Reducers.deletePostRequestReducer(prevState, action);
  32.  
  33. case ActionType.DELETE_POST_SUCCESS:
  34. return Reducers.deletePostSuccessReducer(prevState, action);
  35. }
  36.  
  37. return prevState;
  38. };
  39.  
  40. export default reducer;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement