consome as store/reducers

This commit is contained in:
Shin'ya Ueoka 2017-09-14 22:04:42 +09:00
parent 6127fdc285
commit 83cb277ba2
17 changed files with 171 additions and 236 deletions

View file

@ -1,36 +0,0 @@
import * as tabs from '../background/tabs';
import * as consoleActions from '../actions/console';
import actions from '../actions';
const doCompletion = (command, keywords, tabId) => {
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(
tabId,
consoleActions.setCompletions([completions]));
});
}
return Promise.resolve();
};
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, sendToTab.id);
default:
return Promise.resolve();
}
}

View file

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

View file

@ -31,7 +31,6 @@ export default function reducer(state = defaultState, action = {}) {
return Object.assign({}, state, {
errorShown: false,
commandShown: false
});
default:
return state;

View file

@ -1,18 +0,0 @@
import * as consoleFrames from '../console/frames';
import actions from '../actions';
export default function reducer(state, action = {}) {
switch (action.type) {
case actions.CMD_OPEN:
return consoleFrames.showCommand('');
case actions.CMD_TABS_OPEN:
if (action.alter) {
// alter url
return consoleFrames.showCommand('open ' + window.location.href);
} else {
return consoleFrames.showCommand('open ');
}
case actions.CMD_BUFFER:
return consoleFrames.showCommand('buffer ');
}
}

View file

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