need some help from AI-Mentor#1367
need some help from AI-Mentor#1367uselessmorning wants to merge 3 commits intomate-academy:masterfrom
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job implementing the core logic for the promises! They resolve and reject correctly based on the specified events. However, a couple of changes are needed before this can be approved.
-
Event Listeners Not Removed: Your event listeners are never removed after a promise resolves or rejects. This can lead to memory leaks and unexpected behavior. It's important to clean up listeners once they are no longer needed. You can do this by defining the listener as a named function and then calling
document.removeEventListenerfrom within the handler right after the promise is settled. -
Incorrect Rejection Message: When
firstPromiseis rejected, the notification displaysError: First promise was rejected. The requirement is to show only the message itself. This happens because you're passing the entireErrorobject toshowNotification. To fix this, you should passmsg.messageinstead of the wholemsgobject in your.catch()block.
Once you've addressed these points, your solution will be excellent!
✨ 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
| reject(new Error('First promise was rejected')); | ||
| }, 3000); | ||
|
|
||
| document.addEventListener('click', (e) => { |
There was a problem hiding this comment.
This event listener is never removed, even after the promise resolves or rejects. This can lead to memory leaks and unexpected behavior if this function were called multiple times. It's a good practice to clean up listeners once they are no longer needed. You can do this by defining the listener as a named function and then calling document.removeEventListener when the promise settles.
|
|
||
| function secondPromise() { | ||
| return new Promise((resolve, reject) => { | ||
| document.addEventListener('click', (e) => { |
There was a problem hiding this comment.
Similar to firstPromise, this event listener is not removed after the promise resolves. Consider cleaning it up inside the handler after resolve is called to prevent it from running on subsequent clicks.
| let isLeftClicked = false; | ||
| let isRightClicked = false; | ||
|
|
||
| document.addEventListener('mousedown', (e) => { |
There was a problem hiding this comment.
This event listener also remains active even after the promise is resolved. It should be removed once isLeftClicked && isRightClicked becomes true to avoid unnecessary event handling and potential memory leaks.
|
|
||
| firstPromise() | ||
| .then((msg) => showNotification(msg, 'success')) | ||
| .catch((msg) => showNotification(msg, 'error')); |
There was a problem hiding this comment.
The firstPromise is rejected with an Error object. Here, msg will be that Error object, and displaying it directly will result in text like "Error: First promise was rejected". The requirement asks to display the promise's message. To show only the message text, you should pass msg.message to showNotification.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent progress on this task! You've done a great job fixing the event listener cleanup for firstPromise and thirdPromise.
I'm requesting one change before approval. The event listener for secondPromise is not being removed after the promise resolves. This can lead to a memory leak, as the listener will remain active indefinitely.
To fix this, please apply the same pattern you used for the other promises:
- Define the event handler as a named function.
- Call
document.removeEventListener()with that named function right after you callresolve.
You're very close to finishing this. Keep up the great work!
✨ 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
|
|
||
| function secondPromise() { | ||
| return new Promise((resolve, reject) => { | ||
| document.addEventListener('click', (e) => { |
There was a problem hiding this comment.
This event listener is never removed, even after the promise resolves. This can lead to memory leaks. You should apply the same pattern you used for firstPromise and thirdPromise: define a named function for the handler and remove it after calling resolve.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work on this task! Your implementation of all three promises is flawless and meets every requirement perfectly. I'm particularly impressed with how you correctly handled the cleanup of event listeners and timers—this is a critical skill for preventing memory leaks and shows a great understanding of asynchronous JavaScript. You've successfully addressed all the previous feedback, and the code is now clean and robust. I am happy to approve your solution.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.