You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reducer.ts 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // @ts-expect-error
  2. import { Transport } from '../../../modules/transport';
  3. import ReducerRegistry from '../base/redux/ReducerRegistry';
  4. import { set } from '../base/redux/functions';
  5. import {
  6. SET_TRANSPORT,
  7. SUSPEND_DETECTED
  8. } from './actionTypes';
  9. export interface IPowerMonitorState {
  10. suspendDetected?: boolean;
  11. transport?: Transport;
  12. }
  13. /**
  14. * Reduces the redux actions of the feature power monitor.
  15. */
  16. ReducerRegistry.register<IPowerMonitorState>('features/power-monitor', (state = {}, action): IPowerMonitorState => {
  17. switch (action.type) {
  18. case SET_TRANSPORT:
  19. return _setTransport(state, action.transport);
  20. case SUSPEND_DETECTED:
  21. return _suspendDetected(state);
  22. }
  23. return state;
  24. });
  25. /**
  26. * Reduces a specific redux action SET_TRANSPORT of the feature power monitor.
  27. *
  28. * @param {Object} state - The redux state of the feature power monitor.
  29. * @param {?Transport} transport - The transport to store in state.
  30. * @private
  31. * @returns {Object} The new state of the feature power monitor after the reduction of
  32. * the specified action.
  33. */
  34. function _setTransport(state: IPowerMonitorState, transport?: Transport) {
  35. return set(state, 'transport', transport);
  36. }
  37. /**
  38. * Reduces a specific redux action SUSPEND_DETECTED of the feature overlay.
  39. *
  40. * @param {Object} state - The redux state of the feature overlay.
  41. * @private
  42. * @returns {Object} The new state of the feature overlay after the reduction of
  43. * the specified action.
  44. */
  45. function _suspendDetected(state: IPowerMonitorState) {
  46. return set(state, 'suspendDetected', true);
  47. }