dependency free modular application structure
var broker = require('broker');
var channel = broker.channel('session');
broker.channel
var broker = require('broker');
broker.channel('session').subscribe('login', function(){
...
});
Subscribing to events on a channel
var broker = require('broker');
var view = new Backbone.View();
broker.channel('session').publish('show',view);
Publish an event to a channel
Do
Don't
var router = Backbone.Router.extend({
initialize: function(){
broker.channel('session').subscribe('login', function(){
this.loadRoutes({
'home': 'showHome',
'user/:id': 'showUser'
});
}.bind(this));
}
});
Load routes on logon
var router = Backbone.Router.extend({
initialize: function(){
broker.channel('session').subscribe('logoff', function(){
this.unloadRoutes();
}.bind(this));
}
});
Make sure all routes are unloaded at logoff