volume.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { Map } from "immutable";
  2. const CHANGE_VOLUME_LOUDNESS = "VOLUME::CHANGE_VOLUME_LOUDNESS";
  3. const MUTE_VOLUME = "VOLUME::MUTE_VOLUME";
  4. const UNMUTE_VOLUME = "VOLUME::UNMUTE_VOLUME";
  5. function changeVolumeLoudness(loudness) {
  6. return {
  7. type: CHANGE_VOLUME_LOUDNESS,
  8. loudness,
  9. }
  10. }
  11. function muteVolume() {
  12. return {
  13. type: MUTE_VOLUME,
  14. }
  15. }
  16. function unmuteVolume() {
  17. return {
  18. type: UNMUTE_VOLUME,
  19. }
  20. }
  21. const initialState = Map({
  22. loudness: 25,
  23. muted: false,
  24. });
  25. function reducer(state = initialState, action) {
  26. switch (action.type) {
  27. case CHANGE_VOLUME_LOUDNESS:
  28. const { loudness } = action;
  29. return state.merge({
  30. loudness,
  31. });
  32. case MUTE_VOLUME:
  33. return state.merge({
  34. muted: true,
  35. });
  36. case UNMUTE_VOLUME:
  37. return state.merge({
  38. muted: false,
  39. });
  40. }
  41. return state;
  42. }
  43. const actionCreators = {
  44. changeVolumeLoudness,
  45. muteVolume,
  46. unmuteVolume,
  47. };
  48. const actionTypes = {
  49. CHANGE_VOLUME_LOUDNESS,
  50. MUTE_VOLUME,
  51. UNMUTE_VOLUME,
  52. };
  53. export {
  54. actionCreators,
  55. actionTypes,
  56. };
  57. export default reducer;