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.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // @flow
  2. import { equals, ReducerRegistry, set } from '../redux';
  3. import { SET_LOG_COLLECTOR, SET_LOGGING_CONFIG } from './actionTypes';
  4. // eslint-disable-next-line
  5. const LOGGING_CONFIG = require('../../../../logging_config.js');
  6. /**
  7. * The default/initial redux state of the feature base/logging.
  8. *
  9. * @type {{
  10. * config: Object
  11. * }}
  12. */
  13. const DEFAULT_STATE = {
  14. config: LOGGING_CONFIG,
  15. /**
  16. * The log collector.
  17. */
  18. logCollector: undefined
  19. };
  20. // Reduce verbosity on mobile, it kills performance.
  21. if (navigator.product === 'ReactNative') {
  22. const RN_LOGGING_CONFIG = {
  23. 'modules/sdp/SDPUtil.js': 'info',
  24. 'modules/xmpp/ChatRoom.js': 'warn',
  25. 'modules/xmpp/JingleSessionPC.js': 'info',
  26. 'modules/xmpp/strophe.jingle.js': 'info'
  27. };
  28. DEFAULT_STATE.config = {
  29. ...LOGGING_CONFIG,
  30. ...RN_LOGGING_CONFIG
  31. };
  32. }
  33. ReducerRegistry.register(
  34. 'features/base/logging',
  35. (state = DEFAULT_STATE, action) => {
  36. switch (action.type) {
  37. case SET_LOGGING_CONFIG:
  38. return _setLoggingConfig(state, action);
  39. case SET_LOG_COLLECTOR: {
  40. return _setLogCollector(state, action);
  41. }
  42. default:
  43. return state;
  44. }
  45. });
  46. /**
  47. * Reduces a specific Redux action SET_LOGGING_CONFIG of the feature
  48. * base/logging.
  49. *
  50. * @param {Object} state - The Redux state of the feature base/logging.
  51. * @param {Action} action - The Redux action SET_LOGGING_CONFIG to reduce.
  52. * @private
  53. * @returns {Object} The new state of the feature base/logging after the
  54. * reduction of the specified action.
  55. */
  56. function _setLoggingConfig(state, action) {
  57. const config = {
  58. // The config of DEFAULT_STATE is the default configuration of the
  59. // feature base/logging.
  60. ...DEFAULT_STATE.config,
  61. ...action.config
  62. };
  63. if (equals(state.config, config)) {
  64. return state;
  65. }
  66. return {
  67. ...state,
  68. config
  69. };
  70. }
  71. /**
  72. * Reduces a specific Redux action SET_LOG_COLLECTOR of the feature
  73. * base/logging.
  74. *
  75. * @param {Object} state - The Redux state of the feature base/logging.
  76. * @param {Action} action - The Redux action SET_LOG_COLLECTOR to reduce.
  77. * @private
  78. * @returns {Object} The new state of the feature base/logging after the
  79. * reduction of the specified action.
  80. */
  81. function _setLogCollector(state, action) {
  82. return set(state, 'logCollector', action.logCollector);
  83. }