Skip to content

Solution#331

Open
dmdamyan wants to merge 1 commit into
mate-academy:masterfrom
dmdamyan:develop
Open

Solution#331
dmdamyan wants to merge 1 commit into
mate-academy:masterfrom
dmdamyan:develop

Conversation

@dmdamyan

Copy link
Copy Markdown

No description provided.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

Your solution is approved because it implements all the required MyEventEmitter methods (on, once, off, emit, prependListener, prependOnceListener, removeAllListeners, listenerCount) and they behave correctly for the typical, expected usage. The core semantics are right: emit is synchronous, listeners are called in registration order, once removes itself before invoking the callback, and removing non‑existent listeners or emitting events with no listeners is handled gracefully. One thing to be aware of is your removeAllListeners implementation in src/MyEventEmitter.js, on the line where you check if (!eventName) (around the removeAllListeners method): this treats falsy event names like '' or 0 as if no argument was passed, which would clear all events instead of just that one; a more robust pattern would be to test arguments.length === 0 or compare to undefined. This edge case is not a blocker for the assignment as typically only non‑empty string event names are used, but it’s a good opportunity to tighten your API behavior. As further, non‑required improvements, you could (1) make methods like on, off, once, prependListener, and prependOnceListener return this to enable chaining, (2) allow off(event, originalListener) to remove once listeners by attaching the original function to the wrapper and checking both listener === fn and listener.original === fn, and (3) delete the event key from the internal map when its listener array becomes empty. Overall, your implementation is solid and functionally complete; refining these small areas will help you get even closer to a production‑grade EventEmitter.


✨ 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