Created
March 11, 2016 17:24
-
-
Save julesbou/aa2d6b2d37d5f7d2e468 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// global event dispatcher | |
Backbone.View.prototype.eventAggregator = _.extend({}, Backbone.Events); | |
// create two different views | |
var view1 = new Backbone.View(); | |
var view2 = new Backbone.View(); | |
// and attach a listener on view1 | |
view1.eventAggregator.on(‘disconnect’, function() { | |
console.log('view1 disconnected'); | |
}); | |
// now, triggering an event from view2 will do nothing | |
view2.trigger('disconnect'); // (nothing) | |
// but using the global event dispatcher, view2 can communicate with view1 | |
view2.eventAggregator.trigger('disconnect'); // 'view1 disconnected' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment