Skip to content

need some help from AI-Mentor#1367

Open
uselessmorning wants to merge 3 commits intomate-academy:masterfrom
uselessmorning:develop
Open

need some help from AI-Mentor#1367
uselessmorning wants to merge 3 commits intomate-academy:masterfrom
uselessmorning:develop

Conversation

@uselessmorning
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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 the promises! They resolve and reject correctly based on the specified events. However, a couple of changes are needed before this can be approved.

  1. 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.removeEventListener from within the handler right after the promise is settled.

  2. Incorrect Rejection Message: When firstPromise is rejected, the notification displays Error: First promise was rejected. The requirement is to show only the message itself. This happens because you're passing the entire Error object to showNotification. To fix this, you should pass msg.message instead of the whole msg object 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/scripts/main.js Outdated
reject(new Error('First promise was rejected'));
}, 3000);

document.addEventListener('click', (e) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread src/scripts/main.js Outdated

function secondPromise() {
return new Promise((resolve, reject) => {
document.addEventListener('click', (e) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread src/scripts/main.js Outdated
let isLeftClicked = false;
let isRightClicked = false;

document.addEventListener('mousedown', (e) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread src/scripts/main.js Outdated

firstPromise()
.then((msg) => showNotification(msg, 'success'))
.catch((msg) => showNotification(msg, 'error'));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

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:

  1. Define the event handler as a named function.
  2. Call document.removeEventListener() with that named function right after you call resolve.

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/scripts/main.js Outdated

function secondPromise() {
return new Promise((resolve, reject) => {
document.addEventListener('click', (e) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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 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! ✨

Footnotes

  1. Rate AI review example

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.

2 participants