aboutsummaryrefslogtreecommitdiff
path: root/src/background/shared/completions/index.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-06-17 20:21:39 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-06-17 21:55:25 +0900
commit48e4bccf0d24bb6ce53c4ecea567ed7750fe8949 (patch)
tree7c16a68489f2894564da18ae059ba492db88907a /src/background/shared/completions/index.js
parent88238005ab64f957d9def8c18473d8210b280de9 (diff)
Use async/await on background
Diffstat (limited to 'src/background/shared/completions/index.js')
-rw-r--r--src/background/shared/completions/index.js116
1 files changed, 53 insertions, 63 deletions
diff --git a/src/background/shared/completions/index.js b/src/background/shared/completions/index.js
index 728cee7..d5875fe 100644
--- a/src/background/shared/completions/index.js
+++ b/src/background/shared/completions/index.js
@@ -12,76 +12,66 @@ const getSearchCompletions = (command, keywords, searchConfig) => {
return Promise.resolve(engineItems);
};
-const getHistoryCompletions = (command, keywords) => {
- return histories.getCompletions(keywords).then((pages) => {
- return pages.map((page) => {
- return {
- caption: page.title,
- content: command + ' ' + page.url,
- url: page.url
- };
- });
+const getHistoryCompletions = async(command, keywords) => {
+ let items = await histories.getCompletions(keywords);
+ return items.map((page) => {
+ return {
+ caption: page.title,
+ content: command + ' ' + page.url,
+ url: page.url
+ };
});
};
-const getBookmarksCompletions = (command, keywords) => {
- return bookmarks.getCompletions(keywords).then((items) => {
- return items.map((item) => {
- return {
- caption: item.title,
- content: command + ' ' + item.url,
- url: item.url,
- };
- });
- });
+const getBookmarksCompletions = async(command, keywords) => {
+ let items = await bookmarks.getCompletions(keywords);
+ return items.map(item => ({
+ caption: item.title,
+ content: command + ' ' + item.url,
+ url: item.url,
+ }));
};
-const getOpenCompletions = (command, keywords, searchConfig) => {
- return Promise.all([
- getSearchCompletions(command, keywords, searchConfig),
- getHistoryCompletions(command, keywords),
- getBookmarksCompletions(command, keywords),
- ]).then(([engineItems, historyItems, bookmarkItems]) => {
- let completions = [];
- if (engineItems.length > 0) {
- completions.push({
- name: 'Search Engines',
- items: engineItems
- });
- }
- if (historyItems.length > 0) {
- completions.push({
- name: 'History',
- items: historyItems
- });
- }
- if (bookmarkItems.length > 0) {
- completions.push({
- name: 'Bookmarks',
- items: bookmarkItems
- });
- }
- return completions;
- });
+const getOpenCompletions = async(command, keywords, searchConfig) => {
+ let engineItems = await getSearchCompletions(command, keywords, searchConfig);
+ let historyItems = await getHistoryCompletions(command, keywords);
+ let bookmarkItems = await getBookmarksCompletions(command, keywords);
+ let completions = [];
+ if (engineItems.length > 0) {
+ completions.push({
+ name: 'Search Engines',
+ items: engineItems
+ });
+ }
+ if (historyItems.length > 0) {
+ completions.push({
+ name: 'History',
+ items: historyItems
+ });
+ }
+ if (bookmarkItems.length > 0) {
+ completions.push({
+ name: 'Bookmarks',
+ items: bookmarkItems
+ });
+ }
+ return completions;
};
-const getBufferCompletions = (command, keywords, excludePinned) => {
- return tabs.getCompletions(keywords, excludePinned).then((got) => {
- let items = got.map((tab) => {
- return {
- caption: tab.title,
- content: command + ' ' + tab.title,
- url: tab.url,
- icon: tab.favIconUrl
- };
- });
- return [
- {
- name: 'Buffers',
- items: items
- }
- ];
- });
+const getBufferCompletions = async(command, keywords, excludePinned) => {
+ let items = await tabs.getCompletions(keywords, excludePinned);
+ items = items.map(tab => ({
+ caption: tab.title,
+ content: command + ' ' + tab.title,
+ url: tab.url,
+ icon: tab.favIconUrl
+ }));
+ return [
+ {
+ name: 'Buffers',
+ items: items
+ }
+ ];
};
const getCompletions = (line, settings) => {