Skip to content

Instantly share code, notes, and snippets.

@djhojd
Forked from mxriverlynn/1.js
Created September 26, 2013 12:05
Show Gist options
  • Save djhojd/6713229 to your computer and use it in GitHub Desktop.
Save djhojd/6713229 to your computer and use it in GitHub Desktop.
MyApp = {};
MyApp.vent = _.extend({}, Backbone.Events);
MyApp.vent.on("some:event", function(){
alert("some event was fired!");
});
MyApp.vent.trigger("some:event");
MyApp = new Backbone.Marionette.Application();
MyApp.vent.on("some:event", function(){
alert("some event was fired!");
});
MyApp.vent.trigger("some:event");
MyApp = new Backbone.Marionette.Application();
MyApp.UserManagement = (function(Backbone){
var mgmt = {};
var mgmtEvents = new Backbone.Marionette.EventAggregator();
mgmt.UserListView = Backbone.View.extend({
events: {
"click .user": "userClicked"
},
userClicked: function(){
var user = // get the user that was clicked
mgmtEvents.trigger("user:selected", user);
},
// ...
});
mgmt.UserDetailView = Backbone.View.extend({
// ...
});
mgmtEvents.on("user:selected", function(user){
var view = new mgmt.UserDetailView({
model: user
});
view.render();
$("#detail").html(view.el);
});
return mgmt;
})(Backbone);
MyApp.vent.on("myChannel", "myEvent", function(){
// do stuff here
});
MyApp.vent.trigger("myChannel", "myEvent");
MyApp.myChannel = _.extend({}, Backbone.Events);
MyApp.anotherChannel = _.extend({}, Backbone.Events);
MyApp.myChannel.on("someEvent", function(){
// ...
});
MyApp.myChannel.on("anotherEvent", function(){
// ...
});
MyApp.vent.on("some:namespaced:event", function(){
// ...
});
MyApp.vent.trigger("some:namespaced:event");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment