From 6dbac1b7efbd6ef6191636a99085928e29df626a Mon Sep 17 00:00:00 2001 From: Alyona Shunevych Date: Fri, 27 Dec 2024 18:52:08 +0200 Subject: [PATCH] Solution --- src/transformStateWithClones.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/transformStateWithClones.js b/src/transformStateWithClones.js index 65f9b43e1..33c077cac 100644 --- a/src/transformStateWithClones.js +++ b/src/transformStateWithClones.js @@ -12,19 +12,18 @@ 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]; } @@ -32,6 +31,7 @@ function transformStateWithClones(state, actions) { stateAfterAction = currentState; break; } + stateHistory.push(stateAfterAction); }