Skip to content

Commit

Permalink
Update transformStateWithClones.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Zava96 authored Oct 13, 2023
1 parent bad5cb4 commit a5427e5
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/transformStateWithClones.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit a5427e5

Please sign in to comment.