parent
ad1f3c07fb
commit
fcd15f4f09
9 changed files with 78 additions and 75 deletions
@ -1,36 +0,0 @@ |
||||
import * as messages from '../../../shared/messages'; |
||||
import MessageListener from '../../MessageListener'; |
||||
|
||||
import FindUseCase from '../../usecases/FindUseCase'; |
||||
|
||||
let findUseCase = new FindUseCase(); |
||||
|
||||
export default class FindComponent { |
||||
constructor() { |
||||
new MessageListener().onWebMessage(this.onMessage.bind(this)); |
||||
} |
||||
|
||||
onMessage(message: messages.Message) { |
||||
switch (message.type) { |
||||
case messages.CONSOLE_ENTER_FIND: |
||||
return this.start(message.text); |
||||
case messages.FIND_NEXT: |
||||
return this.next(); |
||||
case messages.FIND_PREV: |
||||
return this.prev(); |
||||
} |
||||
return Promise.resolve(); |
||||
} |
||||
|
||||
start(text: string) { |
||||
return findUseCase.startFind(text.length === 0 ? null : text); |
||||
} |
||||
|
||||
next() { |
||||
return findUseCase.findNext(); |
||||
} |
||||
|
||||
prev() { |
||||
return findUseCase.findPrev(); |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
import * as messages from '../../shared/messages'; |
||||
import FindUseCase from '../usecases/FindUseCase'; |
||||
|
||||
export default class FindController { |
||||
private findUseCase: FindUseCase; |
||||
|
||||
constructor({ |
||||
findUseCase = new FindUseCase(), |
||||
} = {}) { |
||||
this.findUseCase = findUseCase; |
||||
} |
||||
|
||||
async start(m: messages.ConsoleEnterFindMessage): Promise<void> { |
||||
await this.findUseCase.startFind(m.text); |
||||
} |
||||
|
||||
async next(_: messages.FindNextMessage): Promise<void> { |
||||
await this.findUseCase.findNext(); |
||||
} |
||||
|
||||
async prev(_: messages.FindPrevMessage): Promise<void> { |
||||
await this.findUseCase.findPrev(); |
||||
} |
||||
} |
Reference in new issue