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/controllers | |
parent | ced89134e32d793d8e091113cfb20867e1c3b572 (diff) | |
parent | 7be8bc71784b8dedd0fee03dd72dd8936e2f3929 (diff) |
Merge pull request #588 from ueokande/tsyringe
Use tsyringe for DI container
Diffstat (limited to 'src/background/controllers')
-rw-r--r-- | src/background/controllers/AddonEnabledController.ts | 8 | ||||
-rw-r--r-- | src/background/controllers/CommandController.ts | 13 | ||||
-rw-r--r-- | src/background/controllers/FindController.ts | 9 | ||||
-rw-r--r-- | src/background/controllers/LinkController.ts | 9 | ||||
-rw-r--r-- | src/background/controllers/MarkController.ts | 9 | ||||
-rw-r--r-- | src/background/controllers/OperationController.ts | 25 | ||||
-rw-r--r-- | src/background/controllers/SettingController.ts | 13 | ||||
-rw-r--r-- | src/background/controllers/VersionController.ts | 9 |
8 files changed, 46 insertions, 49 deletions
diff --git a/src/background/controllers/AddonEnabledController.ts b/src/background/controllers/AddonEnabledController.ts index 251af25..903df40 100644 --- a/src/background/controllers/AddonEnabledController.ts +++ b/src/background/controllers/AddonEnabledController.ts @@ -1,10 +1,12 @@ +import { injectable } from 'tsyringe'; import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase'; +@injectable() export default class AddonEnabledController { - private addonEnabledUseCase: AddonEnabledUseCase; - constructor() { - this.addonEnabledUseCase = new AddonEnabledUseCase(); + constructor( + private addonEnabledUseCase: AddonEnabledUseCase, + ) { } indicate(enabled: boolean): Promise<any> { diff --git a/src/background/controllers/CommandController.ts b/src/background/controllers/CommandController.ts index f3a6b7f..2ad1683 100644 --- a/src/background/controllers/CommandController.ts +++ b/src/background/controllers/CommandController.ts @@ -1,3 +1,4 @@ +import { injectable } from 'tsyringe'; import CompletionsUseCase from '../usecases/CompletionsUseCase'; import CommandUseCase from '../usecases/CommandUseCase'; import CompletionGroup from '../domains/CompletionGroup'; @@ -7,14 +8,12 @@ const trimStart = (str: string): string => { return str.replace(/^\s+/, ''); }; +@injectable() export default class CommandController { - private completionsUseCase: CompletionsUseCase; - - private commandIndicator: CommandUseCase; - - constructor() { - this.completionsUseCase = new CompletionsUseCase(); - this.commandIndicator = new CommandUseCase(); + constructor( + private completionsUseCase: CompletionsUseCase, + private commandIndicator: CommandUseCase, + ) { } getCompletions(line: string): Promise<CompletionGroup[]> { diff --git a/src/background/controllers/FindController.ts b/src/background/controllers/FindController.ts index 28959e2..1cec962 100644 --- a/src/background/controllers/FindController.ts +++ b/src/background/controllers/FindController.ts @@ -1,10 +1,11 @@ +import { injectable } from 'tsyringe'; import FindUseCase from '../usecases/FindUseCase'; +@injectable() export default class FindController { - private findUseCase: FindUseCase; - - constructor() { - this.findUseCase = new FindUseCase(); + constructor( + private findUseCase: FindUseCase, + ) { } getKeyword(): Promise<string> { diff --git a/src/background/controllers/LinkController.ts b/src/background/controllers/LinkController.ts index 707b28a..af6148e 100644 --- a/src/background/controllers/LinkController.ts +++ b/src/background/controllers/LinkController.ts @@ -1,10 +1,11 @@ +import { injectable } from 'tsyringe'; import LinkUseCase from '../usecases/LinkUseCase'; +@injectable() export default class LinkController { - private linkUseCase: LinkUseCase; - - constructor() { - this.linkUseCase = new LinkUseCase(); + constructor( + private linkUseCase: LinkUseCase, + ) { } openToTab(url: string, tabId: number): Promise<void> { diff --git a/src/background/controllers/MarkController.ts b/src/background/controllers/MarkController.ts index 419a08b..4726fbc 100644 --- a/src/background/controllers/MarkController.ts +++ b/src/background/controllers/MarkController.ts @@ -1,10 +1,11 @@ +import { injectable } from 'tsyringe'; import MarkUseCase from '../usecases/MarkUseCase'; +@injectable() export default class MarkController { - private markUseCase: MarkUseCase; - - constructor() { - this.markUseCase = new MarkUseCase(); + constructor( + private markUseCase: MarkUseCase, + ) { } setGlobal(key: string, x: number, y: number): Promise<any> { diff --git a/src/background/controllers/OperationController.ts b/src/background/controllers/OperationController.ts index fa09512..de6f8cb 100644 --- a/src/background/controllers/OperationController.ts +++ b/src/background/controllers/OperationController.ts @@ -1,3 +1,4 @@ +import { injectable } from 'tsyringe'; import * as operations from '../../shared/operations'; import FindUseCase from '../usecases/FindUseCase'; import ConsoleUseCase from '../usecases/ConsoleUseCase'; @@ -5,23 +6,15 @@ import TabUseCase from '../usecases/TabUseCase'; import TabSelectUseCase from '../usecases/TabSelectUseCase'; import ZoomUseCase from '../usecases/ZoomUseCase'; +@injectable() export default class OperationController { - private findUseCase: FindUseCase; - - private consoleUseCase: ConsoleUseCase; - - private tabUseCase: TabUseCase; - - private tabSelectUseCase: TabSelectUseCase; - - private zoomUseCase: ZoomUseCase; - - constructor() { - this.findUseCase = new FindUseCase(); - this.consoleUseCase = new ConsoleUseCase(); - this.tabUseCase = new TabUseCase(); - this.tabSelectUseCase = new TabSelectUseCase(); - this.zoomUseCase = new ZoomUseCase(); + constructor( + private findUseCase: FindUseCase, + private consoleUseCase: ConsoleUseCase, + private tabUseCase: TabUseCase, + private tabSelectUseCase: TabSelectUseCase, + private zoomUseCase: ZoomUseCase, + ) { } // eslint-disable-next-line complexity, max-lines-per-function diff --git a/src/background/controllers/SettingController.ts b/src/background/controllers/SettingController.ts index dfd2817..34951ff 100644 --- a/src/background/controllers/SettingController.ts +++ b/src/background/controllers/SettingController.ts @@ -1,15 +1,14 @@ +import { injectable } from 'tsyringe'; import SettingUseCase from '../usecases/SettingUseCase'; import ContentMessageClient from '../infrastructures/ContentMessageClient'; import Settings from '../../shared/Settings'; +@injectable() export default class SettingController { - private settingUseCase: SettingUseCase; - - private contentMessageClient: ContentMessageClient; - - constructor() { - this.settingUseCase = new SettingUseCase(); - this.contentMessageClient = new ContentMessageClient(); + constructor( + private settingUseCase: SettingUseCase, + private contentMessageClient: ContentMessageClient, + ) { } getSetting(): Promise<Settings> { diff --git a/src/background/controllers/VersionController.ts b/src/background/controllers/VersionController.ts index 2e2a197..b00185a 100644 --- a/src/background/controllers/VersionController.ts +++ b/src/background/controllers/VersionController.ts @@ -1,10 +1,11 @@ +import { injectable } from 'tsyringe'; import VersionUseCase from '../usecases/VersionUseCase'; +@injectable() export default class VersionController { - private versionUseCase: VersionUseCase; - - constructor() { - this.versionUseCase = new VersionUseCase(); + constructor( + private versionUseCase: VersionUseCase, + ) { } notify(): Promise<void> { |