aboutsummaryrefslogtreecommitdiff
path: root/src/reducers/command.js
blob: 7e035933e7001ef73229bc7e94592bb034915748 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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();
  }
}