Many people prefer the quick way that EventDispatcher
can set up an object to handle events. With one line of code in an object’s constructor you can have an EventDispatcher instance ready to go, plus all the add and remove interface functions will be added to the target object. I’ll admit, it’s pretty elegant.
EventDispatcher.initialize(target);
I’ve updated my EventManager class with the same functionality. Obviously, the implementation is different, but the interface is the same, so all you have to do is call the static function initialize
and you’re ready to go. Everything else should work the same way as the previous version. If you use the mixin, an EventManager instance is automatically set in the _eventManager variable of the target object, but initialize
also returns the same object if you’d like to assign it elsewhere.
Download a ZIP of the source files for version 1.1!