O'Reilly logo

Getting Started with Backbone Marionette by Arturo Soto, Raymundo Armendariz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the event aggregator of Marionette.js

The Marionette implementation of the event aggregator pattern made its way out of the Marionette core build as it can be found now in a separate distributable file called backbone.wreqr.js. This implementation extends from the backbone.events object. The following is an example of how to instantiate an event aggregator:

var vent = new Backbone.Wreqr.EventAggregator();

You can start adding listeners that will react to the events triggered:

vent.on("do something", function(){
  console.log("im logging a message");
});

Now, you have a listener that will be expecting an event to be triggered.

Let's trigger the do something method:

vent.trigger("do something");

And that's all you need to log the message. Ok, but how ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required