Skip to content

Commit

Permalink
add solution
Browse files Browse the repository at this point in the history
  • Loading branch information
KatOlista committed Jul 30, 2023
1 parent a50f640 commit fba0459
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,34 @@
*/
function transformState(state, actions) {
for (let i = 0; i < actions.length; i++) {
if (actions[i].type === 'addProperties') {
Object.assign(state, actions[i].extraData);
switch (actions[i].type) {
case 'addProperties':
Object.assign(state, actions[i].extraData);
break;
case 'removeProperties':
for (const action of actions[i].keysToRemove) {
delete state[action];
};
break;
case 'clear':
Object.keys(state).forEach(key => delete state[key]);
break;
default:
return state;
}
// if (actions[i].type === 'addProperties') {
// Object.assign(state, actions[i].extraData);
// }

if (actions[i].type === 'removeProperties') {
for (const item of actions[i].keysToRemove) {
delete state[item];
}
}
// if (actions[i].type === 'removeProperties') {
// for (const action of actions[i].keysToRemove) {
// delete state[action];
// }
// }

if (actions[i].type === 'clear') {
Object.keys(state).forEach(key => delete state[key]);
}
// if (actions[i].type === 'clear') {
// Object.keys(state).forEach(key => delete state[key]);
// }
}
}

Expand Down

0 comments on commit fba0459

Please sign in to comment.