Make find as a clean architecture

This commit is contained in:
Shin'ya Ueoka 2019-05-11 11:37:18 +09:00
parent bacf83a320
commit 1ba1660269
15 changed files with 424 additions and 182 deletions

View file

@ -1,13 +1,12 @@
import * as findActions from '../../actions/find';
import * as messages from '../../../shared/messages';
import MessageListener from '../../MessageListener';
import FindUseCase from '../../usecases/FindUseCase';
let findUseCase = new FindUseCase();
export default class FindComponent {
private store: any;
constructor(store: any) {
this.store = store;
constructor() {
new MessageListener().onWebMessage(this.onMessage.bind(this));
}
@ -20,27 +19,18 @@ export default class FindComponent {
case messages.FIND_PREV:
return this.prev();
}
return Promise.resolve();
}
start(text: string) {
let state = this.store.getState().find;
if (text.length === 0) {
return this.store.dispatch(
findActions.next(state.keyword as string, true));
}
return this.store.dispatch(findActions.next(text, true));
return findUseCase.startFind(text.length === 0 ? null : text);
}
next() {
let state = this.store.getState().find;
return this.store.dispatch(
findActions.next(state.keyword as string, false));
return findUseCase.findNext();
}
prev() {
let state = this.store.getState().find;
return this.store.dispatch(
findActions.prev(state.keyword as string, false));
return findUseCase.findPrev();
}
}

View file

@ -17,7 +17,7 @@ export default class TopContent {
new CommonComponent(win, store); // eslint-disable-line no-new
new FollowController(win, store); // eslint-disable-line no-new
new FindComponent(store); // eslint-disable-line no-new
new FindComponent(); // eslint-disable-line no-new
// TODO make component
consoleFrames.initialize(this.win.document);