Posts

Showing posts with the label EventEmitter

On EventEmitter In node.js

Today I had a whole node.js session and I have spent a bit of time looking at current EventEmitter implementation. I have twitted already that it sucks as it is, and while it's really trivial to implement the same for any browser , I believe many mistakes have been made about the API . Here the list: on() is a shortcut for addListener but there is no off() as removeListener's shortcut (inconsistent) add/removeListener is not DOM friendly, we cannot reuse an EventEmitter in the browser without double checking if those methods exist removeAllListeners() accepts no arguments and cleans up the whole emitter but there is no way to retrieve all listeners via listeners() passing no arguments (again, inconsistent) there's no possibility to use handleEvent property, as already defined in the EventListener , once again objects are not reusable between client and server no duplicated checks for both addListener and removeListener, this is totally inconsistent against DOM Event...