diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-10 22:27:20 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-10 23:00:59 +0900 |
commit | e76ca380f733b515c31297a285d8bea44e074a1b (patch) | |
tree | b476d9ca41a8bbbcbbad3b3ee13882da9d640d25 /src/content/components/common/index.ts | |
parent | 05ef6a8ca35aaa801c11eb6b4896caa3690058af (diff) |
Make addon-enabled as a clean architecture
Diffstat (limited to 'src/content/components/common/index.ts')
-rw-r--r-- | src/content/components/common/index.ts | 14 |
1 files changed, 10 insertions, 4 deletions
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. |