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 2.0KB

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