You can create a simple model for storing the state of the application, you do not need anything interesting, just a data bag that implements the usual methods of the Backbone event:
var AppState = Backbone.Model.extend({}); var app_state = new AppState();
Then, in the list of genres view, click events will be listened (as you already did) and set the current genre in the state-application model when someone changes it:
var Genres = Backbone.View.extend({
The view for a particular genre will listen to the "change:genre"
events in the state-application model and respond as the genre changes:
var Genre = Backbone.View.extend({ initialize: function() { _.bindAll(this, 'change_genre'); app_state.on('change:genre', this.change_genre); },
Demo: http://jsfiddle.net/ambiguous/mwBKm/1/
You can create models for any data that you need, and models are a convenient way to work with data events in Backbone. As an added bonus, this approach allows you to easily maintain the state of your application: just add the usual support for Backbone persistence to the AppState
and off you go.
If you need a simple event bus to move events other than data, you can use the Backbone Events
methods to create a simple event aggregator:
app.events = _.extend({}, Backbone.Events);
Then, if you have a global app
namespace, you can say the following:
app.events.on('some-event', some_function);
and
app.events.trigger('some-event', arg1, arg2, ...);