From e76ca380f733b515c31297a285d8bea44e074a1b Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 10 May 2019 22:27:20 +0900 Subject: Make addon-enabled as a clean architecture --- src/content/actions/addon.ts | 19 ------------------- src/content/actions/index.ts | 10 ---------- src/content/actions/operation.ts | 19 ++++++++++++------- 3 files changed, 12 insertions(+), 36 deletions(-) delete mode 100644 src/content/actions/addon.ts (limited to 'src/content/actions') 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 => setEnabled(true); - -const disable = (): Promise => setEnabled(false); - -const setEnabled = async(enabled: boolean): Promise => { - 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 => { +): Promise => { 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, -- cgit v1.2.3