My First Clean Architecture
This commit is contained in:
parent
4d4aaa2c4b
commit
bf7c125fb2
8 changed files with 185 additions and 3 deletions
40
src/background/usecases/completions.js
Normal file
40
src/background/usecases/completions.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
import CompletionItem from '../domains/completion-item';
|
||||
import CompletionGroup from '../domains/completion-group';
|
||||
import Completions from '../domains/completions';
|
||||
import CompletionRepository from '../repositories/completions';
|
||||
import CommandDocs from 'background/shared/commands/docs';
|
||||
|
||||
export default class CompletionsInteractor {
|
||||
constructor() {
|
||||
this.completionRepository = new CompletionRepository();
|
||||
}
|
||||
|
||||
queryConsoleCommand(prefix) {
|
||||
let keys = Object.keys(CommandDocs);
|
||||
let items = keys
|
||||
.filter(name => name.startsWith(prefix))
|
||||
.map(name => ({
|
||||
caption: name,
|
||||
content: name,
|
||||
url: CommandDocs[name],
|
||||
}));
|
||||
|
||||
if (items.length === 0) {
|
||||
return Promise.resolve(Completions.empty());
|
||||
}
|
||||
return Promise.resolve(new Completions(
|
||||
[new CompletionGroup('Console Command', items)]
|
||||
));
|
||||
}
|
||||
|
||||
async queryBdeleteCommand(name, force, args) {
|
||||
let tabs = await this.completionRepository.queryTabs(args);
|
||||
let items = tabs.map(tab => new CompletionItem({
|
||||
caption: tab.title,
|
||||
content: name + ' ' + tab.title,
|
||||
url: tab.url,
|
||||
icon: tab.favIconUrl
|
||||
}));
|
||||
return [new CompletionGroup('Buffers', items)];
|
||||
}
|
||||
}
|
Reference in a new issue