Solution#331
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
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! ✨
No description provided.