-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Solution #2714
base: master
Are you sure you want to change the base?
Solution #2714
Conversation
src/transformState.js
Outdated
if (action.type === 'addProperties') { | ||
const extraData = action.extraData; | ||
|
||
for (const key in extraData) { | ||
state[key] = extraData[key]; | ||
} | ||
} else if (action.type === 'removeProperties') { | ||
const keysToRemove = action.keysToRemove; | ||
|
||
for (const key of keysToRemove) { | ||
if (state.hasOwnProperty(key)) { | ||
delete state[key]; | ||
} | ||
} | ||
} else if (action.type === 'clear') { | ||
for (const key in state) { | ||
delete state[key]; | ||
} | ||
} |
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.
- please use the switch case statement here
- move 'addProperties', 'removeProperties', 'clear' to the constants as it will make a code cleaner
src/transformState.js
Outdated
const keysToRemove = action.keysToRemove; | ||
|
||
for (const key of keysToRemove) { |
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.
redundant variable
please check other places
const keysToRemove = action.keysToRemove; | |
for (const key of keysToRemove) { | |
for (const key of action.keysToRemove) { |
src/transformState.js
Outdated
const add = 'addProperties'; | ||
const remove = 'removeProperties'; | ||
const clear = 'clear'; |
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.
Variable names like this are typically uppercase
const add = 'addProperties'; | |
const remove = 'removeProperties'; | |
const clear = 'clear'; | |
const ADD = 'addProperties'; | |
const REMOVE = 'removeProperties'; | |
const CLEAR = 'clear'; |
src/transformState.js
Outdated
for (const key in action.extraData) { | ||
state[key] = action.extraData[key]; | ||
} |
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.
You could avoid a nested loop here by using Object.assign
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.
Approved.
Object.assign
is cool but more modern way to achieve the same this is using destructuring
More here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax
It's just a note
Thank you, this is a valuable tip. |
No description provided.