diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-10-07 12:21:09 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-07 12:21:09 +0900 |
commit | d995ab0030522f380d165f309ffc72b582366ddb (patch) | |
tree | 69a096e9a8610ae8966af05e91355efdd27ea811 /src/content | |
parent | 482206f6c90985011b197623854b8bfbc26ee54c (diff) | |
parent | 9fb7bf96be786acfbad97f7c76bc423a401dd657 (diff) |
Merge pull request #19 from ueokande/content-and-background-redux-completely
Refactor: full redux on content and background
Diffstat (limited to 'src/content')
-rw-r--r-- | src/content/index.js | 37 | ||||
-rw-r--r-- | src/content/messages.js | 6 |
2 files changed, 20 insertions, 23 deletions
diff --git a/src/content/index.js b/src/content/index.js index 655bea4..b29118d 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -1,18 +1,18 @@ import './console-frame.scss'; import * as consoleFrames from './console-frames'; -import * as scrolls from '../content/scrolls'; -import * as navigates from '../content/navigates'; -import * as followActions from '../actions/follow'; -import * as store from '../store'; -import ContentInputComponent from '../components/content-input'; -import FollowComponent from '../components/follow'; -import followReducer from '../reducers/follow'; -import operations from '../operations'; +import * as scrolls from 'content/scrolls'; +import * as navigates from 'content/navigates'; +import * as followActions from 'actions/follow'; +import { createStore } from 'store'; +import ContentInputComponent from 'components/content-input'; +import FollowComponent from 'components/follow'; +import reducers from 'reducers'; +import operations from 'shared/operations'; import messages from './messages'; -const followStore = store.createStore(followReducer); -const followComponent = new FollowComponent(window.document.body, followStore); -followStore.subscribe(() => { +const store = createStore(reducers); +const followComponent = new FollowComponent(window.document.body, store); +store.subscribe(() => { try { followComponent.update(); } catch (e) { @@ -39,7 +39,7 @@ const execOperation = (operation) => { case operations.SCROLL_END: return scrolls.scrollRight(window); case operations.FOLLOW_START: - return followStore.dispatch(followActions.enable(false)); + return store.dispatch(followActions.enable(false)); case operations.NAVIGATE_HISTORY_PREV: return navigates.historyPrev(window); case operations.NAVIGATE_HISTORY_NEXT: @@ -55,17 +55,12 @@ const execOperation = (operation) => { } }; -const update = (state) => { - if (!state.console.commandShown) { - window.focus(); - consoleFrames.blur(window.document); - } -}; - browser.runtime.onMessage.addListener((action) => { switch (action.type) { - case messages.STATE_UPDATE: - return update(action.state); + case messages.CONSOLE_HIDE: + window.focus(); + consoleFrames.blur(window.document); + return Promise.resolve(); case messages.CONTENT_OPERATION: execOperation(action.operation); return Promise.resolve(); diff --git a/src/content/messages.js b/src/content/messages.js index df9fba2..0e66fa0 100644 --- a/src/content/messages.js +++ b/src/content/messages.js @@ -1,10 +1,12 @@ export default { - STATE_UPDATE: 'state.update', CONTENT_OPERATION: 'content.operation', CONSOLE_BLURRED: 'console.blured', CONSOLE_ENTERED: 'console.entered', - CONSOLE_CHANGEED: 'console.changed', + CONSOLE_QUERY_COMPLETIONS: 'console.query.completions', + CONSOLE_SHOW_COMMAND: 'console.show.command', + CONSOLE_SHOW_ERROR: 'console.show.error', + CONSOLE_HIDE: 'console.hide', KEYDOWN: 'keydown', |