From bf7c125fb214b52d67527bdd292a4b5bb81b1d32 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 20 Jul 2018 23:36:03 +0900 Subject: My First Clean Architecture --- src/background/usecases/completions.js | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/background/usecases/completions.js (limited to 'src/background/usecases/completions.js') diff --git a/src/background/usecases/completions.js b/src/background/usecases/completions.js new file mode 100644 index 0000000..fc1ff52 --- /dev/null +++ b/src/background/usecases/completions.js @@ -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)]; + } +} -- cgit v1.2.3