Skip to content

Commit

Permalink
moved all cases to the object
Browse files Browse the repository at this point in the history
  • Loading branch information
Yulii Zilnyk committed Jul 18, 2023
1 parent 4f448e5 commit 2336ab9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
* @param {Object[]} actions
*/
function transformState(state, actions) {
const actionTypes = {
addProperties: 'addProperties',
removeProperties: 'removeProperties',
clear: 'clear',
};

for (const action of actions) {
switch (action.type) {
case 'addProperties':
case actionTypes.addProperties:
Object.assign(state, action.extraData);
break;

case 'removeProperties':
case actionTypes.removeProperties:
for (const key of action.keysToRemove) {
delete state[key];
}
break;

case 'clear':
case actionTypes.clear:
for (const key in state) {
delete state[key];
}
Expand Down

0 comments on commit 2336ab9

Please sign in to comment.