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

Stateful-clones #2855

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

Stateful-clones #2855

wants to merge 2 commits into from

Conversation

Zava96
Copy link

@Zava96 Zava96 commented Oct 13, 2023

No description provided.

Comment on lines 18 to 28
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 = {};
}

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


result.push(newState);

currentState = newState;

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

Suggested change
currentState = newState;

for (const action of actions) {
const { type, extraData, keysToRemove } = action;

let newState = { ...currentState };

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 })

@Zava96 Zava96 requested a review from VitaliyBodnar October 13, 2023 15:20
Copy link

@etojeDenys etojeDenys left a comment

Choose a reason for hiding this comment

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

good job

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.

3 participants