2022-07-19 07:58:56 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
2020-08-03 17:39:17 +00:00
|
|
|
import {
|
|
|
|
SET_CONFIG
|
2022-07-19 07:58:56 +00:00
|
|
|
} from '../config/actionTypes';
|
|
|
|
import { IConfig } from '../config/configType';
|
|
|
|
import ReducerRegistry from '../redux/ReducerRegistry';
|
|
|
|
import { set } from '../redux/functions';
|
2020-08-03 17:39:17 +00:00
|
|
|
|
2021-04-28 23:00:20 +00:00
|
|
|
import { SET_LAST_N } from './actionTypes';
|
2020-08-03 17:39:17 +00:00
|
|
|
import { validateLastNLimits } from './functions';
|
|
|
|
|
2022-07-19 07:58:56 +00:00
|
|
|
export interface ILastNState {
|
2022-07-20 08:47:01 +00:00
|
|
|
lastN?: number;
|
2022-07-19 07:58:56 +00:00
|
|
|
lastNLimits?: {
|
|
|
|
[key: number]: number;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<ILastNState>('features/base/lastn', (state = {}, action): ILastNState => {
|
2020-08-03 17:39:17 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case SET_CONFIG:
|
|
|
|
return _setConfig(state, action);
|
2021-04-28 23:00:20 +00:00
|
|
|
case SET_LAST_N: {
|
|
|
|
const { lastN } = action;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
lastN
|
|
|
|
};
|
|
|
|
}
|
2020-08-03 17:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces a specific Redux action SET_CONFIG.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state of feature base/lastn.
|
|
|
|
* @param {Action} action - The Redux action SET_CONFIG to reduce.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The new state after the reduction of the specified action.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
function _setConfig(state: ILastNState, { config }: { config: IConfig; }) {
|
2020-08-03 17:39:17 +00:00
|
|
|
return set(state, 'lastNLimits', validateLastNLimits(config.lastNLimits));
|
|
|
|
}
|