I've been wondering about the way enyo handles events and the possibility of creating something simpler and more flexible.
Currently, it appears there are two types of events:
- Component Events, as implemented in
enyo.Component- Registered Events as provided by the RegisteredEventSupport mixin.
Component events are triggered by the dispatchEvent method, and their handlers are defined in a handlers object. Each event will only execute a single event handler on any particular component.
The fact that there can be only one single handler for a particular event is a bit limiting, in particular when it comes to mixins. I've run into several situations where I'd like to extract common functionality into a mixin, but this functionality requires events.
The way I do this currently, is have the mixin extend the importProps method to have it manipulate the handlers object by mixing in a 2nd handlers object containing the handlers required to make the mixin do it's thing. The downside to this, is that now the mixin dictates the name of the event handler. If the component we're extending doesn't use the same name for the handler, things will break.
Registered Events do allow you to register multiple listeners, but, they are not triggered by the normal enyo Component's event flow, they don't bubble, and they don't waterfall. In particular, they don't tie into DOM events.
Wouldn't it be better to simply add support for multiple event handlers to enyo's Component Events and get the best of both worlds?