(function(a,b){varc="/",d=50,e=0,f="postal",g=function(){},h=function(a){varb={envelope:{}},d;switch(a.length){case3:typeofa[1]=="Object"&&typeofa[2]=="Object"?(b.envelope.exchange=c,b.envelope.topic=a[0],b.payload=a[1],d=b.envelope,b.envelope=_.extend(d,a[2])):(b.envelope.exchange=a[0],b.envelope.topic=a[1],b.payload=a[2]);break;case4:b.envelope.exchange=a[0],b.envelope.topic=a[1],b.payload=a[2],d=b.envelope,b.envelope=_.extend(d,a[3]);break;default:b.envelope.exchange=c,b.envelope.topic=a[0],b.payload=a[1]}returnb},i=function(){vara;returnfunction(b){varc=!1;return_.isString(b)?(c=b===a,a=b):(c=_.isEqual(b,a),a=_.clone(b)),!c}},j=function(a,b){this.exchange=a,this.topic=b};j.prototype={subscribe:function(a){varb=newk(this.exchange,this.topic,a);returnn.configuration.bus.subscribe(b),b},publish:function(a,b){varc=_.extend({exchange:this.exchange,timeStamp:newDate,topic:this.topic},b);n.configuration.bus.publish(a,c)}};vark=function(a,b,c){this.exchange=a,this.topic=b,this.callback=c,this.priority=d,this.constraints=[],this.maxCalls=e,this.onHandled=g,this.context=null,n.publish(f,"subscription.created",{event:"subscription.created",exchange:a,topic:b})};k.prototype={unsubscribe:function(){n.configuration.bus.unsubscribe(this),n.publish(f,"subscription.removed",{event:"subscription.removed",exchange:this.exchange,topic:this.topic})},defer:function(){vara=this.callback;returnthis.callback=function(b){setTimeout(a,0,b)},this},disposeAfter:function(a){if(_.isNaN(a)||a<=0)throw"The value provided to disposeAfter (maxCalls) must be a number greater than zero.";varb=this.onHandled,c=_.after(a,_.bind(function(){this.unsubscribe(this)},this));returnthis.onHandled=function(){b.apply(this.context,arguments),c()},this},ignoreDuplicates:function(){returnthis.withConstraint(newi),this},whenHandledThenExecute:function(a){if(!_.isFunction(a))throw"Value provided to 'whenHandledThenExecute' must be a function";returnthis.onHandled=a,this},withConstraint:function(a){if(!_.isFunction(a))throw"Predicate constraint must be a function";returnthis.constraints.push(a),this},withConstraints:function(a){varb=this;return_.isArray(a)&&_.each(a,function(a){b.withConstraint(a)}),b},withContext:function(a){returnthis.context=a,this},withDebounce:function(a){if(_.isNaN(a))throw"Milliseconds must be a number";varb=this.callback;returnthis.callback=_.debounce(b,a),this},withDelay:function(a){if(_.isNaN(a))throw"Milliseconds must be a number";varb=this.callback;returnthis.callback=function(c){setTimeout(b,a,c)},this},withPriority:function(a){if(_.isNaN(a))throw"Priority must be a number";returnthis.priority=a,this},withThrottle:function(a){if(_.isNaN(a))throw"Milliseconds must be a number";varb=this.callback;returnthis.callback=_.throttle(b,a),this}};varl={cache:{},compare:function(a,b){if(this.cache[b]&&this.cache[b][a])return!0;varc=newRegExp("^"+this.regexify(a)+"$"),d=c.test(b);returnd&&(this.cache[b]||(this.cache[b]={}),this.cache[b][a]=!0),d},regexify:function(a){returna.replace(/\./g,"\\.").replace(/\*/g,".*").replace(/#/g,"[A-Z,a-z,0-9]*")}},m={subscriptions:{},wireTaps:[],publish:function(a,b){this.notifyTaps(a,b),_.each(this.subscriptions[b.exchange],function(c){_.each(c,function(c){n.configuration.resolver.compare(c.topic,b.topic)&&_.all(c.constraints,function(b){returnb(a)})&&typeofc.callback=="function"&&(c.callback.apply(c.context,[a,b]),c.onHandled())})})},subscribe:function(a){varb,c,d,e,f;e=this.subscriptions[a.exchange]=this.subscriptions[a.exchange]||{},f=this.subscriptions[a.exchange][a.topic]=this.subscriptions[a.exchange][a.topic]||[],b=f.length-1;for(;b>=0;b--)if(f[b].priority<=a.priority){f.splice(b+1,0,a),c=!0;break}c||f.unshift(a)},notifyTaps:function(a,b){_.each(this.wireTaps,function(c){c(a,b)})},unsubscribe:function(a){if(this.subscriptions[a.exchange][a.topic]){varb=this.subscriptions[a.exchange][a.topic].length,c=0;for(;c<b;c++)if(this.subscriptions[a.exchange][a.topic][c]===a){this.subscriptions[a.exchange][a.topic].splice(c,1);break}}},addWireTap:function(a){varb=this;returnb