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 dae32ad commit b93ed66
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/transformStateWithClones.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
function transformStateWithClones(state, actions) {
const stateHistory = [];
let currentState = {};
let stateAfterAction = {};

for (const action of actions) {
switch (action.type) {
case 'clear':
stateHistory.push({});
stateAfterAction = {};
break;

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

stateHistory.push(Object.assign(currentState, action.extraData));
stateAfterAction = Object.assign(currentState, action.extraData);
break;

case 'removeProperties':
Expand All @@ -28,9 +28,11 @@ function transformStateWithClones(state, actions) {
for (const key of action.keysToRemove) {
delete currentState[key];
}
stateHistory.push(currentState);

stateAfterAction = currentState;
break;
}
stateHistory.push(stateAfterAction);
}

return stateHistory;
Expand Down

0 comments on commit b93ed66

Please sign in to comment.