Skip to content

Commit

Permalink
fix: my horrible logics mistake, somehow thought we could also receiv…
Browse files Browse the repository at this point in the history
…e a single object as `action` not onlu an array
  • Loading branch information
kkrasnoshchok committed Jan 10, 2024
1 parent 058c958 commit 861f800
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,25 @@
* @param {Object[]} actions
*/
function transformState(state, actions) {
if (Array.isArray(actions)) {
for (const action of actions) {
actionsObserver(state, action);
for (const action of actions) {
switch (action.type) {
case 'addProperties':
Object.assign(state, action.extraData);
break;
case 'removeProperties':
for (const key of action.keysToRemove) {
delete state[key];
}
break;
case 'clear':
for (const key in state) {
delete state[key];
}
break;
default:
break;
}

return;
}
actionsObserver(state, actions);
}

module.exports = transformState;

const actionsObserver = (state, action) => {
switch (action.type) {
case 'addProperties':
Object.assign(state, action.extraData);
break;
case 'removeProperties':
for (const key of action.keysToRemove) {
delete state[key];
}
break;
case 'clear':
for (const key in state) {
delete state[key];
}
break;
default:
break;
}
};

0 comments on commit 861f800

Please sign in to comment.