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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import {
  4. HIDE_DIALOG,
  5. HIDE_SHEET,
  6. OPEN_DIALOG,
  7. OPEN_SHEET
  8. } from './actionTypes';
  9. import { isDialogOpen } from './functions';
  10. /**
  11. * Signals Dialog to close its dialog.
  12. *
  13. * @param {Object} [component] - The {@code Dialog} component to close/hide. If
  14. * {@code undefined}, closes/hides {@code Dialog} regardless of which
  15. * component it's rendering; otherwise, closes/hides {@code Dialog} only if
  16. * it's rendering the specified {@code component}.
  17. * @returns {{
  18. * type: HIDE_DIALOG,
  19. * component: (React.Component | undefined)
  20. * }}
  21. */
  22. export function hideDialog(component: ?Object) {
  23. return {
  24. type: HIDE_DIALOG,
  25. component
  26. };
  27. }
  28. /**
  29. * Closes the active sheet.
  30. *
  31. * @returns {{
  32. * type: HIDE_SHEET,
  33. * }}
  34. */
  35. export function hideSheet() {
  36. return {
  37. type: HIDE_SHEET
  38. };
  39. }
  40. /**
  41. * Signals Dialog to open dialog.
  42. *
  43. * @param {Object} component - The component to display as dialog.
  44. * @param {Object} [componentProps] - The React {@code Component} props of the
  45. * specified {@code component}.
  46. * @returns {{
  47. * type: OPEN_DIALOG,
  48. * component: React.Component,
  49. * componentProps: (Object | undefined)
  50. * }}
  51. */
  52. export function openDialog(component: Object, componentProps: ?Object) {
  53. return {
  54. type: OPEN_DIALOG,
  55. component,
  56. componentProps
  57. };
  58. }
  59. /**
  60. * Opens the requested sheet.
  61. *
  62. * @param {Object} component - The component to display as a sheet.
  63. * @param {Object} [componentProps] - The React {@code Component} props of the
  64. * specified {@code component}.
  65. * @returns {{
  66. * type: OPEN_SHEET,
  67. * component: React.Component,
  68. * componentProps: (Object | undefined)
  69. * }}
  70. */
  71. export function openSheet(component: Object, componentProps: ?Object) {
  72. return {
  73. type: OPEN_SHEET,
  74. component,
  75. componentProps
  76. };
  77. }
  78. /**
  79. * Signals Dialog to open a dialog with the specified component if the component
  80. * is not already open. If it is open, then Dialog is signaled to close its
  81. * dialog.
  82. *
  83. * @param {Object} component - The component to display as dialog.
  84. * @param {Object} [componentProps] - The React {@code Component} props of the
  85. * specified {@code component}.
  86. * @returns {Function}
  87. */
  88. export function toggleDialog(component: Object, componentProps: ?Object) {
  89. return (dispatch: Dispatch<any>, getState: Function) => {
  90. if (isDialogOpen(getState, component)) {
  91. dispatch(hideDialog(component));
  92. } else {
  93. dispatch(openDialog(component, componentProps));
  94. }
  95. };
  96. }