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.

middleware.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* @flow */
  2. import { SET_CONFIG } from '../config';
  3. import { MiddlewareRegistry } from '../redux';
  4. declare var APP: Object;
  5. /**
  6. * The redux middleware of the feature base/i18n.
  7. *
  8. * @param {Store} store - The redux store.
  9. * @returns {Function}
  10. * @private
  11. */
  12. MiddlewareRegistry.register(store => next => action => {
  13. switch (action.type) {
  14. case SET_CONFIG:
  15. return _setConfig(store, next, action);
  16. }
  17. return next(action);
  18. });
  19. /**
  20. * Notifies the feature base/i18n that the action SET_CONFIG is being dispatched
  21. * within a specific redux store.
  22. *
  23. * @param {Store} store - The redux store in which the specified action is being
  24. * dispatched.
  25. * @param {Dispatch} next - The redux dispatch function to dispatch the
  26. * specified action to the specified store.
  27. * @param {Action} action - The redux action SET_CONFIG which is being
  28. * dispatched in the specified store.
  29. * @private
  30. * @returns {Object} The new state that is the result of the reduction of the
  31. * specified action.
  32. */
  33. function _setConfig({ getState }, next, action) {
  34. const oldValue = getState()['features/base/config'];
  35. const result = next(action);
  36. const newValue = getState()['features/base/config'];
  37. if (oldValue !== newValue && typeof APP === 'object') {
  38. APP.translation.init();
  39. }
  40. return result;
  41. }