aboutsummaryrefslogtreecommitdiff
path: root/src/content/usecases/FollowMasterUseCase.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/usecases/FollowMasterUseCase.ts')
-rw-r--r--src/content/usecases/FollowMasterUseCase.ts50
1 files changed, 25 insertions, 25 deletions
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);
}