add set property action in background
This commit is contained in:
parent
6083e70ea0
commit
22c34a0a6f
4 changed files with 36 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
||||||
export default {
|
export default {
|
||||||
// Settings
|
// Settings
|
||||||
SETTING_SET_SETTINGS: 'setting.set.settings',
|
SETTING_SET_SETTINGS: 'setting.set.settings',
|
||||||
|
SETTING_SET_PROPERTY: 'setting.set.property',
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,4 +10,12 @@ const load = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export { load };
|
const setProperty = (name, value) => {
|
||||||
|
return {
|
||||||
|
type: actions.SETTING_SET_PROPERTY,
|
||||||
|
name,
|
||||||
|
value,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export { load, setProperty };
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import actions from 'settings/actions';
|
import actions from 'background/actions';
|
||||||
|
|
||||||
const defaultState = {
|
const defaultState = {
|
||||||
value: {},
|
value: {},
|
||||||
|
@ -10,6 +10,13 @@ export default function reducer(state = defaultState, action = {}) {
|
||||||
return {
|
return {
|
||||||
value: action.value,
|
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:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,4 +16,22 @@ describe("setting reducer", () => {
|
||||||
let state = settingReducer(undefined, action);
|
let state = settingReducer(undefined, action);
|
||||||
expect(state).to.have.deep.property('value', { key: 123 });
|
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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue