diff --git a/example/amd/js/libs/postal/postal.js b/example/amd/js/libs/postal/postal.js index 313dfc6..0f3e2dd 100644 --- a/example/amd/js/libs/postal/postal.js +++ b/example/amd/js/libs/postal/postal.js @@ -56,7 +56,7 @@ ChannelDefinition.prototype = { }, publish: function(data, envelope) { - var env = envelope || {}; + var env = (Object.prototype.toString.call(envelope) === "[object String]") ? { topic: envelope } : envelope || {}; env.channel = this.channel; env.timeStamp = new Date(); env.topic = env.topic || this.topic; diff --git a/example/standard/js/postal.js b/example/standard/js/postal.js index 313dfc6..0f3e2dd 100644 --- a/example/standard/js/postal.js +++ b/example/standard/js/postal.js @@ -56,7 +56,7 @@ ChannelDefinition.prototype = { }, publish: function(data, envelope) { - var env = envelope || {}; + var env = (Object.prototype.toString.call(envelope) === "[object String]") ? { topic: envelope } : envelope || {}; env.channel = this.channel; env.timeStamp = new Date(); env.topic = env.topic || this.topic; diff --git a/lib/browser/standard/postal.diagnostics.min.gz.js b/lib/browser/standard/postal.diagnostics.min.gz.js index b4fe75f..ce0d3c9 100644 Binary files a/lib/browser/standard/postal.diagnostics.min.gz.js and b/lib/browser/standard/postal.diagnostics.min.gz.js differ diff --git a/lib/browser/standard/postal.js b/lib/browser/standard/postal.js index 313dfc6..0f3e2dd 100644 --- a/lib/browser/standard/postal.js +++ b/lib/browser/standard/postal.js @@ -56,7 +56,7 @@ ChannelDefinition.prototype = { }, publish: function(data, envelope) { - var env = envelope || {}; + var env = (Object.prototype.toString.call(envelope) === "[object String]") ? { topic: envelope } : envelope || {}; env.channel = this.channel; env.timeStamp = new Date(); env.topic = env.topic || this.topic; diff --git a/lib/browser/standard/postal.min.gz.js b/lib/browser/standard/postal.min.gz.js index 2ac0cb5..d016611 100644 Binary files a/lib/browser/standard/postal.min.gz.js and b/lib/browser/standard/postal.min.gz.js differ diff --git a/lib/browser/standard/postal.min.js b/lib/browser/standard/postal.min.js index 316f540..e70d1e7 100644 --- a/lib/browser/standard/postal.min.js +++ b/lib/browser/standard/postal.min.js @@ -1 +1 @@ -(function(a,b,c){typeof define=="function"&&define.amd?define(["underscore"],function(d){return c(d,a,b)}):c(a._,a,b)})(this,document,function(a,b,c,d){var e="/",f=50,g=0,h="postal",i=function(){},j=function(){var b;return function(c){var d=!1;return a.isString(c)?(d=c===b,b=c):(d=a.isEqual(c,b),b=a.clone(c)),!d}},k=function(a,b){this.channel=a||e,this.topic=b||""};k.prototype={subscribe:function(){var a=arguments.length;if(a===1)return new l(this.channel,this.topic,arguments[0]);if(a===2)return new l(this.channel,arguments[0],arguments[1])},publish:function(a,b){var c=b||{};c.channel=this.channel,c.timeStamp=new Date,c.topic=c.topic||this.topic,p.configuration.bus.publish(a,c)}};var l=function(a,b,c){this.channel=a,this.topic=b,this.callback=c,this.priority=f,this.constraints=new Array(0),this.maxCalls=g,this.onHandled=i,this.context=null,p.publish({event:"subscription.created",channel:a,topic:b},{channel:h,topic:"subscription.created"}),p.configuration.bus.subscribe(this)};l.prototype={unsubscribe:function(){p.configuration.bus.unsubscribe(this),p.publish({event:"subscription.removed",channel:this.channel,topic:this.topic},{channel:h,topic:"subscription.removed"})},defer:function(){var a=this.callback;return this.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.";var c=this.onHandled,d=a.after(b,a.bind(function(){this.unsubscribe(this)},this));return this.onHandled=function(){c.apply(this.context,arguments),d()},this},ignoreDuplicates:function(){return this.withConstraint(new j),this},whenHandledThenExecute:function(b){if(!a.isFunction(b))throw"Value provided to 'whenHandledThenExecute' must be a function";return this.onHandled=b,this},withConstraint:function(b){if(!a.isFunction(b))throw"Predicate constraint must be a function";return this.constraints.push(b),this},withConstraints:function(b){var c=this;return a.isArray(b)&&a.each(b,function(a){c.withConstraint(a)}),c},withContext:function(a){return this.context=a,this},withDebounce:function(b){if(a.isNaN(b))throw"Milliseconds must be a number";var c=this.callback;return this.callback=a.debounce(c,b),this},withDelay:function(b){if(a.isNaN(b))throw"Milliseconds must be a number";var c=this.callback;return this.callback=function(a){setTimeout(c,b,a)},this},withPriority:function(b){if(a.isNaN(b))throw"Priority must be a number";return this.priority=b,this},withThrottle:function(b){if(a.isNaN(b))throw"Milliseconds must be a number";var c=this.callback;return this.callback=a.throttle(c,b),this}};var m={cache:{},compare:function(a,b){if(this.cache[b]&&this.cache[b][a])return!0;var c=new RegExp("^"+a.replace(/\./g,"\\.").replace(/\*/g,".*").replace(/#/g,"[A-Z,a-z,0-9]*")+"$"),d=c.test(b);return d&&(this.cache[b]||(this.cache[b]={}),this.cache[b][a]=!0),d}},n={subscriptions:{},wireTaps:new Array(0),publish:function(b,c){a.each(this.wireTaps,function(a){a(b,c)}),a.each(this.subscriptions[c.channel],function(d){a.each(d,function(d){p.configuration.resolver.compare(d.topic,c.topic)&&a.all(d.constraints,function(a){return a(b)})&&typeof d.callback=="function"&&(d.callback.apply(d.context,[b,c]),d.onHandled())})})},subscribe:function(a){var b,c,d,e=this.subscriptions[a.channel],f;e||(e=this.subscriptions[a.channel]={}),f=this.subscriptions[a.channel][a.topic],f||(f=this.subscriptions[a.channel][a.topic]=new Array(0)),b=f.length-1;for(;b>=0;b--)if(f[b].priority<=a.priority){f.splice(b+1,0,a),c=!0;break}return c||f.unshift(a),a},unsubscribe:function(a){if(this.subscriptions[a.channel][a.topic]){var b=this.subscriptions[a.channel][a.topic].length,c=0;for(;c=0;b--)if(f[b].priority<=a.priority){f.splice(b+1,0,a),c=!0;break}return c||f.unshift(a),a},unsubscribe:function(a){if(this.subscriptions[a.channel][a.topic]){var b=this.subscriptions[a.channel][a.topic].length,c=0;for(;c