Types on src/background

This commit is contained in:
Shin'ya Ueoka 2019-05-01 11:04:24 +09:00
parent 0cffb09e24
commit 678020a3a2
48 changed files with 446 additions and 431 deletions

View file

@ -3,10 +3,20 @@ import TabPresenter from '../presenters/TabPresenter';
import ContentMessageClient from '../infrastructures/ContentMessageClient';
export default class AddonEnabledUseCase {
private indicatorPresentor: IndicatorPresenter;
private tabPresenter: TabPresenter;
private contentMessageClient: ContentMessageClient;
constructor() {
this.indicatorPresentor = new IndicatorPresenter();
this.indicatorPresentor.onClick(tab => this.onIndicatorClick(tab.id));
this.indicatorPresentor.onClick((tab) => {
if (tab.id) {
this.onIndicatorClick(tab.id);
}
});
this.tabPresenter = new TabPresenter();
this.tabPresenter.onSelected(info => this.onTabSelected(info.tabId));
@ -14,15 +24,15 @@ export default class AddonEnabledUseCase {
this.contentMessageClient = new ContentMessageClient();
}
indicate(enabled) {
indicate(enabled: boolean): Promise<void> {
return this.indicatorPresentor.indicate(enabled);
}
onIndicatorClick(tabId) {
onIndicatorClick(tabId: number): Promise<void> {
return this.contentMessageClient.toggleAddonEnabled(tabId);
}
async onTabSelected(tabId) {
async onTabSelected(tabId: number): Promise<void> {
let enabled = await this.contentMessageClient.getAddonEnabled(tabId);
return this.indicatorPresentor.indicate(enabled);
}