From 59f7ef205df4750063c755a7b8834bfd7509da83 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 21 Oct 2017 13:26:36 +0900 Subject: add addon actions --- src/content/reducers/addon.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/content/reducers/addon.js (limited to 'src/content/reducers') diff --git a/src/content/reducers/addon.js b/src/content/reducers/addon.js new file mode 100644 index 0000000..8cc5ef1 --- /dev/null +++ b/src/content/reducers/addon.js @@ -0,0 +1,24 @@ +import actions from 'content/actions'; + +const defaultState = { + enabled: true, +}; + +export default function reducer(state = defaultState, action = {}) { + switch (action.type) { + case actions.ADDON_ENABLE: + return Object.assign({}, state, { + enabled: true, + }); + case actions.ADDON_DISABLE: + return Object.assign({}, state, { + enabled: false, + }); + case actions.ADDON_TOGGLE_ENABLED: + return Object.assign({}, state, { + enabled: !state.enabled, + }); + default: + return state; + } +} -- cgit v1.2.3 From dc6d93c1da28ed17fe1bc5be07bdfab30a40dd66 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 21 Oct 2017 19:40:22 +0900 Subject: enable/disable addon by keys --- src/content/actions/operation.js | 7 +++++++ src/content/components/common/keymapper.js | 12 ++++++++++++ src/content/reducers/index.js | 3 +++ src/shared/operations.js | 5 +++++ 4 files changed, 27 insertions(+) (limited to 'src/content/reducers') diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js index 81bcc2f..897f361 100644 --- a/src/content/actions/operation.js +++ b/src/content/actions/operation.js @@ -4,9 +4,16 @@ import * as scrolls from 'content/scrolls'; import * as navigates from 'content/navigates'; import * as urls from 'content/urls'; import * as consoleFrames from 'content/console-frames'; +import * as addonActions from './addon'; const exec = (operation) => { switch (operation.type) { + case operations.ADDON_ENABLE: + return addonActions.enable(); + case operations.ADDON_DISABLE: + return addonActions.disable(); + case operations.ADDON_TOGGLE_ENABLED: + return addonActions.toggleEnabled(); case operations.SCROLL_VERTICALLY: return scrolls.scrollVertically(window, operation.count); case operations.SCROLL_HORIZONALLY: diff --git a/src/content/components/common/keymapper.js b/src/content/components/common/keymapper.js index 8c0ddb1..5070cd8 100644 --- a/src/content/components/common/keymapper.js +++ b/src/content/components/common/keymapper.js @@ -1,5 +1,6 @@ import * as inputActions from 'content/actions/input'; import * as operationActions from 'content/actions/operation'; +import operations from 'shared/operations'; export default class KeymapperComponent { constructor(store) { @@ -10,12 +11,23 @@ export default class KeymapperComponent { } key(key) { + let enabled = this.store.getState().addon.enabled; + this.store.dispatch(inputActions.keyPress(key)); let input = this.store.getState().input; let matched = Object.keys(input.keymaps).filter((keyStr) => { return keyStr.startsWith(input.keys); }); + if (!enabled) { + // available keymaps are only ADDON_ENABLE and ADDON_TOGGLE_ENABLED if + // the addon disabled + matched = matched.filter((keys) => { + let type = input.keymaps[keys].type; + return type === operations.ADDON_ENABLE || + type === operations.ADDON_TOGGLE_ENABLED; + }); + } if (matched.length === 0) { this.store.dispatch(inputActions.clearKeys()); return false; diff --git a/src/content/reducers/index.js b/src/content/reducers/index.js index c026a19..7cf318e 100644 --- a/src/content/reducers/index.js +++ b/src/content/reducers/index.js @@ -1,14 +1,17 @@ +import addonReducer from './addon'; import inputReducer from './input'; import followReducer from './follow'; // Make setting reducer instead of re-use const defaultState = { + addon: addonReducer(undefined, {}), input: inputReducer(undefined, {}), follow: followReducer(undefined, {}), }; export default function reducer(state = defaultState, action = {}) { return Object.assign({}, state, { + addon: addonReducer(state.addon, action), input: inputReducer(state.input, action), follow: followReducer(state.follow, action), }); diff --git a/src/shared/operations.js b/src/shared/operations.js index 0d2a381..d5c2985 100644 --- a/src/shared/operations.js +++ b/src/shared/operations.js @@ -1,4 +1,9 @@ export default { + // Addons + ADDON_ENABLE: 'addon.enable', + ADDON_DISABLE: 'addon.disable', + ADDON_TOGGLE_ENABLED: 'addon.toggle.enabled', + // Command COMMAND_SHOW: 'command.show', COMMAND_SHOW_OPEN: 'command.show.open', -- cgit v1.2.3