Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

reducer.ts 1.2KB

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