define(["underscore"],function(a){varb="/",c=50,d=0,e="postal",f=function(){},g=function(c){vard={envelope:{}},e;switch(c.length){case3:typeofc[1]=="Object"&&typeofc[2]=="Object"?(d.envelope.exchange=b,d.envelope.topic=c[0],d.payload=c[1],e=d.envelope,d.envelope=a.extend(e,c[2])):(d.envelope.exchange=c[0],d.envelope.topic=c[1],d.payload=c[2]);break;case4:d.envelope.exchange=c[0],d.envelope.topic=c[1],d.payload=c[2],e=d.envelope,d.envelope=a.extend(e,c[3]);break;default:d.envelope.exchange=b,d.envelope.topic=c[0],d.payload=c[1]}returnd},h=function(){varb;returnfunction(c){vard=!1;returna.isString(c)?(d=c===b,b=c):(d=a.isEqual(c,b),b=a.clone(c)),!d}},i=function(a,b){this.exchange=a,this.topic=b};i.prototype={subscribe:function(a){varb=newj(this.exchange,this.topic,a);returnm.configuration.bus.subscribe(b),b},publish:function(b,c){vard=a.extend({exchange:this.exchange,timeStamp:newDate,topic:this.topic},c);m.configuration.bus.publish(b,d)}};varj=function(a,b,g){this.exchange=a,this.topic=b,this.callback=g,this.priority=c,this.constraints=[],this.maxCalls=d,this.onHandled=f,this.context=null,m.publish(e,"subscription.created",{event:"subscription.created",exchange:a,topic:b})};j.prototype={unsubscribe:function(){m.configuration.bus.unsubscribe(this),m.publish(e,"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(b){if(a.isNaN(b)||b<=0)throw"The value provided to disposeAfter (maxCalls) must be a number greater than zero.";varc=this.onHandled,d=a.after(b,a.bind(function(){this.unsubscribe(this)},this));returnthis.onHandled=function(){c.apply(this.context,arguments),d()},this},ignoreDuplicates:function(){returnthis.withConstraint(newh),this},whenHandledThenExecute:function(b){if(!a.isFunction(b))throw"Value provided to 'whenHandledThenExecute' must be a function";returnthis.onHandled=b,this},withConstraint:function(b){if(!a.isFunction(b))throw"Predicate constraint must be a function";returnthis.constraints.push(b),this},withConstraints:function(b){varc=this;returna.isArray(b)&&a.each(b,function(a){c.withConstraint(a)}),c},withContext:function(a){returnthis.context=a,this},withDebounce:function(b){if(a.isNaN(b))throw"Milliseconds must be a number";varc=this.callback;returnthis.callback=a.debounce(c,b),this},withDelay:function(b){if(a.isNaN(b))throw"Milliseconds must be a number";varc=this.callback;returnthis.callback=function(a){setTimeout(c,b,a)},this},withPriority:function(b){if(a.isNaN(b))throw"Priority must be a number";returnthis.priority=b,this},withThrottle:function(b){if(a.isNaN(b))throw"Milliseconds must be a number";varc=this.callback;returnthis.callback=a.throttle(c,b),this}};vark={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]*")}},l={subscriptions:{},wireTaps:[],publish:function(b,c){this.notifyTaps(b,c),a.each(this.subscriptions[c.exchange],function(d){a.each(d,function(d){m.configuration.resolver.compare(d.topic,c.topic)&&a.all(d.constraints,function(a){returna(b)})&&typeofd.callback=="function"&&(d.callback.apply(d.context,[b,c]),d.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(b,c){a.each(this.wireTaps,function(a){a(b,c)})},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){