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

middleware.ts 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { IStore } from '../app/types';
  2. import { SET_CONFIG } from '../base/config/actionTypes';
  3. import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
  4. import { CAPTURE_EVENTS } from '../remote-control/actionTypes';
  5. import { disableKeyboardShortcuts, enableKeyboardShortcuts } from './actions';
  6. MiddlewareRegistry.register((store: IStore) => (next: Function) => (action: any) => {
  7. const { dispatch } = store;
  8. switch (action.type) {
  9. case CAPTURE_EVENTS:
  10. if (action.isCapturingEvents) {
  11. dispatch(disableKeyboardShortcuts());
  12. } else {
  13. dispatch(enableKeyboardShortcuts());
  14. }
  15. return next(action);
  16. case SET_CONFIG: {
  17. const result = next(action);
  18. const state = store.getState();
  19. const { disableShortcuts } = state['features/base/config'];
  20. if (disableShortcuts !== undefined) {
  21. if (disableShortcuts) {
  22. dispatch(disableKeyboardShortcuts());
  23. } else {
  24. dispatch(enableKeyboardShortcuts());
  25. }
  26. }
  27. return result;
  28. }
  29. }
  30. return next(action);
  31. });