Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

reducer.ts 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* eslint-disable lines-around-comment */
  2. import {
  3. SET_CONFIG
  4. } from '../config/actionTypes';
  5. import { IConfig } from '../config/configType';
  6. import ReducerRegistry from '../redux/ReducerRegistry';
  7. import { set } from '../redux/functions';
  8. import { SET_LAST_N } from './actionTypes';
  9. // @ts-ignore
  10. import { validateLastNLimits } from './functions';
  11. export interface ILastNState {
  12. lastNLimits?: {
  13. [key: number]: number;
  14. };
  15. lastN?: number;
  16. }
  17. ReducerRegistry.register('features/base/lastn', (state: ILastNState = { }, action) => {
  18. switch (action.type) {
  19. case SET_CONFIG:
  20. return _setConfig(state, action);
  21. case SET_LAST_N: {
  22. const { lastN } = action;
  23. return {
  24. ...state,
  25. lastN
  26. };
  27. }
  28. }
  29. return state;
  30. });
  31. /**
  32. * Reduces a specific Redux action SET_CONFIG.
  33. *
  34. * @param {Object} state - The Redux state of feature base/lastn.
  35. * @param {Action} action - The Redux action SET_CONFIG to reduce.
  36. * @private
  37. * @returns {Object} The new state after the reduction of the specified action.
  38. */
  39. function _setConfig(state: ILastNState, { config }: {config: IConfig}) {
  40. return set(state, 'lastNLimits', validateLastNLimits(config.lastNLimits));
  41. }