-
Notifications
You must be signed in to change notification settings - Fork 4.8k
added a solution to the problem #5244
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?
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 work on implementing the state transformation logic and correctly using clones to avoid mutation! Your solution is very close. However, changes are needed because the switch statement in src/transformStateWithClones.js is missing a default case. This is a requirement from the checklist [CHECKLIST ITEM #3]. Without it, if the function receives an action with an unknown type, it will cause a runtime error in the next loop iteration. Please add a default case to handle these unexpected actions, for example, by throwing an error.
✨ 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
| switch (action.type) { | ||
| case 'addProperties': { | ||
| newState = { ...curState, ...action.extraData }; | ||
| break; | ||
| } | ||
|
|
||
| case 'removeProperties': { | ||
| newState = { ...curState }; | ||
|
|
||
| for (const key of action.keysToRemove) { | ||
| delete newState[key]; | ||
| } | ||
| break; | ||
| } | ||
|
|
||
| case 'clear': { | ||
| newState = {}; | ||
| break; | ||
| } | ||
| } |
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 switch statement is missing a default case. This violates checklist item #3: 'switch/case should always have default case for error handling.' Without it, an unknown action type will result in newState being undefined, which can cause errors in subsequent operations.
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 adding the default case to your switch statement—you're very close to a complete solution! However, this requires one final adjustment. The default case is intended for error handling, but currently, it returns a copy of the state, which silently ignores unknown action types. To align with the requirements [CHECKLIST ITEM #3], please update the default case to throw an error when an unknown action type is encountered. For instance, you could use: throw new Error("Unknown action type: ".concat(action.type));. This change will ensure that invalid actions are properly flagged instead of being ignored.
✨ 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
| default: { | ||
| newState = { ...curState }; | ||
| break; | ||
| } |
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 default case should handle errors for unknown action types, as required by checklist item #3: 'switch/case should always have default case for error handling'. Instead of returning a copy of the current state, it's better to throw an error to indicate that an invalid action type was passed to the function.
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 iteration! You've done a fantastic job addressing the previous feedback, especially with implementing the error handling in the default case. Your solution is now fully functional and meets all the requirements.
I am approving this submission to keep you moving forward, but there is one tiny detail to be aware of for the future. There's a small typo in the error message in src/transformStateWithClones.js. The word Unknow should be Unknown.
This is just a minor point of polish. Keep up the great work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| } | ||
|
|
||
| default: { | ||
| throw new Error(`Unknow action type: ${action.type}`); |
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.
There's a small typo here. The word Unknow should be Unknown.
No description provided.