Skip to content

Commit

Permalink
switch statement
Browse files Browse the repository at this point in the history
  • Loading branch information
Patryk-Buczkowski committed Aug 1, 2023
1 parent b68e9c7 commit 18e66b7
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,28 @@
* @param {Object[]} actions
*/
function transformState(state, actions) {
actions.forEach((obj) => {
const ADD_PROPERTIES = obj.type === 'addProperties';
const REMOVE_PROERTIES = obj.type === 'removeProperties';
const CLEAR_ALL = obj.type === 'clear';
for (const action of actions) {
switch (action.type) {
case ('addProperties') :
Object.assign(state, action.extraData);

if (ADD_PROPERTIES) {
Object.assign(state, obj.extraData);
}
break;

if (REMOVE_PROERTIES) {
for (const i of obj.keysToRemove) {
delete state[i];
}
}
case `removeProperties`:
for (const i of action.keysToRemove) {
delete state[i];
}

if (CLEAR_ALL) {
for (const i in state) {
delete state[i];
}
}
});
break;

// return state; <-- works without it and
// works when in uncommented, it's redundant?
case `clear`:
for (const i in state) {
delete state[i];
}

break;
}
};
}

module.exports = transformState;

0 comments on commit 18e66b7

Please sign in to comment.