Use TSyringe on content script

jh-changes
Shin'ya Ueoka 6 years ago
parent 71f3a1ea2d
commit 1666e626b0
  1. 111
      src/content/Application.ts
  2. 2
      src/content/MessageListener.ts
  3. 2
      src/content/client/BackgroundClient.ts
  4. 11
      src/content/controllers/AddonEnabledController.ts
  5. 11
      src/content/controllers/ConsoleFrameController.ts
  6. 11
      src/content/controllers/FindController.ts
  7. 11
      src/content/controllers/FollowKeyController.ts
  8. 11
      src/content/controllers/FollowMasterController.ts
  9. 11
      src/content/controllers/FollowSlaveController.ts
  10. 59
      src/content/controllers/KeymapController.ts
  11. 11
      src/content/controllers/MarkController.ts
  12. 16
      src/content/controllers/MarkKeyController.ts
  13. 15
      src/content/controllers/SettingController.ts
  14. 52
      src/content/di.ts
  15. 16
      src/content/index.ts
  16. 97
      src/content/routes.ts
  17. 22
      src/content/usecases/AddonEnabledUseCase.ts
  18. 37
      src/content/usecases/ClipboardUseCase.ts
  19. 15
      src/content/usecases/ConsoleFrameUseCase.ts
  20. 14
      src/content/usecases/FindSlaveUseCase.ts
  21. 35
      src/content/usecases/FindUseCase.ts
  22. 14
      src/content/usecases/FocusUseCase.ts
  23. 35
      src/content/usecases/FollowMasterUseCase.ts
  24. 38
      src/content/usecases/FollowSlaveUseCase.ts
  25. 33
      src/content/usecases/KeymapUseCase.ts
  26. 14
      src/content/usecases/MarkKeyUseCase.ts
  27. 46
      src/content/usecases/MarkUseCase.ts
  28. 15
      src/content/usecases/NavigateUseCase.ts
  29. 22
      src/content/usecases/ScrollUseCase.ts
  30. 21
      src/content/usecases/SettingUseCase.ts
  31. 2
      test/content/usecases/AddonEnabledUseCase.test.ts
  32. 8
      test/content/usecases/ClipboardUseCase.test.ts
  33. 2
      test/content/usecases/FindUseCase.test.ts
  34. 11
      test/content/usecases/MarkUseCase.test.ts
  35. 2
      test/content/usecases/SettingUseCaase.test.ts

