Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

reducer.ts 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { ComponentType } from 'react';
  2. import ReducerRegistry from '../redux/ReducerRegistry';
  3. import { assign } from '../redux/functions';
  4. import {
  5. HIDE_DIALOG,
  6. HIDE_SHEET,
  7. OPEN_DIALOG,
  8. OPEN_SHEET
  9. } from './actionTypes';
  10. export interface IDialogState {
  11. component?: ComponentType;
  12. componentProps?: Object;
  13. isNewDialog?: boolean;
  14. sheet?: ComponentType;
  15. sheetProps?: Object;
  16. }
  17. /**
  18. * Reduces redux actions which show or hide dialogs.
  19. *
  20. * @param {IDialogState} state - The current redux state.
  21. * @param {Action} action - The redux action to reduce.
  22. * @param {string} action.type - The type of the redux action to reduce..
  23. * @returns {State} The next redux state that is the result of reducing the
  24. * specified action.
  25. */
  26. ReducerRegistry.register<IDialogState>('features/base/dialog', (state = {}, action): IDialogState => {
  27. switch (action.type) {
  28. case HIDE_DIALOG: {
  29. const { component } = action;
  30. if (typeof component === 'undefined' || state.component === component) {
  31. return assign(state, {
  32. component: undefined,
  33. componentProps: undefined
  34. });
  35. }
  36. break;
  37. }
  38. case OPEN_DIALOG:
  39. return assign(state, {
  40. component: action.component,
  41. componentProps: action.componentProps,
  42. isNewDialog: action.isNewDialog
  43. });
  44. case HIDE_SHEET:
  45. return assign(state, {
  46. sheet: undefined,
  47. sheetProps: undefined
  48. });
  49. case OPEN_SHEET:
  50. return assign(state, {
  51. sheet: action.component,
  52. sheetProps: action.componentProps
  53. });
  54. }
  55. return state;
  56. });