Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
alyonashunevych committed Dec 27, 2024
1 parent b93ed66 commit 6dbac1b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/transformStateWithClones.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ function transformStateWithClones(state, actions) {
let stateAfterAction = {};

for (const action of actions) {
currentState = { ...(stateHistory.at(-1) || { ...state }) };

switch (action.type) {
case 'clear':
stateAfterAction = {};
break;

case 'addProperties':
currentState = { ...(stateHistory.at(-1) || { ...state }) };
stateAfterAction = Object.assign(currentState, action.extraData);
break;

case 'removeProperties':
currentState = { ...(stateHistory.at(-1) || { ...state }) };

for (const key of action.keysToRemove) {
delete currentState[key];
}

stateAfterAction = currentState;
break;
}

stateHistory.push(stateAfterAction);
}

Expand Down

0 comments on commit 6dbac1b

Please sign in to comment.