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

reducer.ts 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import PersistenceRegistry from '../base/redux/PersistenceRegistry';
  2. import ReducerRegistry from '../base/redux/ReducerRegistry';
  3. import {
  4. DISABLE_KEYBOARD_SHORTCUTS,
  5. ENABLE_KEYBOARD_SHORTCUTS,
  6. REGISTER_KEYBOARD_SHORTCUT,
  7. UNREGISTER_KEYBOARD_SHORTCUT
  8. } from './actionTypes';
  9. import { IKeyboardShortcutsState } from './types';
  10. /**
  11. * The redux subtree of this feature.
  12. */
  13. const STORE_NAME = 'features/keyboard-shortcuts';
  14. const defaultState = {
  15. enabled: true,
  16. shortcuts: new Map(),
  17. shortcutsHelp: new Map()
  18. };
  19. PersistenceRegistry.register(STORE_NAME, {
  20. enabled: true
  21. });
  22. ReducerRegistry.register<IKeyboardShortcutsState>(STORE_NAME,
  23. (state = defaultState, action): IKeyboardShortcutsState => {
  24. switch (action.type) {
  25. case ENABLE_KEYBOARD_SHORTCUTS:
  26. return {
  27. ...state,
  28. enabled: true
  29. };
  30. case DISABLE_KEYBOARD_SHORTCUTS:
  31. return {
  32. ...state,
  33. enabled: false
  34. };
  35. case REGISTER_KEYBOARD_SHORTCUT: {
  36. const shortcutKey = action.shortcut.alt ? `:${action.shortcut.character}` : action.shortcut.character;
  37. return {
  38. ...state,
  39. shortcuts: new Map(state.shortcuts)
  40. .set(shortcutKey, action.shortcut),
  41. shortcutsHelp: action.shortcut.helpDescription
  42. ? new Map(state.shortcutsHelp)
  43. .set(action.shortcut.helpCharacter ?? shortcutKey, action.shortcut.helpDescription)
  44. : state.shortcutsHelp
  45. };
  46. }
  47. case UNREGISTER_KEYBOARD_SHORTCUT: {
  48. const shortcutKey = action.alt ? `:${action.character}` : action.character;
  49. const shortcuts = new Map(state.shortcuts);
  50. shortcuts.delete(shortcutKey);
  51. const shortcutsHelp = new Map(state.shortcutsHelp);
  52. shortcutsHelp.delete(shortcutKey);
  53. return {
  54. ...state,
  55. shortcuts,
  56. shortcutsHelp
  57. };
  58. }
  59. }
  60. return state;
  61. });