javascriptbackbone.jsmarionettebackbone-events

What's the difference between event EventAggregator and EventBinder in Backbone Marionette?


From the docs in Marionette.EventAggregator and Marionette.EventBinder the code is quite the same. I suppose there's a difference I'm missing, what is it? When to use each of them?


Solution

  • The primary difference was intent. An EventAggregator's intent is explained in these articles:

    http://martinfowler.com/eaaDev/EventAggregator.html

    http://codebetter.com/jeremymiller/2009/07/22/braindump-on-the-event-aggregator-pattern/

    http://lostechies.com/derickbailey/2011/07/19/references-routing-and-the-event-aggregator-coordinating-views-in-backbone-js/

    The EventBinder's purpose was to manage dependencies in event bindings, as first described by Johnny Oshika here: Backbone.js : repopulate or recreate the view?

    ...

    Moving forward with Marionette and Backbone v0.9.9, though, EventBinder is now obsolete because Backbone.Events now includes the listenTo and stopListening methods. The EventAggregator is taking over anything that Backbone.Events doesn't cover. This is for Marionette v1.0-rc3 and beyond, though. If you're still using Marionette v1.0-rc2 or previous, you'll still need the EventBinder.