diff options
Diffstat (limited to 'src/content/usecases')
-rw-r--r-- | src/content/usecases/AddonEnabledUseCase.ts | 22 | ||||
-rw-r--r-- | src/content/usecases/ClipboardUseCase.ts | 37 | ||||
-rw-r--r-- | src/content/usecases/ConsoleFrameUseCase.ts | 15 | ||||
-rw-r--r-- | src/content/usecases/FindSlaveUseCase.ts | 14 | ||||
-rw-r--r-- | src/content/usecases/FindUseCase.ts | 35 | ||||
-rw-r--r-- | src/content/usecases/FocusUseCase.ts | 14 | ||||
-rw-r--r-- | src/content/usecases/FollowMasterUseCase.ts | 50 | ||||
-rw-r--r-- | src/content/usecases/FollowSlaveUseCase.ts | 38 | ||||
-rw-r--r-- | src/content/usecases/KeymapUseCase.ts | 33 | ||||
-rw-r--r-- | src/content/usecases/MarkKeyUseCase.ts | 14 | ||||
-rw-r--r-- | src/content/usecases/MarkUseCase.ts | 46 | ||||
-rw-r--r-- | src/content/usecases/NavigateUseCase.ts | 15 | ||||
-rw-r--r-- | src/content/usecases/ScrollUseCase.ts | 22 | ||||
-rw-r--r-- | src/content/usecases/SettingUseCase.ts | 21 |
14 files changed, 151 insertions, 225 deletions
diff --git a/src/content/usecases/AddonEnabledUseCase.ts b/src/content/usecases/AddonEnabledUseCase.ts index e9ce0a6..2d6fa11 100644 --- a/src/content/usecases/AddonEnabledUseCase.ts +++ b/src/content/usecases/AddonEnabledUseCase.ts @@ -1,19 +1,17 @@ -import AddonIndicatorClient, { AddonIndicatorClientImpl } - from '../client/AddonIndicatorClient'; -import AddonEnabledRepository, { AddonEnabledRepositoryImpl } - from '../repositories/AddonEnabledRepository'; +import { injectable, inject } from 'tsyringe'; +import AddonIndicatorClient from '../client/AddonIndicatorClient'; +import AddonEnabledRepository from '../repositories/AddonEnabledRepository'; +@injectable() export default class AddonEnabledUseCase { - private indicator: AddonIndicatorClient; - private repository: AddonEnabledRepository; + constructor( + @inject('AddonIndicatorClient') + private indicator: AddonIndicatorClient, - constructor({ - indicator = new AddonIndicatorClientImpl(), - repository = new AddonEnabledRepositoryImpl(), - } = {}) { - this.indicator = indicator; - this.repository = repository; + @inject('AddonEnabledRepository') + private repository: AddonEnabledRepository, + ) { } async enable(): Promise<void> { diff --git a/src/content/usecases/ClipboardUseCase.ts b/src/content/usecases/ClipboardUseCase.ts index b2ece2f..8c4d621 100644 --- a/src/content/usecases/ClipboardUseCase.ts +++ b/src/content/usecases/ClipboardUseCase.ts @@ -1,31 +1,18 @@ +import { injectable, inject } from 'tsyringe'; import * as urls from '../../shared/urls'; -import ClipboardRepository, { ClipboardRepositoryImpl } - from '../repositories/ClipboardRepository'; -import SettingRepository, { SettingRepositoryImpl } - from '../repositories/SettingRepository'; -import TabsClient, { TabsClientImpl } - from '../client/TabsClient'; -import ConsoleClient, { ConsoleClientImpl } from '../client/ConsoleClient'; +import ClipboardRepository from '../repositories/ClipboardRepository'; +import SettingRepository from '../repositories/SettingRepository'; +import TabsClient from '../client/TabsClient'; +import ConsoleClient from '../client/ConsoleClient'; +@injectable() export default class ClipboardUseCase { - private repository: ClipboardRepository; - - private settingRepository: SettingRepository; - - private client: TabsClient; - - private consoleClient: ConsoleClient; - - constructor({ - repository = new ClipboardRepositoryImpl(), - settingRepository = new SettingRepositoryImpl(), - client = new TabsClientImpl(), - consoleClient = new ConsoleClientImpl(), - } = {}) { - this.repository = repository; - this.settingRepository = settingRepository; - this.client = client; - this.consoleClient = consoleClient; + constructor( + @inject('ClipboardRepository') private repository: ClipboardRepository, + @inject('SettingRepository') private settingRepository: SettingRepository, + @inject('TabsClient') private client: TabsClient, + @inject('ConsoleClient') private consoleClient: ConsoleClient, + ) { } async yankCurrentURL(): Promise<string> { diff --git a/src/content/usecases/ConsoleFrameUseCase.ts b/src/content/usecases/ConsoleFrameUseCase.ts index b4c756c..3c4b0a1 100644 --- a/src/content/usecases/ConsoleFrameUseCase.ts +++ b/src/content/usecases/ConsoleFrameUseCase.ts @@ -1,13 +1,12 @@ -import ConsoleFramePresenter, { ConsoleFramePresenterImpl } - from '../presenters/ConsoleFramePresenter'; +import { injectable, inject } from 'tsyringe'; +import ConsoleFramePresenter from '../presenters/ConsoleFramePresenter'; +@injectable() export default class ConsoleFrameUseCase { - private consoleFramePresenter: ConsoleFramePresenter; - - constructor({ - consoleFramePresenter = new ConsoleFramePresenterImpl(), - } = {}) { - this.consoleFramePresenter = consoleFramePresenter; + constructor( + @inject('ConsoleFramePresenter') + private consoleFramePresenter: ConsoleFramePresenter, + ) { } unfocus() { diff --git a/src/content/usecases/FindSlaveUseCase.ts b/src/content/usecases/FindSlaveUseCase.ts index b733cbd..0a5c2ce 100644 --- a/src/content/usecases/FindSlaveUseCase.ts +++ b/src/content/usecases/FindSlaveUseCase.ts @@ -1,13 +1,11 @@ -import FindMasterClient, { FindMasterClientImpl } - from '../client/FindMasterClient'; +import { injectable, inject } from 'tsyringe'; +import FindMasterClient from '../client/FindMasterClient'; +@injectable() export default class FindSlaveUseCase { - private findMasterClient: FindMasterClient; - - constructor({ - findMasterClient = new FindMasterClientImpl(), - } = {}) { - this.findMasterClient = findMasterClient; + constructor( + @inject('FindMasterClient') private findMasterClient: FindMasterClient, + ) { } findNext() { diff --git a/src/content/usecases/FindUseCase.ts b/src/content/usecases/FindUseCase.ts index 74cbc97..88b516c 100644 --- a/src/content/usecases/FindUseCase.ts +++ b/src/content/usecases/FindUseCase.ts @@ -1,28 +1,17 @@ -import FindPresenter, { FindPresenterImpl } from '../presenters/FindPresenter'; -import FindRepository, { FindRepositoryImpl } - from '../repositories/FindRepository'; -import FindClient, { FindClientImpl } from '../client/FindClient'; -import ConsoleClient, { ConsoleClientImpl } from '../client/ConsoleClient'; +import { injectable, inject } from 'tsyringe'; +import FindPresenter from '../presenters/FindPresenter'; +import FindRepository from '../repositories/FindRepository'; +import FindClient from '../client/FindClient'; +import ConsoleClient from '../client/ConsoleClient'; +@injectable() export default class FindUseCase { - private presenter: FindPresenter; - - private repository: FindRepository; - - private client: FindClient; - - private consoleClient: ConsoleClient; - - constructor({ - presenter = new FindPresenterImpl() as FindPresenter, - repository = new FindRepositoryImpl(), - client = new FindClientImpl(), - consoleClient = new ConsoleClientImpl(), - } = {}) { - this.presenter = presenter; - this.repository = repository; - this.client = client; - this.consoleClient = consoleClient; + constructor( + @inject('FindPresenter') private presenter: FindPresenter, + @inject('FindRepository') private repository: FindRepository, + @inject('FindClient') private client: FindClient, + @inject('ConsoleClient') private consoleClient: ConsoleClient, + ) { } async startFind(keyword?: string): Promise<void> { diff --git a/src/content/usecases/FocusUseCase.ts b/src/content/usecases/FocusUseCase.ts index 0ad4021..0158672 100644 --- a/src/content/usecases/FocusUseCase.ts +++ b/src/content/usecases/FocusUseCase.ts @@ -1,13 +1,11 @@ -import FocusPresenter, { FocusPresenterImpl } - from '../presenters/FocusPresenter'; +import { injectable, inject } from 'tsyringe'; +import FocusPresenter from '../presenters/FocusPresenter'; +@injectable() export default class FocusUseCases { - private presenter: FocusPresenter; - - constructor({ - presenter = new FocusPresenterImpl(), - } = {}) { - this.presenter = presenter; + constructor( + @inject('FocusPresenter') private presenter: FocusPresenter, + ) { } focusFirstInput() { diff --git a/src/content/usecases/FollowMasterUseCase.ts b/src/content/usecases/FollowMasterUseCase.ts index 9cbb790..7d7e875 100644 --- a/src/content/usecases/FollowMasterUseCase.ts +++ b/src/content/usecases/FollowMasterUseCase.ts @@ -1,31 +1,29 @@ -import FollowKeyRepository, { FollowKeyRepositoryImpl } - from '../repositories/FollowKeyRepository'; -import FollowMasterRepository, { FollowMasterRepositoryImpl } - from '../repositories/FollowMasterRepository'; -import FollowSlaveClient, { FollowSlaveClientImpl } - from '../client/FollowSlaveClient'; +import { injectable, inject } from 'tsyringe'; +import FollowKeyRepository from '../repositories/FollowKeyRepository'; +import FollowMasterRepository from '../repositories/FollowMasterRepository'; +import FollowSlaveClient from '../client/FollowSlaveClient'; +import FollowSlaveClientFactory from '../client/FollowSlaveClientFactory'; +import SettingRepository from '../repositories/SettingRepository'; import HintKeyProducer from './HintKeyProducer'; -import SettingRepository, { SettingRepositoryImpl } - from '../repositories/SettingRepository'; +@injectable() export default class FollowMasterUseCase { - private followKeyRepository: FollowKeyRepository; + // TODO Make repository + private producer: HintKeyProducer | null; - private followMasterRepository: FollowMasterRepository; + constructor( + @inject('FollowKeyRepository') + private followKeyRepository: FollowKeyRepository, - private settingRepository: SettingRepository; + @inject('FollowMasterRepository') + private followMasterRepository: FollowMasterRepository, - // TODO Make repository - private producer: HintKeyProducer | null; + @inject('SettingRepository') + private settingRepository: SettingRepository, - constructor({ - followKeyRepository = new FollowKeyRepositoryImpl(), - followMasterRepository = new FollowMasterRepositoryImpl(), - settingRepository = new SettingRepositoryImpl(), - } = {}) { - this.followKeyRepository = followKeyRepository; - this.followMasterRepository = followMasterRepository; - this.settingRepository = settingRepository; + @inject('FollowSlaveClientFactory') + private followSlaveClientFactory: FollowSlaveClientFactory, + ) { this.producer = null; } @@ -38,7 +36,7 @@ export default class FollowMasterUseCase { let viewWidth = window.top.innerWidth; let viewHeight = window.top.innerHeight; - new FollowSlaveClientImpl(window.top).requestHintCount( + this.followSlaveClientFactory.create(window.top).requestHintCount( { width: viewWidth, height: viewHeight }, { x: 0, y: 0 }, ); @@ -47,7 +45,8 @@ export default class FollowMasterUseCase { for (let i = 0; i < frameElements.length; ++i) { let ele = frameElements[i] as HTMLFrameElement | HTMLIFrameElement; let { left: frameX, top: frameY } = ele.getBoundingClientRect(); - new FollowSlaveClientImpl(ele.contentWindow!!).requestHintCount( + let client = this.followSlaveClientFactory.create(ele.contentWindow!!); + client.requestHintCount( { width: viewWidth, height: viewHeight }, { x: frameX, y: frameY }, ); @@ -77,7 +76,8 @@ export default class FollowMasterUseCase { let { left: frameX, top: frameY } = ele.getBoundingClientRect(); pos = { x: frameX, y: frameY }; } - new FollowSlaveClientImpl(sender).createHints( + let client = this.followSlaveClientFactory.create(sender); + client.createHints( { width: viewWidth, height: viewHeight }, pos, produced, @@ -138,7 +138,7 @@ export default class FollowMasterUseCase { private broadcastToSlaves(handler: (client: FollowSlaveClient) => void) { let allFrames = [window.self].concat(Array.from(window.frames as any)); - let clients = allFrames.map(frame => new FollowSlaveClientImpl(frame)); + let clients = allFrames.map(w => this.followSlaveClientFactory.create(w)); for (let client of clients) { handler(client); } diff --git a/src/content/usecases/FollowSlaveUseCase.ts b/src/content/usecases/FollowSlaveUseCase.ts index eb011de..a2cc80e 100644 --- a/src/content/usecases/FollowSlaveUseCase.ts +++ b/src/content/usecases/FollowSlaveUseCase.ts @@ -1,11 +1,9 @@ -import FollowSlaveRepository, { FollowSlaveRepositoryImpl } - from '../repositories/FollowSlaveRepository'; -import FollowPresenter, { FollowPresenterImpl } - from '../presenters/FollowPresenter'; -import TabsClient, { TabsClientImpl } from '../client/TabsClient'; +import { injectable, inject } from 'tsyringe'; +import FollowSlaveRepository from '../repositories/FollowSlaveRepository'; +import FollowPresenter from '../presenters/FollowPresenter'; +import TabsClient from '../client/TabsClient'; +import FollowMasterClient from '../client/FollowMasterClient'; import { LinkHint, InputHint } from '../presenters/Hint'; -import FollowMasterClient, { FollowMasterClientImpl } - from '../client/FollowMasterClient'; import Key from '../domains/Key'; interface Size { @@ -18,25 +16,21 @@ interface Point { y: number; } +@injectable() export default class FollowSlaveUseCase { - private presenter: FollowPresenter; + constructor( + @inject('FollowPresenter') + private presenter: FollowPresenter, - private tabsClient: TabsClient; + @inject('TabsClient') + private tabsClient: TabsClient, - private followMasterClient: FollowMasterClient; + @inject('FollowMasterClient') + private followMasterClient: FollowMasterClient, - private followSlaveRepository: FollowSlaveRepository; - - constructor({ - presenter = new FollowPresenterImpl(), - tabsClient = new TabsClientImpl(), - followMasterClient = new FollowMasterClientImpl(window.top), - followSlaveRepository = new FollowSlaveRepositoryImpl(), - } = {}) { - this.presenter = presenter; - this.tabsClient = tabsClient; - this.followMasterClient = followMasterClient; - this.followSlaveRepository = followSlaveRepository; + @inject('FollowSlaveRepository') + private followSlaveRepository: FollowSlaveRepository, + ) { } countTargets(viewSize: Size, framePosition: Point): void { diff --git a/src/content/usecases/KeymapUseCase.ts b/src/content/usecases/KeymapUseCase.ts index af0ad77..d0d039a 100644 --- a/src/content/usecases/KeymapUseCase.ts +++ b/src/content/usecases/KeymapUseCase.ts @@ -1,10 +1,7 @@ -import KeymapRepository, { KeymapRepositoryImpl } - from '../repositories/KeymapRepository'; -import SettingRepository, { SettingRepositoryImpl } - from '../repositories/SettingRepository'; -import AddonEnabledRepository, { AddonEnabledRepositoryImpl } - from '../repositories/AddonEnabledRepository'; - +import { injectable, inject } from 'tsyringe'; +import KeymapRepository from '../repositories/KeymapRepository'; +import SettingRepository from '../repositories/SettingRepository'; +import AddonEnabledRepository from '../repositories/AddonEnabledRepository'; import * as operations from '../../shared/operations'; import { Keymaps } from '../../shared/Settings'; import Key from '../domains/Key'; @@ -17,22 +14,18 @@ const reservedKeymaps: Keymaps = { '<C-[>': { type: operations.CANCEL }, }; - +@injectable() export default class KeymapUseCase { - private repository: KeymapRepository; - - private settingRepository: SettingRepository; + constructor( + @inject('KeymapRepository') + private repository: KeymapRepository, - private addonEnabledRepository: AddonEnabledRepository; + @inject('SettingRepository') + private settingRepository: SettingRepository, - constructor({ - repository = new KeymapRepositoryImpl(), - settingRepository = new SettingRepositoryImpl(), - addonEnabledRepository = new AddonEnabledRepositoryImpl(), - } = {}) { - this.repository = repository; - this.settingRepository = settingRepository; - this.addonEnabledRepository = addonEnabledRepository; + @inject('AddonEnabledRepository') + private addonEnabledRepository: AddonEnabledRepository, + ) { } nextOp(key: Key): operations.Operation | null { diff --git a/src/content/usecases/MarkKeyUseCase.ts b/src/content/usecases/MarkKeyUseCase.ts index c0aa655..6cef6f2 100644 --- a/src/content/usecases/MarkKeyUseCase.ts +++ b/src/content/usecases/MarkKeyUseCase.ts @@ -1,13 +1,11 @@ -import MarkKeyRepository, { MarkKeyRepositoryImpl } - from '../repositories/MarkKeyRepository'; +import { injectable, inject } from 'tsyringe'; +import MarkKeyRepository from '../repositories/MarkKeyRepository'; +@injectable() export default class MarkKeyUseCase { - private repository: MarkKeyRepository; - - constructor({ - repository = new MarkKeyRepositoryImpl() - } = {}) { - this.repository = repository; + constructor( + @inject('MarkKeyRepository') private repository: MarkKeyRepository, + ) { } isSetMode(): boolean { diff --git a/src/content/usecases/MarkUseCase.ts b/src/content/usecases/MarkUseCase.ts index 530f141..a7d5ad8 100644 --- a/src/content/usecases/MarkUseCase.ts +++ b/src/content/usecases/MarkUseCase.ts @@ -1,35 +1,19 @@ -import ScrollPresenter, { ScrollPresenterImpl } - from '../presenters/ScrollPresenter'; -import MarkClient, { MarkClientImpl } from '../client/MarkClient'; -import MarkRepository, { MarkRepositoryImpl } - from '../repositories/MarkRepository'; -import SettingRepository, { SettingRepositoryImpl } - from '../repositories/SettingRepository'; -import ConsoleClient, { ConsoleClientImpl } from '../client/ConsoleClient'; - +import { injectable, inject } from 'tsyringe'; +import ScrollPresenter from '../presenters/ScrollPresenter'; +import MarkClient from '../client/MarkClient'; +import MarkRepository from '../repositories/MarkRepository'; +import SettingRepository from '../repositories/SettingRepository'; +import ConsoleClient from '../client/ConsoleClient'; + +@injectable() export default class MarkUseCase { - private scrollPresenter: ScrollPresenter; - - private client: MarkClient; - - private repository: MarkRepository; - - private settingRepository: SettingRepository; - - private consoleClient: ConsoleClient; - - constructor({ - scrollPresenter = new ScrollPresenterImpl(), - client = new MarkClientImpl(), - repository = new MarkRepositoryImpl(), - settingRepository = new SettingRepositoryImpl(), - consoleClient = new ConsoleClientImpl(), - } = {}) { - this.scrollPresenter = scrollPresenter; - this.client = client; - this.repository = repository; - this.settingRepository = settingRepository; - this.consoleClient = consoleClient; + constructor( + @inject('ScrollPresenter') private scrollPresenter: ScrollPresenter, + @inject('MarkClient') private client: MarkClient, + @inject('MarkRepository') private repository: MarkRepository, + @inject('SettingRepository') private settingRepository: SettingRepository, + @inject('ConsoleClient') private consoleClient: ConsoleClient, + ) { } async set(key: string): Promise<void> { diff --git a/src/content/usecases/NavigateUseCase.ts b/src/content/usecases/NavigateUseCase.ts index 6f82d3f..4711c5e 100644 --- a/src/content/usecases/NavigateUseCase.ts +++ b/src/content/usecases/NavigateUseCase.ts @@ -1,13 +1,12 @@ -import NavigationPresenter, { NavigationPresenterImpl } - from '../presenters/NavigationPresenter'; +import { injectable, inject } from 'tsyringe'; +import NavigationPresenter from '../presenters/NavigationPresenter'; +@injectable() export default class NavigateUseCase { - private navigationPresenter: NavigationPresenter; - - constructor({ - navigationPresenter = new NavigationPresenterImpl(), - } = {}) { - this.navigationPresenter = navigationPresenter; + constructor( + @inject('NavigationPresenter') + private navigationPresenter: NavigationPresenter, + ) { } openHistoryPrev(): void { diff --git a/src/content/usecases/ScrollUseCase.ts b/src/content/usecases/ScrollUseCase.ts index 6a1f801..32cbef1 100644 --- a/src/content/usecases/ScrollUseCase.ts +++ b/src/content/usecases/ScrollUseCase.ts @@ -1,19 +1,13 @@ -import ScrollPresenter, { ScrollPresenterImpl } - from '../presenters/ScrollPresenter'; -import SettingRepository, { SettingRepositoryImpl } - from '../repositories/SettingRepository'; +import { injectable, inject } from 'tsyringe'; +import ScrollPresenter from '../presenters/ScrollPresenter'; +import SettingRepository from '../repositories/SettingRepository'; +@injectable() export default class ScrollUseCase { - private presenter: ScrollPresenter; - - private settingRepository: SettingRepository; - - constructor({ - presenter = new ScrollPresenterImpl(), - settingRepository = new SettingRepositoryImpl(), - } = {}) { - this.presenter = presenter; - this.settingRepository = settingRepository; + constructor( + @inject('ScrollPresenter') private presenter: ScrollPresenter, + @inject('SettingRepository') private settingRepository: SettingRepository, + ) { } scrollVertically(count: number): void { diff --git a/src/content/usecases/SettingUseCase.ts b/src/content/usecases/SettingUseCase.ts index 765cb45..d5f66c6 100644 --- a/src/content/usecases/SettingUseCase.ts +++ b/src/content/usecases/SettingUseCase.ts @@ -1,19 +1,14 @@ -import SettingRepository, { SettingRepositoryImpl } - from '../repositories/SettingRepository'; -import SettingClient, { SettingClientImpl } from '../client/SettingClient'; +import { injectable, inject } from 'tsyringe'; +import SettingRepository from '../repositories/SettingRepository'; +import SettingClient from '../client/SettingClient'; import Settings from '../../shared/Settings'; +@injectable() export default class SettingUseCase { - private repository: SettingRepository; - - private client: SettingClient; - - constructor({ - repository = new SettingRepositoryImpl(), - client = new SettingClientImpl(), - } = {}) { - this.repository = repository; - this.client = client; + constructor( + @inject('SettingRepository') private repository: SettingRepository, + @inject('SettingClient') private client: SettingClient, + ) { } async reload(): Promise<Settings> { |