diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-14 22:04:42 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-16 21:08:18 +0900 |
commit | 83cb277ba2af2bc2f87ace1d97fa582a7043bcd5 (patch) | |
tree | 1ff5eb02fc6b7b12d0a1e825ba1fdb889a1e095b /src/reducers | |
parent | 6127fdc285bc430b48259bd6e90b69623b4e76cc (diff) |
consome as store/reducers
Diffstat (limited to 'src/reducers')
-rw-r--r-- | src/reducers/background.js | 36 | ||||
-rw-r--r-- | src/reducers/command.js | 24 | ||||
-rw-r--r-- | src/reducers/console.js | 1 | ||||
-rw-r--r-- | src/reducers/content.js | 18 | ||||
-rw-r--r-- | src/reducers/index.js | 7 |
5 files changed, 5 insertions, 81 deletions
diff --git a/src/reducers/background.js b/src/reducers/background.js deleted file mode 100644 index ba934fd..0000000 --- a/src/reducers/background.js +++ /dev/null @@ -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(); - } -} diff --git a/src/reducers/command.js b/src/reducers/command.js deleted file mode 100644 index b645e29..0000000 --- a/src/reducers/command.js +++ /dev/null @@ -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(); - } -} diff --git a/src/reducers/console.js b/src/reducers/console.js index 3303802..31de654 100644 --- a/src/reducers/console.js +++ b/src/reducers/console.js @@ -31,7 +31,6 @@ export default function reducer(state = defaultState, action = {}) { return Object.assign({}, state, { errorShown: false, commandShown: false - }); default: return state; diff --git a/src/reducers/content.js b/src/reducers/content.js deleted file mode 100644 index ce59b18..0000000 --- a/src/reducers/content.js +++ /dev/null @@ -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 '); - } -} diff --git a/src/reducers/index.js b/src/reducers/index.js index 6cc1a31..83a9a56 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -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) }); } |