From a5427e58529c39d4e7ce190a82dfe83a1c72aba5 Mon Sep 17 00:00:00 2001 From: Zava96 <103376060+Zava96@users.noreply.github.com> Date: Fri, 13 Oct 2023 18:19:53 +0300 Subject: [PATCH] Update transformStateWithClones.js --- src/transformStateWithClones.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/transformStateWithClones.js b/src/transformStateWithClones.js index 59c695fa3..98ebe54ec 100644 --- a/src/transformStateWithClones.js +++ b/src/transformStateWithClones.js @@ -13,26 +13,27 @@ function transformStateWithClones(state, actions) { for (const action of actions) { const { type, extraData, keysToRemove } = action; - let newState = { ...currentState }; - - if (type === 'addProperties') { - for (const key in extraData) { - newState[key] = extraData[key]; - } - } else if (type === 'removeProperties') { - for (const key of keysToRemove) { - delete newState[key]; - } - } else if (type === 'clear') { - newState = {}; + const newState = { ...currentState }; + + switch (type) { + case 'addProperties': + for (const key in extraData) { + newState[key] = extraData[key]; + } + break; + case 'removeProperties': + for (const key of keysToRemove) { + delete newState[key]; + } + break; + case 'clear': + Object.keys(newState).forEach((key) => delete newState[key]); + break; } - result.push(newState); + result.push({ ...newState }); - currentState = newState; } return result; } - -module.exports = transformStateWithClones;