parent
efc48dc742
commit
2ec912c262
8 changed files with 200 additions and 7 deletions
@ -0,0 +1,19 @@ |
||||
import * as messages from '../../shared/messages'; |
||||
import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase'; |
||||
|
||||
export default class AddonEnabledController { |
||||
private addonEnabledUseCase: AddonEnabledUseCase; |
||||
|
||||
constructor({ |
||||
addonEnabledUseCase = new AddonEnabledUseCase(), |
||||
} = {}) { |
||||
this.addonEnabledUseCase = addonEnabledUseCase; |
||||
} |
||||
|
||||
getAddonEnabled( |
||||
_message: messages.AddonEnabledQueryMessage, |
||||
): Promise<boolean> { |
||||
let enabled = this.addonEnabledUseCase.getEnabled(); |
||||
return Promise.resolve(enabled); |
||||
} |
||||
} |
@ -0,0 +1,16 @@ |
||||
import * as messages from '../../shared/messages'; |
||||
import MarkUseCase from '../usecases/MarkUseCase'; |
||||
|
||||
export default class MarkController { |
||||
private markUseCase: MarkUseCase; |
||||
|
||||
constructor({ |
||||
markUseCase = new MarkUseCase(), |
||||
} = {}) { |
||||
this.markUseCase = markUseCase; |
||||
} |
||||
|
||||
scrollTo(message: messages.TabScrollToMessage) { |
||||
this.markUseCase.scroll(message.x, message.y); |
||||
} |
||||
} |
@ -0,0 +1,31 @@ |
||||
import MarkUseCase from '../usecases/MarkUseCase'; |
||||
import MarkKeyyUseCase from '../usecases/MarkKeyUseCase'; |
||||
import * as keys from '../../shared/utils/keys'; |
||||
|
||||
export default class MarkKeyController { |
||||
private markUseCase: MarkUseCase; |
||||
|
||||
private markKeyUseCase: MarkKeyyUseCase; |
||||
|
||||
constructor({ |
||||
markUseCase = new MarkUseCase(), |
||||
markKeyUseCase = new MarkKeyyUseCase(), |
||||
} = {}) { |
||||
this.markUseCase = markUseCase; |
||||
this.markKeyUseCase = markKeyUseCase; |
||||
} |
||||
|
||||
press(key: keys.Key): boolean { |
||||
if (this.markKeyUseCase.isSetMode()) { |
||||
this.markUseCase.set(key.key); |
||||
this.markKeyUseCase.disableSetMode(); |
||||
return true; |
||||
} |
||||
if (this.markKeyUseCase.isJumpMode()) { |
||||
this.markUseCase.jump(key.key); |
||||
this.markKeyUseCase.disableJumpMode(); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
} |
@ -0,0 +1,52 @@ |
||||
export default interface MarkKeyRepository { |
||||
isSetMode(): boolean; |
||||
|
||||
enableSetMode(): void; |
||||
|
||||
disabeSetMode(): void; |
||||
|
||||
isJumpMode(): boolean; |
||||
|
||||
enableJumpMode(): void; |
||||
|
||||
disabeJumpMode(): void; |
||||
|
||||
// eslint-disable-next-line semi
|
||||
} |
||||
|
||||
interface Mode { |
||||
setMode: boolean; |
||||
jumpMode: boolean; |
||||
} |
||||
|
||||
let current: Mode = { |
||||
setMode: false, |
||||
jumpMode: false, |
||||
}; |
||||
|
||||
export class MarkKeyRepositoryImpl implements MarkKeyRepository { |
||||
|
||||
isSetMode(): boolean { |
||||
return current.setMode; |
||||
} |
||||
|
||||
enableSetMode(): void { |
||||
current.setMode = true; |
||||
} |
||||
|
||||
disabeSetMode(): void { |
||||
current.setMode = false; |
||||
} |
||||
|
||||
isJumpMode(): boolean { |
||||
return current.jumpMode; |
||||
} |
||||
|
||||
enableJumpMode(): void { |
||||
current.jumpMode = true; |
||||
} |
||||
|
||||
disabeJumpMode(): void { |
||||
current.jumpMode = false; |
||||
} |
||||
} |
@ -0,0 +1,36 @@ |
||||
import MarkKeyRepository, { MarkKeyRepositoryImpl } |
||||
from '../repositories/MarkKeyRepository'; |
||||
|
||||
export default class MarkKeyUseCase { |
||||
private repository: MarkKeyRepository; |
||||
|
||||
constructor({ |
||||
repository = new MarkKeyRepositoryImpl() |
||||
} = {}) { |
||||
this.repository = repository; |
||||
} |
||||
|
||||
isSetMode(): boolean { |
||||
return this.repository.isSetMode(); |
||||
} |
||||
|
||||
isJumpMode(): boolean { |
||||
return this.repository.isJumpMode(); |
||||
} |
||||
|
||||
enableSetMode(): void { |
||||
this.repository.enableSetMode(); |
||||
} |
||||
|
||||
disableSetMode(): void { |
||||
this.repository.disabeSetMode(); |
||||
} |
||||
|
||||
enableJumpMode(): void { |
||||
this.repository.enableJumpMode(); |
||||
} |
||||
|
||||
disableJumpMode(): void { |
||||
this.repository.disabeJumpMode(); |
||||
} |
||||
} |
Reference in new issue