aboutsummaryrefslogtreecommitdiff
path: root/src/content/components
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/components
parent05ef6a8ca35aaa801c11eb6b4896caa3690058af (diff)
Make addon-enabled as a clean architecture
Diffstat (limited to 'src/content/components')
-rw-r--r--src/content/components/common/index.ts14
-rw-r--r--src/content/components/common/keymapper.ts8
-rw-r--r--src/content/components/top-content/index.ts13
3 files changed, 21 insertions, 14 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.
diff --git a/src/content/components/common/keymapper.ts b/src/content/components/common/keymapper.ts
index c94bae0..02579ec 100644
--- a/src/content/components/common/keymapper.ts
+++ b/src/content/components/common/keymapper.ts
@@ -3,6 +3,10 @@ import * as operationActions from '../../actions/operation';
import * as operations from '../../../shared/operations';
import * as keyUtils from '../../../shared/utils/keys';
+import AddonEnabledUseCase from '../../usecases/AddonEnabledUseCase';
+
+let addonEnabledUseCase = new AddonEnabledUseCase();
+
const mapStartsWith = (
mapping: keyUtils.Key[],
keys: keyUtils.Key[],
@@ -41,7 +45,7 @@ export default class KeymapperComponent {
(mapping: keyUtils.Key[]) => {
return mapStartsWith(mapping, input.keys);
});
- if (!state.addon.enabled) {
+ if (!addonEnabledUseCase.getEnabled()) {
// available keymaps are only ADDON_ENABLE and ADDON_TOGGLE_ENABLED if
// the addon disabled
matched = matched.filter((keys) => {
@@ -59,7 +63,7 @@ export default class KeymapperComponent {
}
let operation = keymaps.get(matched[0]) as operations.Operation;
let act = operationActions.exec(
- operation, state.setting, state.addon.enabled
+ operation, state.setting,
);
this.store.dispatch(act);
this.store.dispatch(inputActions.clearKeys());
diff --git a/src/content/components/top-content/index.ts b/src/content/components/top-content/index.ts
index ac95ea9..101edca 100644
--- a/src/content/components/top-content/index.ts
+++ b/src/content/components/top-content/index.ts
@@ -5,15 +5,15 @@ import * as consoleFrames from '../../console-frames';
import * as messages from '../../../shared/messages';
import MessageListener from '../../MessageListener';
import * as scrolls from '../../scrolls';
+import AddonEnabledUseCase from '../../usecases/AddonEnabledUseCase';
+
+let addonEnabledUseCase = new AddonEnabledUseCase();
export default class TopContent {
private win: Window;
- private store: any;
-
constructor(win: Window, store: any) {
this.win = win;
- this.store = store;
new CommonComponent(win, store); // eslint-disable-line no-new
new FollowController(win, store); // eslint-disable-line no-new
@@ -36,14 +36,11 @@ export default class TopContent {
}
onBackgroundMessage(message: messages.Message) {
- let addonState = this.store.getState().addon;
+ let addonEnabled = addonEnabledUseCase.getEnabled();
switch (message.type) {
case messages.ADDON_ENABLED_QUERY:
- return Promise.resolve({
- type: messages.ADDON_ENABLED_RESPONSE,
- enabled: addonState.enabled,
- });
+ return Promise.resolve(addonEnabled);
case messages.TAB_SCROLL_TO:
return scrolls.scrollTo(message.x, message.y, false);
}