Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

reducer.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // @flow
  2. import { ReducerRegistry } from '../base/redux';
  3. import {
  4. TOGGLE_REACTIONS_VISIBLE,
  5. SET_REACTION_QUEUE,
  6. ADD_REACTION_BUFFER,
  7. FLUSH_REACTION_BUFFER,
  8. SHOW_SOUNDS_NOTIFICATION
  9. } from './actionTypes';
  10. /**
  11. * Returns initial state for reactions' part of Redux store.
  12. *
  13. * @private
  14. * @returns {{
  15. * visible: boolean,
  16. * message: string,
  17. * timeoutID: number,
  18. * queue: Array,
  19. * notificationDisplayed: boolean
  20. * }}
  21. */
  22. function _getInitialState() {
  23. return {
  24. /**
  25. * The indicator that determines whether the reactions menu is visible.
  26. *
  27. * @type {boolean}
  28. */
  29. visible: false,
  30. /**
  31. * An array that contains the reactions buffer to be sent.
  32. *
  33. * @type {Array}
  34. */
  35. buffer: [],
  36. /**
  37. * A number, non-zero value which identifies the timer created by a call
  38. * to setTimeout().
  39. *
  40. * @type {number|null}
  41. */
  42. timeoutID: null,
  43. /**
  44. * The array of reactions to animate
  45. *
  46. * @type {Array}
  47. */
  48. queue: [],
  49. /**
  50. * Whether or not the disable reaction sounds notification was shown
  51. */
  52. notificationDisplayed: false
  53. };
  54. }
  55. ReducerRegistry.register(
  56. 'features/reactions',
  57. (state: Object = _getInitialState(), action: Object) => {
  58. switch (action.type) {
  59. case TOGGLE_REACTIONS_VISIBLE:
  60. return {
  61. ...state,
  62. visible: !state.visible
  63. };
  64. case ADD_REACTION_BUFFER:
  65. return {
  66. ...state,
  67. buffer: action.buffer,
  68. timeoutID: action.timeoutID
  69. };
  70. case FLUSH_REACTION_BUFFER:
  71. return {
  72. ...state,
  73. buffer: [],
  74. timeoutID: null
  75. };
  76. case SET_REACTION_QUEUE: {
  77. return {
  78. ...state,
  79. queue: action.value
  80. };
  81. }
  82. case SHOW_SOUNDS_NOTIFICATION: {
  83. return {
  84. ...state,
  85. notificationDisplayed: true
  86. };
  87. }
  88. }
  89. return state;
  90. });