From 6083e70ea089fa2683741a1118be0e4e6b76f858 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 8 Jan 2018 21:54:16 +0900 Subject: separate setting actions and reducers --- src/background/actions/setting.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/background/actions/setting.js (limited to 'src/background/actions/setting.js') diff --git a/src/background/actions/setting.js b/src/background/actions/setting.js new file mode 100644 index 0000000..0454a68 --- /dev/null +++ b/src/background/actions/setting.js @@ -0,0 +1,13 @@ +import actions from '../actions'; +import * as settingsStorage from 'shared/settings/storage'; + +const load = () => { + return settingsStorage.loadValue().then((value) => { + return { + type: actions.SETTING_SET_SETTINGS, + value, + }; + }); +}; + +export { load }; -- cgit v1.2.3 From 22c34a0a6f9721fb9d907ab10de91cbbc40d6bbe Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 10 Jan 2018 21:34:40 +0900 Subject: add set property action in background --- src/background/actions/index.js | 1 + src/background/actions/setting.js | 10 +++++++++- src/background/reducers/setting.js | 9 ++++++++- test/background/reducers/setting.test.js | 18 ++++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) (limited to 'src/background/actions/setting.js') diff --git a/src/background/actions/index.js b/src/background/actions/index.js index 8c212c2..efe4074 100644 --- a/src/background/actions/index.js +++ b/src/background/actions/index.js @@ -1,4 +1,5 @@ export default { // Settings SETTING_SET_SETTINGS: 'setting.set.settings', + SETTING_SET_PROPERTY: 'setting.set.property', }; diff --git a/src/background/actions/setting.js b/src/background/actions/setting.js index 0454a68..773142f 100644 --- a/src/background/actions/setting.js +++ b/src/background/actions/setting.js @@ -10,4 +10,12 @@ const load = () => { }); }; -export { load }; +const setProperty = (name, value) => { + return { + type: actions.SETTING_SET_PROPERTY, + name, + value, + }; +}; + +export { load, setProperty }; diff --git a/src/background/reducers/setting.js b/src/background/reducers/setting.js index 70bf8ea..045a654 100644 --- a/src/background/reducers/setting.js +++ b/src/background/reducers/setting.js @@ -1,4 +1,4 @@ -import actions from 'settings/actions'; +import actions from 'background/actions'; const defaultState = { value: {}, @@ -10,6 +10,13 @@ export default function reducer(state = defaultState, action = {}) { return { value: action.value, }; + case actions.SETTING_SET_PROPERTY: + return { + value: Object.assign({}, state.value, { + properties: Object.assign({}, state.value.properties, + { [action.name]: action.value }) + }) + }; default: return state; } diff --git a/test/background/reducers/setting.test.js b/test/background/reducers/setting.test.js index a6a5573..2ef98cb 100644 --- a/test/background/reducers/setting.test.js +++ b/test/background/reducers/setting.test.js @@ -16,4 +16,22 @@ describe("setting reducer", () => { let state = settingReducer(undefined, action); expect(state).to.have.deep.property('value', { key: 123 }); }); + + it('return next state for SETTING_SET_PROPERTY', () => { + let state = { + value: { + properties: { smoothscroll: true } + } + } + let action = { + type: actions.SETTING_SET_PROPERTY, + name: 'encoding', + value: 'utf-8', + }; + state = settingReducer(state, action); + + console.log(state); + expect(state.value.properties).to.have.property('smoothscroll', true); + expect(state.value.properties).to.have.property('encoding', 'utf-8'); + }); }); -- cgit v1.2.3