Skip to content

Commit

Permalink
replace break with return, improved average performance by 17 percent
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrMar1939 committed Aug 2, 2023
1 parent 823a6bc commit f86fa7c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/transformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,35 @@
* @param {Object[]} actions
*/
function transformState(state, actions) {
const finiteStateMachine = ({ type, extraData, keysToRemove }) => {
const changeState = ({ type, extraData, keysToRemove }) => {
switch (type) {
case 'addProperties':
Object.assign(state, extraData);
break;

return;

case 'removeProperties':
keysToRemove.forEach(keyToRemove => {
delete state[keyToRemove];
});
break;

return;

case 'clear':
for (const key in state) {
delete state[key];
}
break;

return;

default:
break;
return 'error';
}
};

actions.forEach(action => {
finiteStateMachine(action);
changeState(action);
});

return state;
}

module.exports = transformState;

0 comments on commit f86fa7c

Please sign in to comment.