aboutsummaryrefslogtreecommitdiff
path: root/src/content/components/common/index.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-05-11 08:04:01 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2019-05-11 08:04:01 +0900
commitbacf83a32083c5a4c4a45c061288081423bbf18a (patch)
treef5a73e2b989428ca3f3466b6e4a4cc744e24f4b7 /src/content/components/common/index.ts
parente76ca380f733b515c31297a285d8bea44e074a1b (diff)
Make settings as a clean architecture
Diffstat (limited to 'src/content/components/common/index.ts')
-rw-r--r--src/content/components/common/index.ts36
1 files changed, 14 insertions, 22 deletions
diff --git a/src/content/components/common/index.ts b/src/content/components/common/index.ts
index be77812..899953d 100644
--- a/src/content/components/common/index.ts
+++ b/src/content/components/common/index.ts
@@ -2,22 +2,18 @@ import InputComponent from './input';
import FollowComponent from './follow';
import MarkComponent from './mark';
import KeymapperComponent from './keymapper';
-import * as settingActions from '../../actions/setting';
import * as messages from '../../../shared/messages';
import MessageListener from '../../MessageListener';
import * as blacklists from '../../../shared/blacklists';
import * as keys from '../../../shared/utils/keys';
-import * as actions from '../../actions';
import AddonEnabledUseCase from '../../usecases/AddonEnabledUseCase';
+import SettingUseCase from '../../usecases/SettingUseCase';
let addonEnabledUseCase = new AddonEnabledUseCase();
+let settingUseCase = new SettingUseCase();
export default class Common {
- private win: Window;
-
- private store: any;
-
constructor(win: Window, store: any) {
const input = new InputComponent(win.document.body);
const follow = new FollowComponent(win);
@@ -28,9 +24,6 @@ export default class Common {
input.onKey((key: keys.Key) => mark.key(key));
input.onKey((key: keys.Key) => keymapper.key(key));
- this.win = win;
- this.store = store;
-
this.reloadSettings();
new MessageListener().onBackgroundMessage(this.onMessage.bind(this));
@@ -41,23 +34,22 @@ export default class Common {
case messages.SETTINGS_CHANGED:
return this.reloadSettings();
case messages.ADDON_TOGGLE_ENABLED:
- addonEnabledUseCase.toggle();
+ return addonEnabledUseCase.toggle();
}
+ return undefined;
}
- reloadSettings() {
+ async reloadSettings() {
try {
- this.store.dispatch(settingActions.load())
- .then((action: actions.SettingAction) => {
- let enabled = !blacklists.includes(
- action.settings.blacklist, this.win.location.href
- );
- if (enabled) {
- addonEnabledUseCase.enable();
- } else {
- addonEnabledUseCase.disable();
- }
- });
+ let current = await settingUseCase.reload();
+ let disabled = blacklists.includes(
+ current.blacklist, window.location.href,
+ );
+ if (disabled) {
+ addonEnabledUseCase.disable();
+ } else {
+ addonEnabledUseCase.enable();
+ }
} catch (e) {
// Sometime sendMessage fails when background script is not ready.
console.warn(e);