diff options
Diffstat (limited to 'src/background')
-rw-r--r-- | src/background/components/background.js | 12 | ||||
-rw-r--r-- | src/background/index.js | 6 | ||||
-rw-r--r-- | src/background/reducers/index.js | 12 |
3 files changed, 18 insertions, 12 deletions
diff --git a/src/background/components/background.js b/src/background/components/background.js index 266ad64..a5f4f5f 100644 --- a/src/background/components/background.js +++ b/src/background/components/background.js @@ -7,7 +7,6 @@ import * as commands from 'shared/commands'; export default class BackgroundComponent { constructor(store) { this.store = store; - this.setting = {}; browser.runtime.onMessage.addListener((message, sender) => { try { @@ -21,11 +20,8 @@ export default class BackgroundComponent { }); } - update() { - this.settings = this.store.getState(); - } - onMessage(message, sender) { + let settings = this.store.getState().setting; switch (message.type) { case messages.BACKGROUND_OPERATION: return this.store.dispatch( @@ -43,16 +39,16 @@ export default class BackgroundComponent { type: messages.CONSOLE_HIDE_COMMAND, }); case messages.CONSOLE_ENTERED: - return commands.exec(message.text, this.settings.value).catch((e) => { + return commands.exec(message.text, settings.value).catch((e) => { return browser.tabs.sendMessage(sender.tab.id, { type: messages.CONSOLE_SHOW_ERROR, text: e.message, }); }); case messages.SETTINGS_QUERY: - return Promise.resolve(this.store.getState().value); + return Promise.resolve(this.store.getState().setting.value); case messages.CONSOLE_QUERY_COMPLETIONS: - return commands.complete(message.text, this.settings.value); + return commands.complete(message.text, settings.value); case messages.SETTINGS_RELOAD: this.store.dispatch(settingsActions.load()); return this.broadcastSettingsChanged(); diff --git a/src/background/index.js b/src/background/index.js index 6ba37eb..8a68767 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -1,7 +1,7 @@ import * as settingsActions from 'settings/actions/setting'; import messages from 'shared/messages'; import BackgroundComponent from 'background/components/background'; -import reducers from 'settings/reducers/setting'; +import reducers from 'background/reducers'; import { createStore } from 'shared/store'; const store = createStore(reducers, (e, sender) => { @@ -13,9 +13,7 @@ const store = createStore(reducers, (e, sender) => { }); } }); +// eslint-disable-next-line no-unused-vars const backgroundComponent = new BackgroundComponent(store); -store.subscribe((sender) => { - backgroundComponent.update(sender); -}); store.dispatch(settingsActions.load()); diff --git a/src/background/reducers/index.js b/src/background/reducers/index.js new file mode 100644 index 0000000..4be8fac --- /dev/null +++ b/src/background/reducers/index.js @@ -0,0 +1,12 @@ +import settingReducer from 'settings/reducers/setting'; + +// Make setting reducer instead of re-use +const defaultState = { + setting: settingReducer(undefined, {}), +}; + +export default function reducer(state = defaultState, action = {}) { + return Object.assign({}, state, { + setting: settingReducer(state.setting, action), + }); +} |