use input as store/reducer

This commit is contained in:
Shin'ya Ueoka 2017-09-14 21:40:28 +09:00
parent c42ac8fac4
commit 6127fdc285
5 changed files with 44 additions and 37 deletions

View file

@ -2,7 +2,7 @@ import * as tabs from '../background/tabs';
import * as consoleActions from '../actions/console';
import actions from '../actions';
const doCompletion = (command, keywords, sender) => {
const doCompletion = (command, keywords, tabId) => {
if (command === 'buffer') {
return tabs.getCompletions(keywords).then((tabs) => {
let items = tabs.map((tab) => {
@ -18,18 +18,18 @@ const doCompletion = (command, keywords, sender) => {
items: items
};
return browser.tabs.sendMessage(
sender,
tabId,
consoleActions.setCompletions([completions]));
});
}
return Promise.resolve();
};
export default function reducer(state, action = {}, sender) {
export default function reducer(state, action = {}, sendToTab) {
// TODO hide sender object
switch (action.type) {
case actions.BACKGROUND_REQUEST_COMPLETIONS:
return doCompletion(action.command, action.keywords, sender.tab.id);
return doCompletion(action.command, action.keywords, sendToTab.id);
default:
return Promise.resolve();
}

View file

@ -1,23 +1,23 @@
import * as tabs from '../background/tabs';
import actions from '../actions';
const cmdBuffer = (sender, arg) => {
const cmdBuffer = (tab, arg) => {
if (isNaN(arg)) {
return tabs.selectByKeyword(sender.tab, arg);
return tabs.selectByKeyword(tab, arg);
} else {
let index = parseInt(arg, 10) - 1;
return tabs.selectAt(index);
}
}
export default function reducer(state, action, sender) {
export default function reducer(state, action, sendToTab) {
switch (action.type) {
case actions.COMMAND_OPEN_URL:
return browser.tabs.update(sender.tab.id, { url: action.url });
return browser.tabs.update(sendToTab.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);
return cmdBuffer(sendToTab, action.keywords);
default:
return Promise.resolve();
}

View file

@ -1,7 +1,11 @@
import inputReducer from '../reducers/input';
const defaultState = {
input: inputReducer(undefined, {})
};
export default function reducer(state = defaultState/*, action = {}*/) {
export default function reducer(state = defaultState, action = {}) {
return Object.assign({}, state, {
input: inputReducer(state.input, action)
});
}