Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

reducer.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // @flow
  2. import { equals, ReducerRegistry, set } from '../redux';
  3. import { SET_LOG_COLLECTOR, SET_LOGGING_CONFIG } from './actionTypes';
  4. /**
  5. * The default/initial redux state of the feature base/logging.
  6. *
  7. * @type {{
  8. * config: Object
  9. * }}
  10. */
  11. const DEFAULT_STATE = {
  12. config: require('../../../../logging_config.js'),
  13. /**
  14. * The log collector.
  15. */
  16. logCollector: undefined
  17. };
  18. ReducerRegistry.register(
  19. 'features/base/logging',
  20. (state = DEFAULT_STATE, action) => {
  21. switch (action.type) {
  22. case SET_LOGGING_CONFIG:
  23. return _setLoggingConfig(state, action);
  24. case SET_LOG_COLLECTOR: {
  25. return _setLogCollector(state, action);
  26. }
  27. default:
  28. return state;
  29. }
  30. });
  31. /**
  32. * Reduces a specific Redux action SET_LOGGING_CONFIG of the feature
  33. * base/logging.
  34. *
  35. * @param {Object} state - The Redux state of the feature base/logging.
  36. * @param {Action} action - The Redux action SET_LOGGING_CONFIG to reduce.
  37. * @private
  38. * @returns {Object} The new state of the feature base/logging after the
  39. * reduction of the specified action.
  40. */
  41. function _setLoggingConfig(state, action) {
  42. const config = {
  43. // The config of DEFAULT_STATE is the default configuration of the
  44. // feature base/logging.
  45. ...DEFAULT_STATE.config,
  46. ...action.config
  47. };
  48. if (equals(state.config, config)) {
  49. return state;
  50. }
  51. return {
  52. ...state,
  53. config
  54. };
  55. }
  56. /**
  57. * Reduces a specific Redux action SET_LOG_COLLECTOR of the feature
  58. * base/logging.
  59. *
  60. * @param {Object} state - The Redux state of the feature base/logging.
  61. * @param {Action} action - The Redux action SET_LOG_COLLECTOR to reduce.
  62. * @private
  63. * @returns {Object} The new state of the feature base/logging after the
  64. * reduction of the specified action.
  65. */
  66. function _setLogCollector(state, action) {
  67. return set(state, 'logCollector', action.logCollector);
  68. }