Skip to content

Commit

Permalink
added new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliiababych committed Oct 3, 2023
1 parent 8355273 commit 69b7bf3
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/transformStateWithClones.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,30 @@ function transformStateWithClones(state, actions) {
let currentState = { ...state };

for (const action of actions) {
switch (true) {
case (action.type === 'addProperties'
&& action.hasOwnProperty('extraData')):
currentState = {
...currentState, ...action.extraData,
};
finalState.push({ ...currentState });
switch (action.type) {
case 'addProperties':
if (action.extraData) {
currentState = {
...currentState, ...action.extraData,
};
finalState.push({ ...currentState });
}
break;

case (action.type === 'removeProperties'
&& action.hasOwnProperty('keysToRemove')):
const newState = { ...currentState };
case 'removeProperties':
if (action.keysToRemove) {
const newState = { ...currentState };

for (const keyToRemove of action.keysToRemove) {
delete newState[keyToRemove];
}
for (const keyToRemove of action.keysToRemove) {
delete newState[keyToRemove];
}

currentState = newState;
finalState.push({ ...currentState });
currentState = newState;
finalState.push({ ...currentState });
}
break;

case (action.type === 'clear'):
case 'clear':
currentState = {};
finalState.push({ ...currentState });
break;
Expand Down

0 comments on commit 69b7bf3

Please sign in to comment.