@ -0,0 +1,111 @@
import { injectable } from 'tsyringe';
import MessageListener from './MessageListener';
import FindController from './controllers/FindController';
import MarkController from './controllers/MarkController';
import FollowMasterController from './controllers/FollowMasterController';
import FollowSlaveController from './controllers/FollowSlaveController';
import FollowKeyController from './controllers/FollowKeyController';
import InputDriver from './InputDriver';
import KeymapController from './controllers/KeymapController';
import AddonEnabledUseCase from './usecases/AddonEnabledUseCase';
import MarkKeyController from './controllers/MarkKeyController';
import AddonEnabledController from './controllers/AddonEnabledController';
import SettingController from './controllers/SettingController';
import ConsoleFrameController from './controllers/ConsoleFrameController';
import * as messages from '../shared/messages';
type Message = messages.Message;
@injectable()
export default class Application {
// eslint-disable-next-line max-params
constructor(
private messageListener: MessageListener,
private findController: FindController,
private markController: MarkController,
private followMasterController: FollowMasterController,
private followSlaveController: FollowSlaveController,
private followKeyController: FollowKeyController,
private keymapController: KeymapController,
private addonEnabledUseCase: AddonEnabledUseCase,
private markKeyController: MarkKeyController,
private addonEnabledController: AddonEnabledController,
private settingController: SettingController,
private consoleFrameController: ConsoleFrameController,
) {
}
run() {
this.routeCommonComponents();
if (window.self === window.top) {
this.routeMasterComponents();
}
}
private routeMasterComponents() {
this.messageListener.onWebMessage((msg: Message, sender: Window) => {
switch (msg.type) {
case messages.CONSOLE_ENTER_FIND:
return this.findController.start(msg);
case messages.FIND_NEXT:
return this.findController.next(msg);
case messages.FIND_PREV:
return this.findController.prev(msg);
case messages.CONSOLE_UNFOCUS:
return this.consoleFrameController.unfocus(msg);
case messages.FOLLOW_START:
return this.followMasterController.followStart(msg);
case messages.FOLLOW_RESPONSE_COUNT_TARGETS:
return this.followMasterController.responseCountTargets(msg, sender);
case messages.FOLLOW_KEY_PRESS:
return this.followMasterController.keyPress(msg);
}
return undefined;
});
this.messageListener.onBackgroundMessage((msg: Message) => {
switch (msg.type) {
case messages.ADDON_ENABLED_QUERY:
return this.addonEnabledController.getAddonEnabled(msg);
case messages.TAB_SCROLL_TO:
return this.markController.scrollTo(msg);
}
return undefined;
});
}
private routeCommonComponents() {
this.messageListener.onWebMessage((msg: Message) => {
switch (msg.type) {
case messages.FOLLOW_REQUEST_COUNT_TARGETS:
return this.followSlaveController.countTargets(msg);
case messages.FOLLOW_CREATE_HINTS:
return this.followSlaveController.createHints(msg);
case messages.FOLLOW_SHOW_HINTS:
return this.followSlaveController.showHints(msg);
case messages.FOLLOW_ACTIVATE:
return this.followSlaveController.activate(msg);
case messages.FOLLOW_REMOVE_HINTS:
return this.followSlaveController.clear(msg);
}
return undefined;
});
this.messageListener.onBackgroundMessage((msg: Message): any => {
switch (msg.type) {
case messages.SETTINGS_CHANGED:
return this.settingController.reloadSettings(msg);
case messages.ADDON_TOGGLE_ENABLED:
return this.addonEnabledUseCase.toggle();
}
});
let inputDriver = new InputDriver(window.document.body);
inputDriver.onKey(key => this.followKeyController.press(key));
inputDriver.onKey(key => this.markKeyController.press(key));
inputDriver.onKey(key => this.keymapController.press(key));
this.settingController.initSettings();
}
}

