aboutsummaryrefslogtreecommitdiff
path: root/src/content/actions
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-05-10 22:27:20 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2019-05-10 23:00:59 +0900
commite76ca380f733b515c31297a285d8bea44e074a1b (patch)
treeb476d9ca41a8bbbcbbad3b3ee13882da9d640d25 /src/content/actions
parent05ef6a8ca35aaa801c11eb6b4896caa3690058af (diff)
Make addon-enabled as a clean architecture
Diffstat (limited to 'src/content/actions')
-rw-r--r--src/content/actions/addon.ts19
-rw-r--r--src/content/actions/index.ts10
-rw-r--r--src/content/actions/operation.ts19
3 files changed, 12 insertions, 36 deletions
diff --git a/src/content/actions/addon.ts b/src/content/actions/addon.ts
deleted file mode 100644
index 8dedae0..0000000
--- a/src/content/actions/addon.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import * as messages from '../../shared/messages';
-import * as actions from './index';
-
-const enable = (): Promise<actions.AddonAction> => setEnabled(true);
-
-const disable = (): Promise<actions.AddonAction> => setEnabled(false);
-
-const setEnabled = async(enabled: boolean): Promise<actions.AddonAction> => {
- await browser.runtime.sendMessage({
- type: messages.ADDON_ENABLED_RESPONSE,
- enabled,
- });
- return {
- type: actions.ADDON_SET_ENABLED,
- enabled,
- };
-};
-
-export { enable, disable, setEnabled };
diff --git a/src/content/actions/index.ts b/src/content/actions/index.ts
index 8aa9c23..74353fb 100644
--- a/src/content/actions/index.ts
+++ b/src/content/actions/index.ts
@@ -2,9 +2,6 @@ import Redux from 'redux';
import Settings from '../../shared/Settings';
import * as keyUtils from '../../shared/utils/keys';
-// Enable/disable
-export const ADDON_SET_ENABLED = 'addon.set.enabled';
-
// Find
export const FIND_SET_KEYWORD = 'find.set.keyword';
@@ -34,11 +31,6 @@ export const MARK_SET_LOCAL = 'mark.set.local';
export const NOOP = 'noop';
-export interface AddonSetEnabledAction extends Redux.Action {
- type: typeof ADDON_SET_ENABLED;
- enabled: boolean;
-}
-
export interface FindSetKeywordAction extends Redux.Action {
type: typeof FIND_SET_KEYWORD;
keyword: string;
@@ -101,7 +93,6 @@ export interface NoopAction extends Redux.Action {
type: typeof NOOP;
}
-export type AddonAction = AddonSetEnabledAction;
export type FindAction = FindSetKeywordAction | NoopAction;
export type SettingAction = SettingSetAction;
export type InputAction = InputKeyPressAction | InputClearKeysAction;
@@ -113,7 +104,6 @@ export type MarkAction =
MarkCancelAction | MarkSetLocalAction | NoopAction;
export type Action =
- AddonAction |
FindAction |
SettingAction |
InputAction |
diff --git a/src/content/actions/operation.ts b/src/content/actions/operation.ts
index 41e080b..949f69f 100644
--- a/src/content/actions/operation.ts
+++ b/src/content/actions/operation.ts
@@ -6,23 +6,28 @@ import * as navigates from '../navigates';
import * as focuses from '../focuses';
import * as urls from '../urls';
import * as consoleFrames from '../console-frames';
-import * as addonActions from './addon';
import * as markActions from './mark';
+import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase';
+
+let addonEnabledUseCase = new AddonEnabledUseCase();
+
// eslint-disable-next-line complexity, max-lines-per-function
-const exec = (
+const exec = async(
operation: operations.Operation,
settings: any,
- addonEnabled: boolean,
-): Promise<actions.Action> | actions.Action => {
+): Promise<actions.Action> => {
let smoothscroll = settings.properties.smoothscroll;
switch (operation.type) {
case operations.ADDON_ENABLE:
- return addonActions.enable();
+ await addonEnabledUseCase.enable();
+ return { type: actions.NOOP };
case operations.ADDON_DISABLE:
- return addonActions.disable();
+ await addonEnabledUseCase.disable();
+ return { type: actions.NOOP };
case operations.ADDON_TOGGLE_ENABLED:
- return addonActions.setEnabled(!addonEnabled);
+ await addonEnabledUseCase.toggle();
+ return { type: actions.NOOP };
case operations.FIND_NEXT:
window.top.postMessage(JSON.stringify({
type: messages.FIND_NEXT,