aboutsummaryrefslogtreecommitdiff
path: root/src/background/usecases/completions.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-07-20 23:36:03 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-07-21 16:15:07 +0900
commitbf7c125fb214b52d67527bdd292a4b5bb81b1d32 (patch)
treea491d7b17a6cee685f134c019a0d624d32e13a3a /src/background/usecases/completions.js
parent4d4aaa2c4ba9f09e23882287ce868c820aa900ee (diff)
My First Clean Architecture
Diffstat (limited to 'src/background/usecases/completions.js')
-rw-r--r--src/background/usecases/completions.js40
1 files changed, 40 insertions, 0 deletions
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)];
+ }
+}