diff options
Diffstat (limited to 'src/reducers')
-rw-r--r-- | src/reducers/background.js | 53 | ||||
-rw-r--r-- | src/reducers/command.js | 24 | ||||
-rw-r--r-- | src/reducers/console.js | 5 | ||||
-rw-r--r-- | src/reducers/content.js | 48 | ||||
-rw-r--r-- | src/reducers/index.js | 14 |
5 files changed, 18 insertions, 126 deletions
diff --git a/src/reducers/background.js b/src/reducers/background.js deleted file mode 100644 index d7d7860..0000000 --- a/src/reducers/background.js +++ /dev/null @@ -1,53 +0,0 @@ -import * as tabs from '../background/tabs'; -import * as zooms from '../background/zooms'; -import * as consoleActions from '../actions/console'; -import actions from '../actions'; - -const doCompletion = (command, keywords, sender) => { - 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( - sender, - consoleActions.setCompletions([completions])); - }); - } - return Promise.resolve(); -}; - -export default function reducer(state, action = {}, sender) { - // TODO hide sender object - switch (action.type) { - case actions.BACKGROUND_REQUEST_COMPLETIONS: - return doCompletion(action.command, action.keywords, sender.tab.id); - case actions.TABS_CLOSE: - return tabs.closeTab(sender.tab.id); - case actions.TABS_REOPEN: - return tabs.reopenTab(); - case actions.TABS_PREV: - return tabs.selectPrevTab(sender.tab.index, action.count); - case actions.TABS_NEXT: - return tabs.selectNextTab(sender.tab.index, action.count); - case actions.TABS_RELOAD: - return tabs.reload(sender.tab, action.cache); - case actions.ZOOM_IN: - return zooms.zoomIn(); - case actions.ZOOM_OUT: - return zooms.zoomOut(); - case actions.ZOOM_NEUTRAL: - return zooms.neutral(); - default: - return Promise.resolve(); - } -} diff --git a/src/reducers/command.js b/src/reducers/command.js deleted file mode 100644 index 7e03593..0000000 --- a/src/reducers/command.js +++ /dev/null @@ -1,24 +0,0 @@ -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(); - } -} diff --git a/src/reducers/console.js b/src/reducers/console.js index 3303802..27ccdc9 100644 --- a/src/reducers/console.js +++ b/src/reducers/console.js @@ -28,10 +28,13 @@ export default function reducer(state = defaultState, action = {}) { commandShown: false, }); case actions.CONSOLE_HIDE: + if (state.errorShown) { + // keep error message if shown + return state; + } 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 bcf1160..0000000 --- a/src/reducers/content.js +++ /dev/null @@ -1,48 +0,0 @@ -import * as consoleFrames from '../console/frames'; -import * as histories from '../content/histories'; -import * as scrolls from '../content/scrolls'; -import Follow from '../content/follow'; -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 '); - case actions.SCROLL_LINES: - scrolls.scrollLines(window, action.count); - break; - case actions.SCROLL_PAGES: - scrolls.scrollPages(window, action.count); - break; - case actions.SCROLL_TOP: - scrolls.scrollTop(window); - break; - case actions.SCROLL_BOTTOM: - scrolls.scrollBottom(window); - break; - case actions.SCROLL_LEFT: - scrolls.scrollLeft(window); - break; - case actions.SCROLL_RIGHT: - scrolls.scrollRight(window); - break; - case actions.FOLLOW_START: - new Follow(window.document, action.newTab); - break; - case actions.HISTORY_PREV: - histories.prev(window); - break; - case actions.HISTORY_NEXT: - histories.next(window); - break; - } -} diff --git a/src/reducers/index.js b/src/reducers/index.js new file mode 100644 index 0000000..83a9a56 --- /dev/null +++ b/src/reducers/index.js @@ -0,0 +1,14 @@ +import inputReducer from '../reducers/input'; +import consoleReducer from '../reducers/console'; + +const defaultState = { + input: inputReducer(undefined, {}), + console: consoleReducer(undefined, {}) +}; + +export default function reducer(state = defaultState, action = {}) { + return Object.assign({}, state, { + input: inputReducer(state.input, action), + console: consoleReducer(state.console, action) + }); +} |