You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

middleware.web.ts 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { AnyAction } from 'redux';
  2. import { IStore } from '../app/types';
  3. import { hideDialog, openDialog } from '../base/dialog/actions';
  4. import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
  5. import { BEGIN_ADD_PEOPLE, HIDE_ADD_PEOPLE_DIALOG } from './actionTypes';
  6. import AddPeopleDialog from './components/add-people-dialog/web/AddPeopleDialog';
  7. import './middleware.any';
  8. /**
  9. * The middleware of the feature invite specific to Web/React.
  10. *
  11. * @param {Store} store - The redux store.
  12. * @returns {Function}
  13. */
  14. MiddlewareRegistry.register(store => next => action => {
  15. switch (action.type) {
  16. case BEGIN_ADD_PEOPLE:
  17. return _beginAddPeople(store, next, action);
  18. case HIDE_ADD_PEOPLE_DIALOG:
  19. return _hideAddPeopleDialog(store, next, action);
  20. }
  21. return next(action);
  22. });
  23. /**
  24. * Notifies the feature invite that the action {@link BEGIN_ADD_PEOPLE} is being
  25. * dispatched within a specific redux {@code store}.
  26. *
  27. * @param {Store} store - The redux store in which the specified {@code action}
  28. * is being dispatched.
  29. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  30. * specified {@code action} to the specified {@code store}.
  31. * @param {Action} action - The redux action {@code BEGIN_ADD_PEOPLE} which is
  32. * being dispatched in the specified {@code store}.
  33. * @private
  34. * @returns {*} The value returned by {@code next(action)}.
  35. */
  36. function _beginAddPeople({ dispatch }: IStore, next: Function, action: AnyAction) {
  37. const result = next(action);
  38. dispatch(openDialog(AddPeopleDialog));
  39. return result;
  40. }
  41. /**
  42. * Notifies the feature invite that the action {@link HIDE_ADD_PEOPLE_DIALOG} is being
  43. * dispatched within a specific redux {@code store}.
  44. *
  45. * @param {Store} store - The redux store in which the specified {@code action}
  46. * is being dispatched.
  47. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  48. * specified {@code action} to the specified {@code store}.
  49. * @param {Action} action - The redux action {@code HIDE_ADD_PEOPLE_DIALOG} which is
  50. * being dispatched in the specified {@code store}.
  51. * @private
  52. * @returns {*} The value returned by {@code next(action)}.
  53. */
  54. function _hideAddPeopleDialog({ dispatch }: IStore, next: Function, action: AnyAction) {
  55. dispatch(hideDialog(AddPeopleDialog));
  56. return next(action);
  57. }