@ -1,7 +1,9 @@
import { injectable } from 'tsyringe';
import { Message, valueOf } from '../shared/messages';
export type WebExtMessageSender = browser.runtime.MessageSender;
@injectable()
export default class MessageListener {
onWebMessage(
listener: (msg: Message, sender: Window) => void,

@ -1,6 +1,8 @@
import { injectable } from 'tsyringe';
import * as operations from '../../shared/operations';
import * as messages from '../../shared/messages';
@injectable()
export default class BackgroundClient {
execBackgroundOp(op: operations.Operation): Promise<void> {
return browser.runtime.sendMessage({

@ -1,13 +1,12 @@
import { injectable } from 'tsyringe';
import * as messages from '../../shared/messages';
import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase';
@injectable()
export default class AddonEnabledController {
private addonEnabledUseCase: AddonEnabledUseCase;
constructor({
addonEnabledUseCase = new AddonEnabledUseCase(),
} = {}) {
this.addonEnabledUseCase = addonEnabledUseCase;
constructor(
private addonEnabledUseCase: AddonEnabledUseCase,
) {
}
getAddonEnabled(

@ -1,13 +1,12 @@
import { injectable } from 'tsyringe';
import ConsoleFrameUseCase from '../usecases/ConsoleFrameUseCase';
import * as messages from '../../shared/messages';
@injectable()
export default class ConsoleFrameController {
private consoleFrameUseCase: ConsoleFrameUseCase;
constructor({
consoleFrameUseCase = new ConsoleFrameUseCase(),
} = {}) {
this.consoleFrameUseCase = consoleFrameUseCase;
constructor(
private consoleFrameUseCase: ConsoleFrameUseCase,
) {
}
unfocus(_message: messages.Message) {

@ -1,13 +1,12 @@
import { injectable } from 'tsyringe';
import * as messages from '../../shared/messages';
import FindUseCase from '../usecases/FindUseCase';
@injectable()
export default class FindController {
private findUseCase: FindUseCase;
constructor({
findUseCase = new FindUseCase(),
} = {}) {
this.findUseCase = findUseCase;
constructor(
private findUseCase: FindUseCase,
) {
}
async start(m: messages.ConsoleEnterFindMessage): Promise<void> {

@ -1,13 +1,12 @@
import { injectable } from 'tsyringe';
import FollowSlaveUseCase from '../usecases/FollowSlaveUseCase';
import Key from '../domains/Key';
@injectable()
export default class FollowKeyController {
private followSlaveUseCase: FollowSlaveUseCase;
constructor({
followSlaveUseCase = new FollowSlaveUseCase(),
} = {}) {
this.followSlaveUseCase = followSlaveUseCase;
constructor(
private followSlaveUseCase: FollowSlaveUseCase,
) {
}
press(key: Key): boolean {

@ -1,13 +1,12 @@
import { injectable } from 'tsyringe';
import FollowMasterUseCase from '../usecases/FollowMasterUseCase';
import * as messages from '../../shared/messages';
@injectable()
export default class FollowMasterController {
private followMasterUseCase: FollowMasterUseCase;
constructor({
followMasterUseCase = new FollowMasterUseCase(),
} = {}) {
this.followMasterUseCase = followMasterUseCase;
constructor(
private followMasterUseCase: FollowMasterUseCase,
) {
}
followStart(m: messages.FollowStartMessage): void {

@ -1,13 +1,12 @@
import { injectable } from 'tsyringe';
import * as messages from '../../shared/messages';
import FollowSlaveUseCase from '../usecases/FollowSlaveUseCase';
@injectable()
export default class FollowSlaveController {
private usecase: FollowSlaveUseCase;
constructor({
usecase = new FollowSlaveUseCase(),
} = {}) {
this.usecase = usecase;
constructor(
private usecase: FollowSlaveUseCase,
) {
}
countTargets(m: messages.FollowRequestCountTargetsMessage): void {

@ -1,3 +1,4 @@
import { injectable, inject } from 'tsyringe';
import * as operations from '../../shared/operations';
import KeymapUseCase from '../usecases/KeymapUseCase';
import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase';
@ -8,53 +9,25 @@ import FocusUseCase from '../usecases/FocusUseCase';
import ClipboardUseCase from '../usecases/ClipboardUseCase';
import BackgroundClient from '../client/BackgroundClient';
import MarkKeyyUseCase from '../usecases/MarkKeyUseCase';
import FollowMasterClient, { FollowMasterClientImpl }
from '../client/FollowMasterClient';
import FollowMasterClient from '../client/FollowMasterClient';
import Key from '../domains/Key';
@injectable()
export default class KeymapController {
private keymapUseCase: KeymapUseCase;
constructor(
private keymapUseCase: KeymapUseCase,
private addonEnabledUseCase: AddonEnabledUseCase,
private findSlaveUseCase: FindSlaveUseCase,
private scrollUseCase: ScrollUseCase,
private navigateUseCase: NavigateUseCase,
private focusUseCase: FocusUseCase,
private clipbaordUseCase: ClipboardUseCase,
private backgroundClient: BackgroundClient,
private markKeyUseCase: MarkKeyyUseCase,
private addonEnabledUseCase: AddonEnabledUseCase;
private findSlaveUseCase: FindSlaveUseCase;
private scrollUseCase: ScrollUseCase;
private navigateUseCase: NavigateUseCase;
private focusUseCase: FocusUseCase;
private clipbaordUseCase: ClipboardUseCase;
private backgroundClient: BackgroundClient;
private markKeyUseCase: MarkKeyyUseCase;
private followMasterClient: FollowMasterClient;
constructor({
keymapUseCase = new KeymapUseCase(),
addonEnabledUseCase = new AddonEnabledUseCase(),
findSlaveUseCase = new FindSlaveUseCase(),
scrollUseCase = new ScrollUseCase(),
navigateUseCase = new NavigateUseCase(),
focusUseCase = new FocusUseCase(),
clipbaordUseCase = new ClipboardUseCase(),
backgroundClient = new BackgroundClient(),
markKeyUseCase = new MarkKeyyUseCase(),
followMasterClient = new FollowMasterClientImpl(window.top),
} = {}) {
this.keymapUseCase = keymapUseCase;
this.addonEnabledUseCase = addonEnabledUseCase;
this.findSlaveUseCase = findSlaveUseCase;
this.scrollUseCase = scrollUseCase;
this.navigateUseCase = navigateUseCase;
this.focusUseCase = focusUseCase;
this.clipbaordUseCase = clipbaordUseCase;
this.backgroundClient = backgroundClient;
this.markKeyUseCase = markKeyUseCase;
this.followMasterClient = followMasterClient;
@inject('FollowMasterClient')
private followMasterClient: FollowMasterClient,
) {
}
// eslint-disable-next-line complexity, max-lines-per-function

@ -1,13 +1,12 @@
import { injectable } from 'tsyringe';
import * as messages from '../../shared/messages';
import MarkUseCase from '../usecases/MarkUseCase';
@injectable()
export default class MarkController {
private markUseCase: MarkUseCase;
constructor({
markUseCase = new MarkUseCase(),
} = {}) {
this.markUseCase = markUseCase;
constructor(
private markUseCase: MarkUseCase,
) {
}
scrollTo(message: messages.TabScrollToMessage) {

@ -1,18 +1,14 @@
import { injectable } from 'tsyringe';
import MarkUseCase from '../usecases/MarkUseCase';
import MarkKeyyUseCase from '../usecases/MarkKeyUseCase';
import Key from '../domains/Key';
@injectable()
export default class MarkKeyController {
private markUseCase: MarkUseCase;
private markKeyUseCase: MarkKeyyUseCase;
constructor({
markUseCase = new MarkUseCase(),
markKeyUseCase = new MarkKeyyUseCase(),
} = {}) {
this.markUseCase = markUseCase;
this.markKeyUseCase = markKeyUseCase;
constructor(
private markUseCase: MarkUseCase,
private markKeyUseCase: MarkKeyyUseCase,
) {
}
press(key: Key): boolean {

@ -1,20 +1,17 @@
import { injectable } from 'tsyringe';
import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase';
import SettingUseCase from '../usecases/SettingUseCase';
import * as blacklists from '../../shared/blacklists';
import * as messages from '../../shared/messages';
@injectable()
export default class SettingController {
private addonEnabledUseCase: AddonEnabledUseCase;
private settingUseCase: SettingUseCase;
constructor({
addonEnabledUseCase = new AddonEnabledUseCase(),
settingUseCase = new SettingUseCase(),
} = {}) {
this.addonEnabledUseCase = addonEnabledUseCase;
this.settingUseCase = settingUseCase;
constructor(
private addonEnabledUseCase: AddonEnabledUseCase,
private settingUseCase: SettingUseCase,
) {
}
async initSettings(): Promise<void> {

@ -0,0 +1,52 @@
/* eslint-disable max-len */
import { FollowMasterClientImpl } from './client/FollowMasterClient';
import { AddonIndicatorClientImpl } from './client/AddonIndicatorClient';
import { AddonEnabledRepositoryImpl } from './repositories/AddonEnabledRepository';
import { ClipboardRepositoryImpl } from './repositories/ClipboardRepository';
import { SettingRepositoryImpl } from './repositories/SettingRepository';
import { TabsClientImpl } from './client/TabsClient';
import { ConsoleClientImpl } from './client/ConsoleClient';
import { ConsoleFramePresenterImpl } from './presenters/ConsoleFramePresenter';
import { FindMasterClientImpl } from './client/FindMasterClient';
import { FindPresenterImpl } from './presenters/FindPresenter';
import { FindRepositoryImpl } from './repositories/FindRepository';
import { FindClientImpl } from './client/FindClient';
import { FocusPresenterImpl } from './presenters/FocusPresenter';
import { FollowKeyRepositoryImpl } from './repositories/FollowKeyRepository';
import { FollowMasterRepositoryImpl } from './repositories/FollowMasterRepository';
import { FollowSlaveRepositoryImpl } from './repositories/FollowSlaveRepository';
import { FollowPresenterImpl } from './presenters/FollowPresenter';
import { KeymapRepositoryImpl } from './repositories/KeymapRepository';
import { MarkKeyRepositoryImpl } from './repositories/MarkKeyRepository';
import { ScrollPresenterImpl } from './presenters/ScrollPresenter';
import { MarkClientImpl } from './client/MarkClient';
import { MarkRepositoryImpl } from './repositories/MarkRepository';
import { NavigationPresenterImpl } from './presenters/NavigationPresenter';
import { SettingClientImpl } from './client/SettingClient';
import { container } from 'tsyringe';
container.register('FollowMasterClient', { useValue: new FollowMasterClientImpl(window.top) });
container.register('AddonIndicatorClient', { useClass: AddonIndicatorClientImpl });
container.register('AddonEnabledRepository', { useClass: AddonEnabledRepositoryImpl });
container.register('ClipboardRepository', { useClass: ClipboardRepositoryImpl });
container.register('SettingRepository', { useClass: SettingRepositoryImpl });
container.register('TabsClient', { useClass: TabsClientImpl });
container.register('ConsoleClient', { useClass: ConsoleClientImpl });
container.register('ConsoleFramePresenter', { useClass: ConsoleFramePresenterImpl });
container.register('FindMasterClient', { useClass: FindMasterClientImpl });
container.register('FindPresenter', { useClass: FindPresenterImpl });
container.register('FindRepository', { useClass: FindRepositoryImpl });
container.register('FindClient', { useClass: FindClientImpl });
container.register('FocusPresenter', { useClass: FocusPresenterImpl });
container.register('FollowKeyRepository', { useClass: FollowKeyRepositoryImpl });
container.register('FollowMasterRepository', { useClass: FollowMasterRepositoryImpl });
container.register('FollowSlaveRepository', { useClass: FollowSlaveRepositoryImpl });
container.register('FollowPresenter', { useClass: FollowPresenterImpl });
container.register('KeymapRepository', { useClass: KeymapRepositoryImpl });
container.register('MarkKeyRepository', { useClass: MarkKeyRepositoryImpl });
container.register('ScrollPresenter', { useClass: ScrollPresenterImpl });
container.register('MarkClient', { useClass: MarkClientImpl });
container.register('MarkRepository', { useClass: MarkRepositoryImpl });
container.register('NavigationPresenter', { useClass: NavigationPresenterImpl });
container.register('SettingClient', { useClass: SettingClientImpl });

@ -1,15 +1,19 @@
import { ConsoleFramePresenterImpl } from './presenters/ConsoleFramePresenter';
import 'reflect-metadata';
import Application from './Application';
import consoleFrameStyle from './site-style';
import * as routes from './routes';
import { ConsoleFramePresenterImpl } from './presenters/ConsoleFramePresenter';
import { container } from 'tsyringe';
import './di';
if (window.self === window.top) {
routes.routeMasterComponents();
new ConsoleFramePresenterImpl().initialize();
}
routes.routeComponents();
try {
let app = container.resolve(Application);
app.run();
} catch (e) { console.error(e); }
let style = window.document.createElement('style');
style.textContent = consoleFrameStyle;

@ -1,97 +0,0 @@
import MessageListener from './MessageListener';
import FindController from './controllers/FindController';
import MarkController from './controllers/MarkController';
import FollowMasterController from './controllers/FollowMasterController';
import FollowSlaveController from './controllers/FollowSlaveController';
import FollowKeyController from './controllers/FollowKeyController';
import InputDriver from './InputDriver';
import KeymapController from './controllers/KeymapController';
import AddonEnabledUseCase from './usecases/AddonEnabledUseCase';
import MarkKeyController from './controllers/MarkKeyController';
import AddonEnabledController from './controllers/AddonEnabledController';
import SettingController from './controllers/SettingController';
import ConsoleFrameController from './controllers/ConsoleFrameController';
import * as messages from '../shared/messages';
export const routeComponents = () => {
let listener = new MessageListener();
let followSlaveController = new FollowSlaveController();
listener.onWebMessage((message: messages.Message) => {
switch (message.type) {
case messages.FOLLOW_REQUEST_COUNT_TARGETS:
return followSlaveController.countTargets(message);
case messages.FOLLOW_CREATE_HINTS:
return followSlaveController.createHints(message);
case messages.FOLLOW_SHOW_HINTS:
return followSlaveController.showHints(message);
case messages.FOLLOW_ACTIVATE:
return followSlaveController.activate(message);
case messages.FOLLOW_REMOVE_HINTS:
return followSlaveController.clear(message);
}
return undefined;
});
let keymapController = new KeymapController();
let markKeyController = new MarkKeyController();
let followKeyController = new FollowKeyController();
let inputDriver = new InputDriver(document.body);
inputDriver.onKey(key => followKeyController.press(key));
inputDriver.onKey(key => markKeyController.press(key));
inputDriver.onKey(key => keymapController.press(key));
let settingController = new SettingController();
settingController.initSettings();
listener.onBackgroundMessage((message: messages.Message): any => {
let addonEnabledUseCase = new AddonEnabledUseCase();
switch (message.type) {
case messages.SETTINGS_CHANGED:
return settingController.reloadSettings(message);
case messages.ADDON_TOGGLE_ENABLED:
return addonEnabledUseCase.toggle();
}
});
};
export const routeMasterComponents = () => {
let listener = new MessageListener();
let findController = new FindController();
let followMasterController = new FollowMasterController();
let markController = new MarkController();
let addonEnabledController = new AddonEnabledController();
let consoleFrameController = new ConsoleFrameController();
listener.onWebMessage((message: messages.Message, sender: Window) => {
switch (message.type) {
case messages.CONSOLE_ENTER_FIND:
return findController.start(message);
case messages.FIND_NEXT:
return findController.next(message);
case messages.FIND_PREV:
return findController.prev(message);
case messages.CONSOLE_UNFOCUS:
return consoleFrameController.unfocus(message);
case messages.FOLLOW_START:
return followMasterController.followStart(message);
case messages.FOLLOW_RESPONSE_COUNT_TARGETS:
return followMasterController.responseCountTargets(message, sender);
case messages.FOLLOW_KEY_PRESS:
return followMasterController.keyPress(message);
}
return undefined;
});
listener.onBackgroundMessage((message: messages.Message) => {
switch (message.type) {
case messages.ADDON_ENABLED_QUERY:
return addonEnabledController.getAddonEnabled(message);
case messages.TAB_SCROLL_TO:
return markController.scrollTo(message);
}
return undefined;
});
};

@ -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> {

@ -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> {

@ -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() {

@ -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() {

@ -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> {

@ -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() {

@ -1,31 +1,26 @@
import FollowKeyRepository, { FollowKeyRepositoryImpl }
from '../repositories/FollowKeyRepository';
import FollowMasterRepository, { FollowMasterRepositoryImpl }
from '../repositories/FollowMasterRepository';
import { injectable, inject } from 'tsyringe';
import FollowKeyRepository from '../repositories/FollowKeyRepository';
import FollowMasterRepository from '../repositories/FollowMasterRepository';
import FollowSlaveClient, { FollowSlaveClientImpl }
from '../client/FollowSlaveClient';
import SettingRepository from '../repositories/SettingRepository';
import HintKeyProducer from './HintKeyProducer';
import SettingRepository, { SettingRepositoryImpl }
from '../repositories/SettingRepository';
@injectable()
export default class FollowMasterUseCase {
private followKeyRepository: FollowKeyRepository;
private followMasterRepository: FollowMasterRepository;
private settingRepository: SettingRepository;
// TODO Make repository
private producer: HintKeyProducer | null;
constructor({
followKeyRepository = new FollowKeyRepositoryImpl(),
followMasterRepository = new FollowMasterRepositoryImpl(),
settingRepository = new SettingRepositoryImpl(),
} = {}) {
this.followKeyRepository = followKeyRepository;
this.followMasterRepository = followMasterRepository;
this.settingRepository = settingRepository;
constructor(
@inject('FollowKeyRepository')
private followKeyRepository: FollowKeyRepository,
@inject('FollowMasterRepository')
private followMasterRepository: FollowMasterRepository,
@inject('SettingRepository')
private settingRepository: SettingRepository,
) {
this.producer = null;
}

@ -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 {

@ -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 {

@ -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 {

@ -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> {

@ -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 {

@ -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 {

@ -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> {

@ -40,7 +40,7 @@ describe('AddonEnabledUseCase', () => {
beforeEach(() => {
repository = new MockAddonEnabledRepository(true);
indicator = new MockAddonIndicatorClient(false);
sut = new AddonEnabledUseCase({ repository, indicator });
sut = new AddonEnabledUseCase(indicator, repository);
});
describe('#enable', () => {

@ -1,4 +1,5 @@
import ClipboardRepository from '../../../src/content/repositories/ClipboardRepository';
import { SettingRepositoryImpl } from '../../../src/content/repositories/SettingRepository';
import TabsClient from '../../../src/content/client/TabsClient';
import MockConsoleClient from '../mock/MockConsoleClient';
import ClipboardUseCase from '../../../src/content/usecases/ClipboardUseCase';
@ -43,7 +44,12 @@ describe('ClipboardUseCase', () => {
repository = new MockClipboardRepository();
client = new MockTabsClient();
consoleClient = new MockConsoleClient();
sut = new ClipboardUseCase({ repository, client: client, consoleClient });
sut = new ClipboardUseCase(
repository,
new SettingRepositoryImpl(),
client,
consoleClient
);
});
describe('#yankCurrentURL', () => {

@ -71,7 +71,7 @@ describe('FindUseCase', () => {
presenter = new MockFindPresenter();
client = new MockFindClient();
consoleClient = new MockConsoleClient();
sut = new FindUseCase({ repository, presenter, client, consoleClient });
sut = new FindUseCase(presenter, repository, client, consoleClient);
});
describe('#startFind', () => {

@ -1,4 +1,5 @@
import MarkRepository from '../../../src/content/repositories/MarkRepository';
import { SettingRepositoryImpl } from '../../../src/content/repositories/SettingRepository';
import MarkUseCase from '../../../src/content/usecases/MarkUseCase';
import MarkClient from '../../../src/content/client/MarkClient';
import MockConsoleClient from '../mock/MockConsoleClient';
@ -54,9 +55,13 @@ describe('MarkUseCase', () => {
client = new MockMarkClient();
consoleClient = new MockConsoleClient();
scrollPresenter = new MockScrollPresenter();
sut = new MarkUseCase({
repository, client, consoleClient, scrollPresenter,
});
sut = new MarkUseCase(
scrollPresenter,
client,
repository,
new SettingRepositoryImpl(),
consoleClient,
);
});
describe('#set', () => {

@ -56,7 +56,7 @@ describe('AddonEnabledUseCase', () => {
repository = new MockSettingRepository();
client = new MockSettingClient(testSettings);
sut = new SettingUseCase({ repository, client });
sut = new SettingUseCase(repository, client);
});
describe('#reload', () => {