You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reducer.js 2.0KB

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