Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

reducer.ts 1.6KB

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