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/components/common/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/content/components/common/index.ts') diff --git a/src/content/components/common/index.ts b/src/content/components/common/index.ts index 5b097b6..be77812 100644 --- a/src/content/components/common/index.ts +++ b/src/content/components/common/index.ts @@ -5,11 +5,14 @@ import KeymapperComponent from './keymapper'; import * as settingActions from '../../actions/setting'; import * as messages from '../../../shared/messages'; 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'; +import AddonEnabledUseCase from '../../usecases/AddonEnabledUseCase'; + +let addonEnabledUseCase = new AddonEnabledUseCase(); + export default class Common { private win: Window; @@ -34,12 +37,11 @@ export default class Common { } onMessage(message: messages.Message) { - let { enabled } = this.store.getState().addon; switch (message.type) { case messages.SETTINGS_CHANGED: return this.reloadSettings(); case messages.ADDON_TOGGLE_ENABLED: - this.store.dispatch(addonActions.setEnabled(!enabled)); + addonEnabledUseCase.toggle(); } } @@ -50,7 +52,11 @@ export default class Common { let enabled = !blacklists.includes( action.settings.blacklist, this.win.location.href ); - this.store.dispatch(addonActions.setEnabled(enabled)); + if (enabled) { + addonEnabledUseCase.enable(); + } else { + addonEnabledUseCase.disable(); + } }); } catch (e) { // Sometime sendMessage fails when background script is not ready. -- cgit v1.2.3