Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

reducer.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { ReducerRegistry } from '../base/redux';
  2. import {
  3. REMOVE_TRANSCRIPT_MESSAGE,
  4. UPDATE_TRANSCRIPT_MESSAGE
  5. } from './actionTypes';
  6. /**
  7. * Default State for 'features/transcription' feature
  8. */
  9. const defaultState = {
  10. transcriptMessages: new Map()
  11. };
  12. /**
  13. * Listen for actions for the transcription feature to be used by the actions
  14. * to update the rendered transcription subtitles.
  15. */
  16. ReducerRegistry.register('features/subtitles', (
  17. state = defaultState, action) => {
  18. switch (action.type) {
  19. case REMOVE_TRANSCRIPT_MESSAGE:
  20. return _removeTranscriptMessage(state, action);
  21. case UPDATE_TRANSCRIPT_MESSAGE:
  22. return _updateTranscriptMessage(state, action);
  23. }
  24. return state;
  25. });
  26. /**
  27. * Reduces a specific Redux action REMOVE_TRANSCRIPT_MESSAGE of the feature
  28. * transcription.
  29. *
  30. * @param {Object} state - The Redux state of the feature transcription.
  31. * @param {Action} action -The Redux action REMOVE_TRANSCRIPT_MESSAGE to reduce.
  32. * @returns {Object} The new state of the feature transcription after the
  33. * reduction of the specified action.
  34. */
  35. function _removeTranscriptMessage(state, { transcriptMessageID }) {
  36. const newTranscriptMessages = new Map(state.transcriptMessages);
  37. // Deletes the key from Map once a final message arrives.
  38. newTranscriptMessages.delete(transcriptMessageID);
  39. return {
  40. ...state,
  41. transcriptMessages: newTranscriptMessages
  42. };
  43. }
  44. /**
  45. * Reduces a specific Redux action UPDATE_TRANSCRIPT_MESSAGE of the feature
  46. * transcription.
  47. *
  48. * @param {Object} state - The Redux state of the feature transcription.
  49. * @param {Action} action -The Redux action UPDATE_TRANSCRIPT_MESSAGE to reduce.
  50. * @returns {Object} The new state of the feature transcription after the
  51. * reduction of the specified action.
  52. */
  53. function _updateTranscriptMessage(state,
  54. { transcriptMessageID, newTranscriptMessage }) {
  55. const newTranscriptMessages = new Map(state.transcriptMessages);
  56. // Updates the new message for the given key in the Map.
  57. newTranscriptMessages.set(transcriptMessageID, newTranscriptMessage);
  58. return {
  59. ...state,
  60. transcriptMessages: newTranscriptMessages
  61. };
  62. }