2022-10-19 08:42:54 +00:00
|
|
|
// @ts-expect-error
|
2019-07-12 13:08:34 +00:00
|
|
|
import { Transport } from '../../../modules/transport';
|
2022-08-26 09:54:16 +00:00
|
|
|
import ReducerRegistry from '../base/redux/ReducerRegistry';
|
|
|
|
import { set } from '../base/redux/functions';
|
2019-07-12 13:08:34 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
SET_TRANSPORT,
|
|
|
|
SUSPEND_DETECTED
|
|
|
|
} from './actionTypes';
|
|
|
|
|
2022-08-26 09:54:16 +00:00
|
|
|
export interface IPowerMonitorState {
|
|
|
|
suspendDetected?: boolean;
|
|
|
|
transport?: Transport;
|
|
|
|
}
|
|
|
|
|
2019-07-12 13:08:34 +00:00
|
|
|
/**
|
|
|
|
* Reduces the redux actions of the feature power monitor.
|
|
|
|
*/
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<IPowerMonitorState>('features/power-monitor', (state = {}, action): IPowerMonitorState => {
|
2019-07-12 13:08:34 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case SET_TRANSPORT:
|
|
|
|
return _setTransport(state, action.transport);
|
|
|
|
|
|
|
|
case SUSPEND_DETECTED:
|
|
|
|
return _suspendDetected(state);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces a specific redux action SET_TRANSPORT of the feature power monitor.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state of the feature power monitor.
|
|
|
|
* @param {?Transport} transport - The transport to store in state.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature power monitor after the reduction of
|
|
|
|
* the specified action.
|
|
|
|
*/
|
2022-08-26 09:54:16 +00:00
|
|
|
function _setTransport(state: IPowerMonitorState, transport?: Transport) {
|
2019-07-12 13:08:34 +00:00
|
|
|
return set(state, 'transport', transport);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces a specific redux action SUSPEND_DETECTED of the feature overlay.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state of the feature overlay.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state of the feature overlay after the reduction of
|
|
|
|
* the specified action.
|
|
|
|
*/
|
2022-08-26 09:54:16 +00:00
|
|
|
function _suspendDetected(state: IPowerMonitorState) {
|
2019-07-12 13:08:34 +00:00
|
|
|
return set(state, 'suspendDetected', true);
|
|
|
|
}
|
|
|
|
|