From 69b7bf3670322a0fd99b185ab1e4ed846733063d Mon Sep 17 00:00:00 2001 From: Yuliia Babych Date: Tue, 3 Oct 2023 19:58:52 +0300 Subject: [PATCH] added new changes --- src/transformStateWithClones.js | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/transformStateWithClones.js b/src/transformStateWithClones.js index d5e93cf06..70353a90d 100644 --- a/src/transformStateWithClones.js +++ b/src/transformStateWithClones.js @@ -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;