diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-05-22 20:16:21 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-22 20:16:21 +0900 |
commit | c1f64927b63d18048790abd3ba907083dbca3084 (patch) | |
tree | 3a64b677763f62094c49527d8182f8756a52fbd1 /src/background/usecases | |
parent | ced89134e32d793d8e091113cfb20867e1c3b572 (diff) | |
parent | 7be8bc71784b8dedd0fee03dd72dd8936e2f3929 (diff) |
Merge pull request #588 from ueokande/tsyringe
Use tsyringe for DI container
Diffstat (limited to 'src/background/usecases')
-rw-r--r-- | src/background/usecases/AddonEnabledUseCase.ts | 20 | ||||
-rw-r--r-- | src/background/usecases/CommandUseCase.ts | 30 | ||||
-rw-r--r-- | src/background/usecases/CompletionsUseCase.ts | 17 | ||||
-rw-r--r-- | src/background/usecases/ConsoleUseCase.ts | 12 | ||||
-rw-r--r-- | src/background/usecases/FindUseCase.ts | 17 | ||||
-rw-r--r-- | src/background/usecases/LinkUseCase.ts | 9 | ||||
-rw-r--r-- | src/background/usecases/MarkUseCase.ts | 21 | ||||
-rw-r--r-- | src/background/usecases/SettingUseCase.ts | 16 | ||||
-rw-r--r-- | src/background/usecases/TabSelectUseCase.ts | 9 | ||||
-rw-r--r-- | src/background/usecases/TabUseCase.ts | 13 | ||||
-rw-r--r-- | src/background/usecases/VersionUseCase.ts | 13 | ||||
-rw-r--r-- | src/background/usecases/ZoomUseCase.ts | 9 |
12 files changed, 80 insertions, 106 deletions
diff --git a/src/background/usecases/AddonEnabledUseCase.ts b/src/background/usecases/AddonEnabledUseCase.ts index 0a6fb03..bb5cd90 100644 --- a/src/background/usecases/AddonEnabledUseCase.ts +++ b/src/background/usecases/AddonEnabledUseCase.ts @@ -1,27 +1,21 @@ +import { injectable } from 'tsyringe'; import IndicatorPresenter from '../presenters/IndicatorPresenter'; import TabPresenter from '../presenters/TabPresenter'; import ContentMessageClient from '../infrastructures/ContentMessageClient'; +@injectable() export default class AddonEnabledUseCase { - private indicatorPresentor: IndicatorPresenter; - - private tabPresenter: TabPresenter; - - private contentMessageClient: ContentMessageClient; - - constructor() { - this.indicatorPresentor = new IndicatorPresenter(); - + constructor( + private indicatorPresentor: IndicatorPresenter, + private tabPresenter: TabPresenter, + private contentMessageClient: ContentMessageClient, + ) { this.indicatorPresentor.onClick((tab) => { if (tab.id) { this.onIndicatorClick(tab.id); } }); - - this.tabPresenter = new TabPresenter(); this.tabPresenter.onSelected(info => this.onTabSelected(info.tabId)); - - this.contentMessageClient = new ContentMessageClient(); } indicate(enabled: boolean): Promise<void> { diff --git a/src/background/usecases/CommandUseCase.ts b/src/background/usecases/CommandUseCase.ts index 2247d7b..921a779 100644 --- a/src/background/usecases/CommandUseCase.ts +++ b/src/background/usecases/CommandUseCase.ts @@ -1,3 +1,4 @@ +import { injectable } from 'tsyringe'; import * as parsers from './parsers'; import * as urls from '../../shared/urls'; import TabPresenter from '../presenters/TabPresenter'; @@ -7,27 +8,16 @@ import BookmarkRepository from '../repositories/BookmarkRepository'; import ConsoleClient from '../infrastructures/ConsoleClient'; import ContentMessageClient from '../infrastructures/ContentMessageClient'; +@injectable() export default class CommandIndicator { - private tabPresenter: TabPresenter; - - private windowPresenter: WindowPresenter; - - private settingRepository: SettingRepository; - - private bookmarkRepository: BookmarkRepository; - - private consoleClient: ConsoleClient; - - private contentMessageClient: ContentMessageClient; - - constructor() { - this.tabPresenter = new TabPresenter(); - this.windowPresenter = new WindowPresenter(); - this.settingRepository = new SettingRepository(); - this.bookmarkRepository = new BookmarkRepository(); - this.consoleClient = new ConsoleClient(); - - this.contentMessageClient = new ContentMessageClient(); + constructor( + private tabPresenter: TabPresenter, + private windowPresenter: WindowPresenter, + private settingRepository: SettingRepository, + private bookmarkRepository: BookmarkRepository, + private consoleClient: ConsoleClient, + private contentMessageClient: ContentMessageClient, + ) { } async open(keywords: string): Promise<browser.tabs.Tab> { diff --git a/src/background/usecases/CompletionsUseCase.ts b/src/background/usecases/CompletionsUseCase.ts index da36e3c..705555b 100644 --- a/src/background/usecases/CompletionsUseCase.ts +++ b/src/background/usecases/CompletionsUseCase.ts @@ -1,3 +1,4 @@ +import { injectable } from 'tsyringe'; import CompletionGroup from '../domains/CompletionGroup'; import CommandDocs from '../domains/CommandDocs'; import CompletionsRepository from '../repositories/CompletionsRepository'; @@ -11,17 +12,13 @@ const COMPLETION_ITEM_LIMIT = 10; type Tab = browser.tabs.Tab; type HistoryItem = browser.history.HistoryItem; +@injectable() export default class CompletionsUseCase { - private tabPresenter: TabPresenter; - - private completionsRepository: CompletionsRepository; - - private settingRepository: SettingRepository; - - constructor() { - this.tabPresenter = new TabPresenter(); - this.completionsRepository = new CompletionsRepository(); - this.settingRepository = new SettingRepository(); + constructor( + private tabPresenter: TabPresenter, + private completionsRepository: CompletionsRepository, + private settingRepository: SettingRepository, + ) { } queryConsoleCommand(prefix: string): Promise<CompletionGroup[]> { diff --git a/src/background/usecases/ConsoleUseCase.ts b/src/background/usecases/ConsoleUseCase.ts index 60c0439..d0bd7bb 100644 --- a/src/background/usecases/ConsoleUseCase.ts +++ b/src/background/usecases/ConsoleUseCase.ts @@ -1,14 +1,14 @@ +import { injectable } from 'tsyringe'; import TabPresenter from '../presenters/TabPresenter'; import ConsoleClient from '../infrastructures/ConsoleClient'; +@injectable() export default class ConsoleUseCase { - private tabPresenter: TabPresenter; - private consoleClient: ConsoleClient; - - constructor() { - this.tabPresenter = new TabPresenter(); - this.consoleClient = new ConsoleClient(); + constructor( + private tabPresenter: TabPresenter, + private consoleClient: ConsoleClient, + ) { } async showCommand(): Promise<any> { diff --git a/src/background/usecases/FindUseCase.ts b/src/background/usecases/FindUseCase.ts index d567800..41b9cbd 100644 --- a/src/background/usecases/FindUseCase.ts +++ b/src/background/usecases/FindUseCase.ts @@ -1,18 +1,15 @@ +import { injectable } from 'tsyringe'; import FindRepository from '../repositories/FindRepository'; import TabPresenter from '../presenters/TabPresenter'; import ConsoleClient from '../infrastructures/ConsoleClient'; +@injectable() export default class FindUseCase { - private tabPresenter: TabPresenter; - - private findRepository: FindRepository; - - private consoleClient: ConsoleClient; - - constructor() { - this.tabPresenter = new TabPresenter(); - this.findRepository = new FindRepository(); - this.consoleClient = new ConsoleClient(); + constructor( + private tabPresenter: TabPresenter, + private findRepository: FindRepository, + private consoleClient: ConsoleClient, + ) { } getKeyword(): Promise<string> { diff --git a/src/background/usecases/LinkUseCase.ts b/src/background/usecases/LinkUseCase.ts index 480f6b5..e87867d 100644 --- a/src/background/usecases/LinkUseCase.ts +++ b/src/background/usecases/LinkUseCase.ts @@ -1,10 +1,11 @@ +import { injectable } from 'tsyringe'; import TabPresenter from '../presenters/TabPresenter'; +@injectable() export default class LinkUseCase { - private tabPresenter: TabPresenter; - - constructor() { - this.tabPresenter = new TabPresenter(); + constructor( + private tabPresenter: TabPresenter, + ) { } openToTab(url: string, tabId: number): Promise<any> { diff --git a/src/background/usecases/MarkUseCase.ts b/src/background/usecases/MarkUseCase.ts index e376c55..8cb96da 100644 --- a/src/background/usecases/MarkUseCase.ts +++ b/src/background/usecases/MarkUseCase.ts @@ -1,22 +1,17 @@ +import { injectable } from 'tsyringe'; import TabPresenter from '../presenters/TabPresenter'; import MarkRepository from '../repositories/MarkRepository'; import ConsoleClient from '../infrastructures/ConsoleClient'; import ContentMessageClient from '../infrastructures/ContentMessageClient'; +@injectable() export default class MarkUseCase { - private tabPresenter: TabPresenter; - - private markRepository: MarkRepository; - - private consoleClient: ConsoleClient; - - private contentMessageClient: ContentMessageClient; - - constructor() { - this.tabPresenter = new TabPresenter(); - this.markRepository = new MarkRepository(); - this.consoleClient = new ConsoleClient(); - this.contentMessageClient = new ContentMessageClient(); + constructor( + private tabPresenter: TabPresenter, + private markRepository: MarkRepository, + private consoleClient: ConsoleClient, + private contentMessageClient: ContentMessageClient, + ) { } async setGlobal(key: string, x: number, y: number): Promise<any> { diff --git a/src/background/usecases/SettingUseCase.ts b/src/background/usecases/SettingUseCase.ts index aa3b534..fd00f80 100644 --- a/src/background/usecases/SettingUseCase.ts +++ b/src/background/usecases/SettingUseCase.ts @@ -1,17 +1,17 @@ -// eslint-disable-next-line max-len -import PersistentSettingRepository from '../repositories/PersistentSettingRepository'; +import { injectable } from 'tsyringe'; +import PersistentSettingRepository + from '../repositories/PersistentSettingRepository'; import SettingRepository from '../repositories/SettingRepository'; import { DefaultSettingData } from '../../shared/SettingData'; import Settings from '../../shared/Settings'; +@injectable() export default class SettingUseCase { - private persistentSettingRepository: PersistentSettingRepository; - private settingRepository: SettingRepository; - - constructor() { - this.persistentSettingRepository = new PersistentSettingRepository(); - this.settingRepository = new SettingRepository(); + constructor( + private persistentSettingRepository: PersistentSettingRepository, + private settingRepository: SettingRepository, + ) { } get(): Promise<Settings> { diff --git a/src/background/usecases/TabSelectUseCase.ts b/src/background/usecases/TabSelectUseCase.ts index a0b52f0..df3db94 100644 --- a/src/background/usecases/TabSelectUseCase.ts +++ b/src/background/usecases/TabSelectUseCase.ts @@ -1,10 +1,11 @@ +import { injectable } from 'tsyringe'; import TabPresenter from '../presenters/TabPresenter'; +@injectable() export default class TabSelectUseCase { - private tabPresenter: TabPresenter; - - constructor() { - this.tabPresenter = new TabPresenter(); + constructor( + private tabPresenter: TabPresenter, + ) { } async selectPrev(count: number): Promise<any> { diff --git a/src/background/usecases/TabUseCase.ts b/src/background/usecases/TabUseCase.ts index 1615333..0239a87 100644 --- a/src/background/usecases/TabUseCase.ts +++ b/src/background/usecases/TabUseCase.ts @@ -1,14 +1,13 @@ +import { injectable } from 'tsyringe'; import TabPresenter from '../presenters/TabPresenter'; import BrowserSettingRepository from '../repositories/BrowserSettingRepository'; +@injectable() export default class TabUseCase { - private tabPresenter: TabPresenter; - - private browserSettingRepository: BrowserSettingRepository; - - constructor() { - this.tabPresenter = new TabPresenter(); - this.browserSettingRepository = new BrowserSettingRepository(); + constructor( + private tabPresenter: TabPresenter, + private browserSettingRepository: BrowserSettingRepository, + ) { } async close(force: boolean): Promise<any> { diff --git a/src/background/usecases/VersionUseCase.ts b/src/background/usecases/VersionUseCase.ts index 8154eba..1d9ef8b 100644 --- a/src/background/usecases/VersionUseCase.ts +++ b/src/background/usecases/VersionUseCase.ts @@ -1,14 +1,13 @@ +import { injectable } from 'tsyringe'; import TabPresenter from '../presenters/TabPresenter'; import NotifyPresenter from '../presenters/NotifyPresenter'; +@injectable() export default class VersionUseCase { - private tabPresenter: TabPresenter; - - private notifyPresenter: NotifyPresenter; - - constructor() { - this.tabPresenter = new TabPresenter(); - this.notifyPresenter = new NotifyPresenter(); + constructor( + private tabPresenter: TabPresenter, + private notifyPresenter: NotifyPresenter, + ) { } notify(): Promise<void> { diff --git a/src/background/usecases/ZoomUseCase.ts b/src/background/usecases/ZoomUseCase.ts index 661c3cd..32ba897 100644 --- a/src/background/usecases/ZoomUseCase.ts +++ b/src/background/usecases/ZoomUseCase.ts @@ -1,3 +1,4 @@ +import { injectable } from 'tsyringe'; import TabPresenter from '../presenters/TabPresenter'; const ZOOM_SETTINGS: number[] = [ @@ -5,11 +6,11 @@ const ZOOM_SETTINGS: number[] = [ 1.10, 1.25, 1.50, 1.75, 2.00, 2.50, 3.00 ]; +@injectable() export default class ZoomUseCase { - private tabPresenter: TabPresenter; - - constructor() { - this.tabPresenter = new TabPresenter(); + constructor( + private tabPresenter: TabPresenter, + ) { } async zoomIn(): Promise<any> { |