Slide 59
Slide 59 text
Mediator.js
function Subscriber(fn, options, context){
if (!this instanceof Subscriber) {
return new Subscriber(fn, context, options);
}else{
this.id = guidGenerator();
this.fn = fn;
this.options = options;
this.context = context;
this.channel = null;
}
};
Publish: function(data){
for(var y = 0, x = this._callbacks.length; y < x; y++) {
if(!this.stopped){
var callback = this._callbacks[y], l;
if(callback.options !== undefined && typeof callback.options.predicate === "function"){
if(callback.options.predicate.apply(callback.context, data)){
callback.fn.apply(callback.context, data);
}
}else{
callback.fn.apply(callback.context, data);
}
}
l = this._callbacks.length;
if(l < x) y--; x = l;
}