diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-10 09:20:54 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-10 11:13:05 +0900 |
commit | 3c67cc0a002aded07e88ea25acc881ff080d1ae4 (patch) | |
tree | ed958c552d1b901d6dd104e73c579bb9c523779d /src/reducers | |
parent | 7e35d11f659029febd738c83b19ab4b8a8b69642 (diff) |
completion as action/reducer
Diffstat (limited to 'src/reducers')
-rw-r--r-- | src/reducers/background.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/reducers/background.js b/src/reducers/background.js new file mode 100644 index 0000000..eccc8ca --- /dev/null +++ b/src/reducers/background.js @@ -0,0 +1,38 @@ +import * as tabs from '../background/tabs'; +import * as consoleActions from '../actions/console'; +import actions from '../actions'; + +const doCompletion = (command, keywords, sendto) => { + if (command === 'buffer') { + return tabs.getCompletions(keywords).then((tabs) => { + let items = tabs.map((tab) => { + return { + caption: tab.title, + content: tab.title, + url: tab.url, + icon: tab.favIconUrl + } + }); + let completions = { + name: "Buffers", + items: items + }; + return browser.tabs.sendMessage( + sendto, + consoleActions.setCompletions([completions])); + }); + } + return Promise.resolve(); +}; + + + +export default function reducer(state, action = {}, sendto) { + // TODO hide sendto object + switch (action.type) { + case actions.BACKGROUND_REQUEST_COMPLETIONS: + return doCompletion(action.command, action.keywords, sendto); + default: + return Promise.resolve(); + } +} |