Skip to content

Commit

Permalink
stateful-object_solution-with-switch
Browse files Browse the repository at this point in the history
  • Loading branch information
olha-rypich committed Jul 15, 2023
1 parent 118cc49 commit 07e6764
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@
*/
function transformState(state, actions) {
for (const action of actions) {
if (action.type === 'addProperties') {
Object.assign(state, action.extraData);
}
switch (action.type) {
case 'addProperties':
Object.assign(state, action.extraData);
break;

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

case 'clear':
for (const key in state) {
delete state[key];
}
break;

if (action.type === 'clear') {
for (const key in state) {
delete state[key];
}
default:
break;
}
}
}
Expand Down

0 comments on commit 07e6764

Please sign in to comment.