Guest User

Untitled

a guest
Dec 19th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. export const SET_COUPON_STATES = '[Data] Set coupon states list';
  2. export const SET_UOR_LIST = '[Data] Set UOR list';
  3.  
  4. export class SetCouponStates implements Action {
  5. readonly type = SET_COUPON_STATES;
  6.  
  7. constructor(public payload: StatoTagliando[]) { }
  8. }
  9.  
  10. export class SetUORList implements Action {
  11. readonly type = SET_UOR_LIST;
  12.  
  13. constructor(public payload: UnitaOrganizzativa[]) { }
  14. }
  15.  
  16. export type DataActionsUnion = SetCouponStates | SetUORList
  17.  
  18. ---------------- REDUCER -------------------
  19.  
  20. const initialState: DataState = new DataState();
  21.  
  22. export function dataReducer(state: DataState = initialState, action: DataActionsUnion) {
  23. if (action.type.includes('[Data]')) {
  24. console.log('[Reducer] ' + action.type);
  25. }
  26. const controller = new Controller();
  27. switch (action.type) {
  28. case DataActions.SetCouponStates:
  29. return controller.setCouponStates(state, action.payload);
  30. case DataActions.SetUORList:
  31. return controller.setCouponStates(state, action.payload);
  32. default:
  33. return state;
  34. }
  35. }
  36.  
  37. class Controller {
  38. setCouponStates(state: DataState, couponStates: StatoTagliando[]): DataState {
  39. return { ...state, couponStates: couponStates }
  40. }
  41.  
  42. setUORList(state: DataState, uorList: UnitaOrganizzativa[]): DataState {
  43. return { ...state, uorList: uorList }
  44. }
  45. }
  46.  
  47. Argument of type 'StatoTagliando[] | UnitaOrganizzativa[]' is not assignable to parameter of type 'StatoTagliando[]'.
  48. Type 'UnitaOrganizzativa[]' is not assignable to type 'StatoTagliando[]'.
  49. Type 'UnitaOrganizzativa' is missing the following properties from type 'StatoTagliando': codiceStato, descrizioneStato
Add Comment
Please, Sign In to add comment