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.

actions.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. * @returns {{
  30. * type: OPEN_DIALOG,
  31. * component: React.Component,
  32. * componentProps: (Object | undefined)
  33. * }}
  34. */
  35. export function openDialog(component: Object, componentProps: ?Object) {
  36. return {
  37. type: OPEN_DIALOG,
  38. component,
  39. componentProps
  40. };
  41. }
  42. /**
  43. * Signals Dialog to open a dialog with the specified component if the component
  44. * is not already open. If it is open, then Dialog is signaled to close its
  45. * dialog.
  46. *
  47. * @param {Object} component - The component to display as dialog.
  48. * @param {Object} [componentProps] - The React {@code Component} props of the
  49. * specified {@code component}.
  50. * @returns {Function}
  51. */
  52. export function toggleDialog(component: Object, componentProps: ?Object) {
  53. return (dispatch: Dispatch<any>, getState: Function) => {
  54. if (isDialogOpen(getState, component)) {
  55. dispatch(hideDialog(component));
  56. } else {
  57. dispatch(openDialog(component, componentProps));
  58. }
  59. };
  60. }