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.

actions.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* @flow */
  2. import { HIDE_DIALOG, OPEN_DIALOG } from './actionTypes';
  3. import { isDialogOpen } from './functions';
  4. /**
  5. * Signals Dialog to close its dialog.
  6. *
  7. * @param {Object} [component] - The {@code Dialog} component to close/hide. If
  8. * {@code undefined}, closes/hides {@code Dialog} regardless of which
  9. * component it's rendering; otherwise, closes/hides {@code Dialog} only if
  10. * it's rendering the specified {@code component}.
  11. * @returns {{
  12. * type: HIDE_DIALOG,
  13. * component: (React.Component | undefined)
  14. * }}
  15. */
  16. export function hideDialog(component: ?Object) {
  17. return {
  18. type: HIDE_DIALOG,
  19. component
  20. };
  21. }
  22. /**
  23. * Signals Dialog to open dialog.
  24. *
  25. * @param {Object} component - The component to display as dialog.
  26. * @param {Object} [componentProps] - The React {@code Component} props of the
  27. * specified {@code component}.
  28. * @returns {{
  29. * type: OPEN_DIALOG,
  30. * component: React.Component,
  31. * componentProps: (Object | undefined)
  32. * }}
  33. */
  34. export function openDialog(component: Object, componentProps: ?Object) {
  35. return {
  36. type: OPEN_DIALOG,
  37. component,
  38. componentProps
  39. };
  40. }
  41. /**
  42. * Signals Dialog to open a dialog with the specified component if the component
  43. * is not already open. If it is open, then Dialog is signaled to close its
  44. * dialog.
  45. *
  46. * @param {Object} component - The component to display as dialog.
  47. * @param {Object} [componentProps] - The React {@code Component} props of the
  48. * specified {@code component}.
  49. * @returns {Function}
  50. */
  51. export function toggleDialog(component: Object, componentProps: ?Object) {
  52. return (dispatch: Dispatch, getState: Function) => {
  53. if (isDialogOpen(getState, component)) {
  54. dispatch(hideDialog(component));
  55. } else {
  56. dispatch(openDialog(component, componentProps));
  57. }
  58. };
  59. }