Find as clean architecture
This commit is contained in:
parent
89c28d67fd
commit
a1e5e97200
5 changed files with 62 additions and 7 deletions
|
@ -1,6 +1,5 @@
|
|||
import messages from 'shared/messages';
|
||||
import * as commandActions from 'background/actions/command';
|
||||
import * as findActions from 'background/actions/find';
|
||||
import * as tabActions from 'background/actions/tab';
|
||||
|
||||
export default class BackgroundComponent {
|
||||
|
@ -21,7 +20,6 @@ export default class BackgroundComponent {
|
|||
|
||||
onMessage(message, sender) {
|
||||
let settings = this.store.getState().setting;
|
||||
let find = this.store.getState().find;
|
||||
|
||||
switch (message.type) {
|
||||
case messages.OPEN_URL:
|
||||
|
@ -37,11 +35,6 @@ export default class BackgroundComponent {
|
|||
commandActions.exec(sender.tab, message.text, settings.value),
|
||||
);
|
||||
return this.broadcastSettingsChanged();
|
||||
case messages.FIND_GET_KEYWORD:
|
||||
return Promise.resolve(find.keyword);
|
||||
case messages.FIND_SET_KEYWORD:
|
||||
this.store.dispatch(findActions.setKeyword(message.keyword));
|
||||
return Promise.resolve({});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
15
src/background/controllers/find.js
Normal file
15
src/background/controllers/find.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import FindInteractor from '../usecases/find';
|
||||
|
||||
export default class FindController {
|
||||
constructor() {
|
||||
this.findInteractor = new FindInteractor();
|
||||
}
|
||||
|
||||
getKeyword() {
|
||||
return this.findInteractor.getKeyword();
|
||||
}
|
||||
|
||||
setKeyword(keyword) {
|
||||
return this.findInteractor.setKeyword(keyword);
|
||||
}
|
||||
}
|
|
@ -1,11 +1,13 @@
|
|||
import messages from '../../shared/messages';
|
||||
import CompletionsController from '../controllers/completions';
|
||||
import SettingController from '../controllers/setting';
|
||||
import FindController from '../controllers/find';
|
||||
|
||||
export default class ContentMessageListener {
|
||||
constructor() {
|
||||
this.settingController = new SettingController();
|
||||
this.completionsController = new CompletionsController();
|
||||
this.findController = new FindController();
|
||||
}
|
||||
|
||||
run() {
|
||||
|
@ -29,6 +31,10 @@ export default class ContentMessageListener {
|
|||
return this.onSettingsQuery();
|
||||
case messages.SETTINGS_RELOAD:
|
||||
return this.onSettingsReload();
|
||||
case messages.FIND_GET_KEYWORD:
|
||||
return this.onFindGetKeyword();
|
||||
case messages.FIND_SET_KEYWORD:
|
||||
return this.onFindSetKeyword(message.keyword);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,4 +50,12 @@ export default class ContentMessageListener {
|
|||
onSettingsReload() {
|
||||
return this.settingController.reload();
|
||||
}
|
||||
|
||||
onFindGetKeyword() {
|
||||
return this.findController.getKeyword();
|
||||
}
|
||||
|
||||
onFindSetKeyword(keyword) {
|
||||
return this.findController.setKeyword(keyword);
|
||||
}
|
||||
}
|
||||
|
|
18
src/background/repositories/find.js
Normal file
18
src/background/repositories/find.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
import MemoryStorage from '../infrastructures/memory-storage';
|
||||
|
||||
const FIND_KEYWORD_KEY = 'find-keyword';
|
||||
|
||||
export default class FindRepository {
|
||||
constructor() {
|
||||
this.cache = new MemoryStorage();
|
||||
}
|
||||
|
||||
getKeyword() {
|
||||
return Promise.resolve(this.cache.get(FIND_KEYWORD_KEY));
|
||||
}
|
||||
|
||||
setKeyword(keyword) {
|
||||
return this.cache.set(FIND_KEYWORD_KEY, keyword);
|
||||
}
|
||||
}
|
||||
|
15
src/background/usecases/find.js
Normal file
15
src/background/usecases/find.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import FindRepository from '../repositories/find';
|
||||
|
||||
export default class FindInteractor {
|
||||
constructor() {
|
||||
this.findRepository = new FindRepository();
|
||||
}
|
||||
|
||||
getKeyword() {
|
||||
return this.findRepository.getKeyword();
|
||||
}
|
||||
|
||||
setKeyword(keyword) {
|
||||
return this.findRepository.setKeyword(keyword);
|
||||
}
|
||||
}
|
Reference in a new issue