Skip to content

Commit

Permalink
Solutin2
Browse files Browse the repository at this point in the history
  • Loading branch information
SichVictor committed Jul 16, 2023
1 parent 18ad47e commit f291f99
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@
* @param {Object} state
* @param {Object[]} actions
*/
const actionTypes = {
addProperties: 'addProperties',
removeProperties: 'removeProperties',
clear: 'clear',
};

function transformState(state, actions) {
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 f291f99

Please sign in to comment.