-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Solving task #5220
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
base: master
Are you sure you want to change the base?
Solving task #5220
Conversation
mateacademy-ai-mentor
left a comment
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.
Review Summary
Hello! Your solution correctly implements the core state transformation logic, and it's great that you're avoiding direct state mutation. However, I'm requesting changes because the implementation doesn't follow some key requirements from the task checklist.
Specifically, your code needs to be refactored to:
- Use a
switchstatement to handle the differentaction.typevalues instead of the currentif/else ifstructure. This is a mandatory requirement [CHECKLIST ITEM #2]. Remember to also include adefaultcase for handling unknown actions [CHECKLIST ITEM #3]. - Avoid repeating code. The
history.push()call is duplicated inside each conditional block. Please move it outside and after the conditional logic so it only runs once per loop iteration [CHECKLIST ITEM #4].
Once these structural changes are made, your solution will be in great shape!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
src/transformStateWithClones.js
Outdated
| if (action.type === 'addProperties') { | ||
| currentState = { ...currentState, ...action.extraData }; | ||
| history.push({ ...currentState }); | ||
| } else if (action.type === 'removeProperties') { | ||
| const nextState = { ...currentState }; | ||
|
|
||
| for (const key of action.keysToRemove) { | ||
| delete nextState[key]; | ||
| } | ||
|
|
||
| currentState = nextState; | ||
| history.push({ ...currentState }); | ||
| } else if (action.type === 'clear') { | ||
| currentState = {}; | ||
| history.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.
This if/else if structure violates a key requirement. Checklist item #2 states: 'Use switch statement if you have limited amount of conditions.' A switch statement on action.type would be more appropriate here. Additionally, this would allow you to include a default case for handling unknown action types, as required by checklist item #3.
src/transformStateWithClones.js
Outdated
|
|
||
| if (action.type === 'addProperties') { | ||
| currentState = { ...currentState, ...action.extraData }; | ||
| history.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.
This history.push() call is repeated in every conditional branch (see also lines 27 and 30). This violates checklist item #4: 'If you perform same action in all switch cases - do it just once afterwards.' To avoid repetition, this line should be moved outside and after the conditional logic, so it executes once at the end of each loop iteration.
mateacademy-ai-mentor
left a comment
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.
Review Summary
Excellent work on this revision! I'm happy to approve your solution. You've successfully addressed all the feedback from the previous review, and the code now meets all requirements perfectly. The logic is clean and well-structured, especially with the correct use of a switch statement and the refactoring to avoid code duplication [CHECKLIST ITEM #4]. Great job!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.