Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. import {Failure, Success} from "typescript-fsa";
  2. import {reducerWithInitialState} from "typescript-fsa-reducers";
  3. import {newState} from "../../common/newState";
  4. //import {CoreActions} from "../../core/store";
  5. import {homeActions} from "./homeActions";
  6. import {HomeInitialState, HomeState} from "./homeState";
  7.  
  8. function clearState(state: HomeState): HomeState {
  9. return newState(state, {resultLessons:null, error: null});
  10. }
  11.  
  12. //Get Statistic
  13. function getStatisticStarted(state: HomeState): HomeState {
  14. return newState(state, {
  15. isLoading: true,
  16. error: null
  17. })
  18. }
  19. function getStatisticDone(state: HomeState, payload: Success<any, any>): HomeState {
  20. return newState(state, {
  21. isLoading: false,
  22. resultStatistic:payload.result,
  23. error: null
  24. })
  25. }
  26. function getStatisticFailed(state: HomeState, failed: Failure<any, Error>): HomeState {
  27. return newState(state, {
  28. isLoading: false,
  29. resultStatistic:null,
  30. error: failed.error,
  31. })
  32. }
  33.  
  34. //Get Calendar
  35. function getCalendarStarted(state: HomeState): HomeState {
  36. return newState(state, {
  37. isLoading: true,
  38. error: null
  39. })
  40. }
  41. function getCalendarDone(state: HomeState, payload: Success<any, any>): HomeState {
  42. return newState(state, {
  43. isLoading: false,
  44. resultHomeCalendar:payload.result,
  45. error: null
  46. })
  47. }
  48. function getCalendarFailed(state: HomeState, failed: Failure<any, Error>): HomeState {
  49. return newState(state, {
  50. isLoading: false,
  51. resultHomeCalendar:null,
  52. error: failed.error,
  53. })
  54. }
  55.  
  56. //Post Online Lessons
  57. function sendLessonsStarted(state: HomeState): HomeState {
  58. return newState(state, {
  59. isLoading: true,
  60. resultLessons:null,
  61. error: null
  62. })
  63. }
  64. function sendLessonsDone(state: HomeState, payload: Success<any, any>): HomeState {
  65. return newState(state, {
  66. isLoading: false,
  67. resultLessons:payload.result,
  68. error: null
  69. })
  70. }
  71. function sendLessonsFailed(state: HomeState, failed: Failure<any, Error>): HomeState {
  72. return newState(state, {
  73. isLoading: false,
  74. resultLessons:null,
  75. error: failed.error.message,
  76. })
  77. }
  78.  
  79. export const homeReducer = reducerWithInitialState(HomeInitialState)
  80. .case(homeActions.clearState, clearState)
  81.  
  82. .case(homeActions.getHomeStatistic.started, getStatisticStarted)
  83. .case(homeActions.getHomeStatistic.done, getStatisticDone)
  84. .case(homeActions.getHomeStatistic.failed, getStatisticFailed)
  85.  
  86. .case(homeActions.getHomeCalendar.started, getCalendarStarted)
  87. .case(homeActions.getHomeCalendar.done, getCalendarDone)
  88. .case(homeActions.getHomeCalendar.failed, getCalendarFailed)
  89.  
  90. .case(homeActions.sendLessons.started, sendLessonsStarted)
  91. .case(homeActions.sendLessons.done, sendLessonsDone)
  92. .case(homeActions.sendLessons.failed, sendLessonsFailed)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement