Skip to content

Instantly share code, notes, and snippets.

@mxriverlynn
Last active August 30, 2015 04:10
Show Gist options
  • Save mxriverlynn/21e84f7786d968eba00d to your computer and use it in GitHub Desktop.
Save mxriverlynn/21e84f7786d968eba00d to your computer and use it in GitHub Desktop.
broker channel vs broker instance
var filtersChannel = Postal.channel("filters");
function FilterController(options){
this.region = options.region;
filtersChannel.subscribe("add", (filter) => this.showFilter(filter));
}
FilterController.prototype.showFilter = function(filter){
var view = new FilterView(filter);
this.region.show(view);
}
FilterController.prototype.addFilter = function(){
var addView = new AddFilterView();
addView.on("add", (f) => filtersChannel.publish("add", f));
this.region.show(addView)
}
function FilterController(options){
this.region = options.region;
this.filtersChannel = new Backbone.Wreqr.EventAggregator();
filtersChannel.on("add", (filter) => this.showFilter(filter));
}
FilterController.prototype.showFilter = function(filter){
var view = new FilterView(filter);
this.region.show(view);
}
FilterController.prototype.addFilter = function(){
var addView = new AddFilterView();
addView.on("add", (f) => filtersChannel.trigger("add", f));
this.region.show(addView)
}
@tung-dang
Copy link

In line 5, I think it should be: this.filtersChannel.on("add", (filter) => this.showFilter(filter));
Is it correct?

@tung-dang
Copy link

Thanks a lot for your helpful blog post: "Message Brokers, Channels And JavaScript Zombies" :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment