Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Solution #2714

wants to merge 3 commits into from

Conversation

patrykyo20
Copy link

No description provided.

Comment on lines 9 to 27
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];
}
}

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

Comment on lines 16 to 18
const keysToRemove = action.keysToRemove;

for (const key of keysToRemove) {

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

Suggested change
const keysToRemove = action.keysToRemove;
for (const key of keysToRemove) {
for (const key of action.keysToRemove) {

Comment on lines 8 to 10
const add = 'addProperties';
const remove = 'removeProperties';
const clear = 'clear';
Copy link

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

Suggested change
const add = 'addProperties';
const remove = 'removeProperties';
const clear = 'clear';
const ADD = 'addProperties';
const REMOVE = 'removeProperties';
const CLEAR = 'clear';

Comment on lines 16 to 18
for (const key in action.extraData) {
state[key] = action.extraData[key];
}
Copy link

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

Copy link

@mbruhler mbruhler left a 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

@patrykyo20
Copy link
Author

Thank you, this is a valuable tip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants