This repository has been archived on 2020-04-04. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Vim-Vixen/src/content/usecases/AddonEnabledUseCase.ts
2019-05-10 23:00:59 +09:00

40 lines
1,004 B
TypeScript

import AddonIndicatorClient, { AddonIndicatorClientImpl }
from '../client/AddonIndicatorClient';
import AddonEnabledRepository, { AddonEnabledRepositoryImpl }
from '../repositories/AddonEnabledRepository';
export default class AddonEnabledUseCase {
private indicator: AddonIndicatorClient;
private repository: AddonEnabledRepository;
constructor({
indicator = new AddonIndicatorClientImpl(),
repository = new AddonEnabledRepositoryImpl(),
} = {}) {
this.indicator = indicator;
this.repository = repository;
}
async enable(): Promise<void> {
await this.setEnabled(true);
}
async disable(): Promise<void> {
await this.setEnabled(false);
}
async toggle(): Promise<void> {
let current = this.repository.get();
await this.setEnabled(!current);
}
getEnabled(): boolean {
return this.repository.get();
}
private async setEnabled(on: boolean): Promise<void> {
this.repository.set(on);
await this.indicator.setEnabled(on);
}
}