Generally one implements notifications by listening for events on specific models but if one wishes to have a single global message interchange, it could be done as follows:
var pubsub = new Backbone.Model;
View1 = Backbone.View.extend({
initialize: function(){
pubsub.bind('custom event', callback);
}
// ...
});
View2 = Backbone.View.extend({
// ...
foo: function(){
pubsub.trigger('custom event', data);
}
});
or the reverse if one wished to publish events from models or collections.
Thanks!
You might want to change
'custom event'
to'custom:event'
or something similar because the code above will actually trigger the callback twice; once for thecustom
event and again for theevent
event.