Search code examples
backbone.jsmarionetteeventaggregator

What's the additional benefit of Event Aggregator in Backbone Marionette compared to the built in Backbone Events?


I have recently looked at Backbone.Marionette. It mentions the Event Aggregator in a way that seems to be something new.

https://github.com/toekneestuck/edgefonts-preview/blob/master/components/backbone.marionette/docs/marionette.eventaggregator.md

However I don't really see the added benefit to normal events. Doesn't following Code provide you the same?

var dispatcher = _.clone(Backbone.Events)

Solution

  • These are almost exactly the same things. (check the code)

    The difference is that EventAggregators is a "class" which can be instantiated (wherea Backbone.Events act more as a mixin).

    Being a "class", EventAggregators can be extended.

    EventAggregators.extend({ /* your new methods */ });
    

    The difference is really small, but goes a long way in reducing boilerplate necessary to create a event hub with custom prototype methods - and extending them in sub-eventAggregator.