Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
oksom committed Jul 13, 2023
1 parent 7878c5e commit b2073fc
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,32 @@
*/
function transformState(state, actions) {
actions.forEach(action => {
if (action.type === 'addProperties') {
Object.assign(state, action.extraData);
} else if (action.type === 'removeProperties') {
const removeKeys = action.keysToRemove.values();
switch (action.type) {
case 'addProperties':
Object.assign(state, action.extraData);

for (const key of removeKeys) {
if (state.hasOwnProperty(key)) {
break;

case 'removeProperties':
const removeKeys = action.keysToRemove.values();

for (const key of removeKeys) {
if (state.hasOwnProperty(key)) {
delete state[key];
}
}

break;

case 'clear':
for (const key in state) {
delete state[key];
}
}
} else if (action.type === 'clear') {
for (const key in state) {
delete state[key];
}

break;

default:
return state;
}
});

Expand Down

0 comments on commit b2073fc

Please sign in to comment.