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

js_stateful-object solution #2704

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

Conversation

Medaed
Copy link

@Medaed Medaed commented Aug 8, 2023

No description provided.

Comment on lines 9 to 11
const actionType = action.type;
const actionExtraData = action.extraData;
const actionKeysToRemove = action.keysToRemove;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't see any sense to create these redundant constants

Comment on lines 13 to 26
if (actionType === 'addProperties') {
Object.assign(state, actionExtraData);
}

if (actionType === 'removeProperties') {
for (const property of actionKeysToRemove) {
delete state[property];
}
}

if (actionType === 'clear') {
for (const element in state) {
delete state[element];
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to use a switch case statement when you have multiple conditions


switch (actionType) {
case 'addProperties':
Object.assign(state, action.extraData);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you modified initial state, it's a bad idea
you need to create a clone of the state and modify this cloned object

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

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.

2 participants