-
Notifications
You must be signed in to change notification settings - Fork 4.8k
js test too #5226
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?
js test too #5226
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
Great job implementing the core logic for state transformation and ensuring the original state is not mutated! Your solution works correctly.
However, this requires changes because it doesn't follow a couple of key requirements from the checklist. The implementation uses a series of if statements instead of the required switch statement to handle different action types. This violates two checklist items:
- [CHECKLIST ITEM #2]: You must use a
switchstatement for a limited number of conditions. - [CHECKLIST ITEM #3]: The
switchstatement must include adefaultcase for error handling.
Please refactor your code to use a switch statement based on action.type and add a default case to handle any unexpected actions.
✨ 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 === 'clear') { | ||
| currentState = {}; | ||
| } | ||
|
|
||
| if (action.type === 'addProperties') { | ||
| currentState = { | ||
| ...currentState, | ||
| ...action.extraData, | ||
| }; | ||
| } | ||
|
|
||
| if (action.type === 'removeProperties') { | ||
| const nextState = { ...currentState }; | ||
|
|
||
| for (const key of action.keysToRemove) { | ||
| delete nextState[key]; | ||
| } | ||
|
|
||
| currentState = nextState; | ||
| } |
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 series of if statements should be refactored into a switch statement based on action.type.
This violates two checklist items:
- Checklist item sol #2: '[CODE STYLE]: Use switch statement if you have limited amount of conditions.'
- Checklist item Kisilov_Vadim #3: '[CODE STYLE]: switch/case should always have default case for error handling.'
A switch statement would be more appropriate here and would allow you to include a default case for any unexpected action types.
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 refactoring your code to use a switch statement! Your solution correctly implements all the required logic, so I am approving your submission.
There is one important improvement to make your code more robust. The task requires pushing a copy of the state to the history. While your current implementation works because each case reassigns currentState, pushing a direct reference can lead to subtle bugs if the state update logic changes in the future. To prevent this, you should always push an explicit copy like this:
history.push({ ...currentState });This ensures each element in the history array is a distinct snapshot. Keep this in mind for future tasks. Great job!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| throw new Error(`Unknown action type: ${action.type}`); | ||
| } | ||
|
|
||
| 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 implementation works because each case in your switch statement creates a new object and reassigns it to currentState. However, this is not a very robust approach. The task requires pushing a copy of the state to the history.
If you were to later change one of the cases to mutate currentState directly, all previous states in the history array would also be changed. To prevent such bugs and follow the requirement, you should always push an explicit copy: history.push({ ...currentState });.
No description provided.