aboutsummaryrefslogtreecommitdiff
path: root/src/reducers/command.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-09-11 21:07:02 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-09-11 21:07:02 +0900
commitbf890a6d9d793b581a44ee267616ed589f429bef (patch)
tree56f0616eed462d825a5e9006f3994fea588df19a /src/reducers/command.js
parent14d13e2c3abdb090431f59970681cdaf95f0a24a (diff)
command as action/reducer
Diffstat (limited to 'src/reducers/command.js')
-rw-r--r--src/reducers/command.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/reducers/command.js b/src/reducers/command.js
new file mode 100644
index 0000000..7e03593
--- /dev/null
+++ b/src/reducers/command.js
@@ -0,0 +1,24 @@
+import * as tabs from '../background/tabs';
+import actions from '../actions';
+
+const cmdBuffer = (sender, arg) => {
+ if (isNaN(arg)) {
+ return tabs.selectByKeyword(sender.tab, arg);
+ } else {
+ let index = parseInt(arg, 10) - 1;
+ return tabs.selectAt(index);
+ }
+}
+
+export default function reducer(state, action, sender) {
+ switch (action.type) {
+ case actions.COMMAND_OPEN_URL:
+ return browser.tabs.update(sender.tab.id, { url: action.url });
+ case actions.COMMAND_TABOPEN_URL:
+ return browser.tabs.create({ url: action.url });
+ case actions.COMMAND_BUFFER:
+ return cmdBuffer(sender, action.keywords);
+ default:
+ return Promise.resolve();
+ }
+}