Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

reducer.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { ReducerRegistry } from '../base/redux';
  2. import {
  3. CLEAR_RECORDING_SESSIONS,
  4. RECORDING_SESSION_UPDATED,
  5. SET_PENDING_RECORDING_NOTIFICATION_UID
  6. } from './actionTypes';
  7. const DEFAULT_STATE = {
  8. sessionDatas: []
  9. };
  10. /**
  11. * Reduces the Redux actions of the feature features/recording.
  12. */
  13. ReducerRegistry.register('features/recording',
  14. (state = DEFAULT_STATE, action) => {
  15. switch (action.type) {
  16. case CLEAR_RECORDING_SESSIONS:
  17. return {
  18. ...state,
  19. sessionDatas: []
  20. };
  21. case RECORDING_SESSION_UPDATED:
  22. return {
  23. ...state,
  24. sessionDatas:
  25. _updateSessionDatas(state.sessionDatas, action.sessionData)
  26. };
  27. case SET_PENDING_RECORDING_NOTIFICATION_UID:
  28. return {
  29. ...state,
  30. pendingNotificationUid: action.uid
  31. };
  32. default:
  33. return state;
  34. }
  35. });
  36. /**
  37. * Updates the known information on recording sessions.
  38. *
  39. * @param {Array} sessionDatas - The current sessions in the redux store.
  40. * @param {Object} newSessionData - The updated session data.
  41. * @private
  42. * @returns {Array} The session datas with the updated session data added.
  43. */
  44. function _updateSessionDatas(sessionDatas, newSessionData) {
  45. const hasExistingSessionData = sessionDatas.find(
  46. sessionData => sessionData.id === newSessionData.id);
  47. let newSessionDatas;
  48. if (hasExistingSessionData) {
  49. newSessionDatas = sessionDatas.map(sessionData => {
  50. if (sessionData.id === newSessionData.id) {
  51. return {
  52. ...newSessionData
  53. };
  54. }
  55. // Nothing to update for this session data so pass it back in.
  56. return sessionData;
  57. });
  58. } else {
  59. // If the session data is not present, then there is nothing to update
  60. // and instead it needs to be added to the known session datas.
  61. newSessionDatas = [
  62. ...sessionDatas,
  63. { ...newSessionData }
  64. ];
  65. }
  66. return newSessionDatas;
  67. }