Use official redux on content

This commit is contained in:
Shin'ya Ueoka 2018-07-07 22:05:22 +09:00
parent cf0dcf2522
commit efa1cb3967
11 changed files with 36 additions and 103 deletions

View file

@ -1,15 +1,19 @@
import messages from 'shared/messages';
import actions from 'content/actions';
const enable = () => {
return { type: actions.ADDON_ENABLE };
const enable = () => setEnabled(true);
const disable = () => setEnabled(false);
const setEnabled = async(enabled) => {
await browser.runtime.sendMessage({
type: messages.ADDON_ENABLED_RESPONSE,
enabled,
});
return {
type: actions.ADDON_SET_ENABLED,
enabled,
};
};
const disable = () => {
return { type: actions.ADDON_DISABLE };
};
const toggleEnabled = () => {
return { type: actions.ADDON_TOGGLE_ENABLED };
};
export { enable, disable, toggleEnabled };
export { enable, disable, setEnabled };

View file

@ -1,8 +1,6 @@
export default {
// Enable/disable
ADDON_ENABLE: 'addon.enable',
ADDON_DISABLE: 'addon.disable',
ADDON_TOGGLE_ENABLED: 'addon.toggle.enabled',
ADDON_SET_ENABLED: 'addon.set.enabled',
// Settings
SETTING_SET: 'setting.set',

View file

@ -9,7 +9,7 @@ import * as addonActions from './addon';
import * as properties from 'shared/settings/properties';
// eslint-disable-next-line complexity, max-lines-per-function
const exec = (operation, repeat, settings) => {
const exec = (operation, repeat, settings, addonEnabled) => {
let smoothscroll = settings.properties.smoothscroll ||
properties.defaults.smoothscroll;
switch (operation.type) {
@ -18,7 +18,7 @@ const exec = (operation, repeat, settings) => {
case operations.ADDON_DISABLE:
return addonActions.disable();
case operations.ADDON_TOGGLE_ENABLED:
return addonActions.toggleEnabled();
return addonActions.setEnabled(!addonEnabled);
case operations.FIND_NEXT:
window.top.postMessage(JSON.stringify({
type: messages.FIND_NEXT,

View file

@ -34,4 +34,4 @@ const load = async() => {
return set(settings);
};
export { load };
export { set, load };