From 42d902982a1d2edbca8ca2edb5fb25e642794e2a Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 22 Jul 2018 15:39:23 +0900 Subject: Indicator as Clean Architecture --- src/background/usecases/addon-enabled.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/background/usecases/addon-enabled.js (limited to 'src/background/usecases/addon-enabled.js') diff --git a/src/background/usecases/addon-enabled.js b/src/background/usecases/addon-enabled.js new file mode 100644 index 0000000..37eb1c2 --- /dev/null +++ b/src/background/usecases/addon-enabled.js @@ -0,0 +1,29 @@ +import IndicatorPresenter from '../presenters/indicator'; +import TabPresenter from '../presenters/tab'; +import ContentMessageClient from '../infrastructures/content-message-client'; + +export default class AddonEnabledInteractor { + constructor() { + this.indicatorPresentor = new IndicatorPresenter(); + + this.indicatorPresentor.onClick(tab => this.onIndicatorClick(tab.id)); + + this.tabPresenter = new TabPresenter(); + this.tabPresenter.onSelected(info => this.onTabSelected(info.tabId)); + + this.contentMessageClient = new ContentMessageClient(); + } + + indicate(enabled) { + this.indicatorPresentor.indicate(enabled); + } + + onIndicatorClick(tabId) { + return this.contentMessageClient.toggleAddonEnabled(tabId); + } + + async onTabSelected(tabId) { + let enabled = await this.contentMessageClient.getAddonEnabled(tabId); + return this.indicatorPresentor.indicate(enabled); + } +} -- cgit v1.2.3 From 6f4e327b6f91aa687b373463d8bc284ffaceba53 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 28 Jul 2018 19:09:49 +0900 Subject: Fix indicate return values --- src/background/controllers/addon-enabled.js | 2 +- src/background/usecases/addon-enabled.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/background/usecases/addon-enabled.js') diff --git a/src/background/controllers/addon-enabled.js b/src/background/controllers/addon-enabled.js index 0f5d801..6a9b776 100644 --- a/src/background/controllers/addon-enabled.js +++ b/src/background/controllers/addon-enabled.js @@ -6,6 +6,6 @@ export default class AddonEnabledController { } indicate(enabled) { - this.addonEnabledInteractor.indicate(enabled); + return this.addonEnabledInteractor.indicate(enabled); } } diff --git a/src/background/usecases/addon-enabled.js b/src/background/usecases/addon-enabled.js index 37eb1c2..d83192f 100644 --- a/src/background/usecases/addon-enabled.js +++ b/src/background/usecases/addon-enabled.js @@ -15,7 +15,7 @@ export default class AddonEnabledInteractor { } indicate(enabled) { - this.indicatorPresentor.indicate(enabled); + return this.indicatorPresentor.indicate(enabled); } onIndicatorClick(tabId) { -- cgit v1.2.3