diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-05 08:03:29 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-06 22:17:18 +0900 |
commit | a0882bbceb7ed71d56bf8557620449fbc3f19749 (patch) | |
tree | f2087d44f21dd68fc3584f62cfb9b62ae58bab2b /src/content/components | |
parent | d01db82c0dca352de2d7644c383d388fc3ec0366 (diff) |
Declare setting types
Diffstat (limited to 'src/content/components')
-rw-r--r-- | src/content/components/common/index.ts | 5 | ||||
-rw-r--r-- | src/content/components/common/input.ts | 1 | ||||
-rw-r--r-- | src/content/components/common/keymapper.ts | 28 | ||||
-rw-r--r-- | src/content/components/common/mark.ts | 10 | ||||
-rw-r--r-- | src/content/components/top-content/follow-controller.ts | 4 |
5 files changed, 27 insertions, 21 deletions
diff --git a/src/content/components/common/index.ts b/src/content/components/common/index.ts index 9b5164e..8bd697f 100644 --- a/src/content/components/common/index.ts +++ b/src/content/components/common/index.ts @@ -8,6 +8,7 @@ import MessageListener from '../../MessageListener'; import * as addonActions from '../../actions/addon'; import * as blacklists from '../../../shared/blacklists'; import * as keys from '../../../shared/utils/keys'; +import * as actions from '../../actions'; export default class Common { private win: Window; @@ -45,9 +46,9 @@ export default class Common { reloadSettings() { try { this.store.dispatch(settingActions.load()) - .then(({ value: settings }: any) => { + .then((action: actions.SettingAction) => { let enabled = !blacklists.includes( - settings.blacklist, this.win.location.href + action.settings.blacklist, this.win.location.href ); this.store.dispatch(addonActions.setEnabled(enabled)); }); diff --git a/src/content/components/common/input.ts b/src/content/components/common/input.ts index 64eb5f3..1fe34c9 100644 --- a/src/content/components/common/input.ts +++ b/src/content/components/common/input.ts @@ -61,7 +61,6 @@ export default class InputComponent { } let key = keys.fromKeyboardEvent(e); - for (let listener of this.onKeyListeners) { let stop = listener(key); if (stop) { diff --git a/src/content/components/common/keymapper.ts b/src/content/components/common/keymapper.ts index d9c9834..c94bae0 100644 --- a/src/content/components/common/keymapper.ts +++ b/src/content/components/common/keymapper.ts @@ -3,7 +3,10 @@ import * as operationActions from '../../actions/operation'; import * as operations from '../../../shared/operations'; import * as keyUtils from '../../../shared/utils/keys'; -const mapStartsWith = (mapping, keys) => { +const mapStartsWith = ( + mapping: keyUtils.Key[], + keys: keyUtils.Key[], +): boolean => { if (mapping.length < keys.length) { return false; } @@ -16,26 +19,33 @@ const mapStartsWith = (mapping, keys) => { }; export default class KeymapperComponent { - constructor(store) { + private store: any; + + constructor(store: any) { this.store = store; } // eslint-disable-next-line max-statements - key(key) { + key(key: keyUtils.Key): boolean { this.store.dispatch(inputActions.keyPress(key)); let state = this.store.getState(); let input = state.input; - let keymaps = new Map(state.setting.keymaps); + let keymaps = new Map<keyUtils.Key[], operations.Operation>( + state.setting.keymaps.map( + (e: {key: keyUtils.Key[], op: operations.Operation}) => [e.key, e.op], + ) + ); - let matched = Array.from(keymaps.keys()).filter((mapping) => { - return mapStartsWith(mapping, input.keys); - }); + let matched = Array.from(keymaps.keys()).filter( + (mapping: keyUtils.Key[]) => { + return mapStartsWith(mapping, input.keys); + }); if (!state.addon.enabled) { // available keymaps are only ADDON_ENABLE and ADDON_TOGGLE_ENABLED if // the addon disabled matched = matched.filter((keys) => { - let type = keymaps.get(keys).type; + let type = (keymaps.get(keys) as operations.Operation).type; return type === operations.ADDON_ENABLE || type === operations.ADDON_TOGGLE_ENABLED; }); @@ -47,7 +57,7 @@ export default class KeymapperComponent { matched.length === 1 && input.keys.length < matched[0].length) { return true; } - let operation = keymaps.get(matched[0]); + let operation = keymaps.get(matched[0]) as operations.Operation; let act = operationActions.exec( operation, state.setting, state.addon.enabled ); diff --git a/src/content/components/common/mark.ts b/src/content/components/common/mark.ts index 500d03b..686116c 100644 --- a/src/content/components/common/mark.ts +++ b/src/content/components/common/mark.ts @@ -1,7 +1,6 @@ -import * as markActions from 'content/actions/mark'; -import * as scrolls from 'content/scrolls'; -import * as consoleFrames from 'content/console-frames'; -import * as properties from 'shared/settings/properties'; +import * as markActions from '../../actions/mark'; +import * as scrolls from '../..//scrolls'; +import * as consoleFrames from '../..//console-frames'; const cancelKey = (key): boolean => { return key.key === 'Esc' || key.key === '[' && key.ctrlKey; @@ -20,8 +19,7 @@ export default class MarkComponent { // eslint-disable-next-line max-statements key(key) { let { mark: markStage, setting } = this.store.getState(); - let smoothscroll = setting.properties.smoothscroll || - properties.defaults.smoothscroll; + let smoothscroll = setting.properties.smoothscroll; if (!markStage.setMode && !markStage.jumpMode) { return false; diff --git a/src/content/components/top-content/follow-controller.ts b/src/content/components/top-content/follow-controller.ts index be71f6e..d49b22a 100644 --- a/src/content/components/top-content/follow-controller.ts +++ b/src/content/components/top-content/follow-controller.ts @@ -2,7 +2,6 @@ import * as followControllerActions from '../../actions/follow-controller'; import * as messages from '../../../shared/messages'; import MessageListener, { WebMessageSender } from '../../MessageListener'; import HintKeyProducer from '../../hint-key-producer'; -import * as properties from '../../../shared/settings/properties'; const broadcastMessage = (win: Window, message: messages.Message): void => { let json = JSON.stringify(message); @@ -162,7 +161,6 @@ export default class FollowController { } hintchars() { - return this.store.getState().setting.properties.hintchars || - properties.defaults.hintchars; + return this.store.getState().setting.properties.hintchars; } } |