-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stateful-clones #2855
base: master
Are you sure you want to change the base?
Stateful-clones #2855
Conversation
src/transformStateWithClones.js
Outdated
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 = {}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- is better to use switch case statement if instead of multiple if blocks
- move addProperties, removeProperties, clear to the constants as it will make a code cleaner
src/transformStateWithClones.js
Outdated
|
||
result.push(newState); | ||
|
||
currentState = newState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need to reassign currentState
currentState = newState; |
src/transformStateWithClones.js
Outdated
for (const action of actions) { | ||
const { type, extraData, keysToRemove } = action; | ||
|
||
let newState = { ...currentState }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newState variables it redundant, because you can directly push copy of state to result
result.push({ ...currentState })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job
No description provided.