您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.native.ts 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { OVERWRITE_CONFIG, SET_CONFIG, UPDATE_CONFIG } from '../base/config/actionTypes';
  2. import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
  3. import { I_AM_VISITOR_MODE } from '../visitors/actionTypes';
  4. import { SET_TOOLBAR_BUTTONS } from './actionTypes';
  5. import { setMainToolbarThresholds } from './actions.native';
  6. import { NATIVE_THRESHOLDS, NATIVE_TOOLBAR_BUTTONS } from './constants';
  7. import { getToolbarButtons } from './functions.native';
  8. /**
  9. * Middleware which intercepts Toolbox actions to handle changes to the
  10. * visibility timeout of the Toolbox.
  11. *
  12. * @param {Store} store - The redux store.
  13. * @returns {Function}
  14. */
  15. MiddlewareRegistry.register(store => next => action => {
  16. switch (action.type) {
  17. case UPDATE_CONFIG:
  18. case OVERWRITE_CONFIG:
  19. case I_AM_VISITOR_MODE:
  20. case SET_CONFIG: {
  21. const result = next(action);
  22. const { dispatch } = store;
  23. const state = store.getState();
  24. const toolbarButtons = getToolbarButtons(state, NATIVE_TOOLBAR_BUTTONS);
  25. if (action.type !== I_AM_VISITOR_MODE) {
  26. dispatch(setMainToolbarThresholds(NATIVE_THRESHOLDS));
  27. }
  28. dispatch({
  29. type: SET_TOOLBAR_BUTTONS,
  30. toolbarButtons
  31. });
  32. return result;
  33. }
  34. }
  35. return next(action);
  36. });