Comparing version 2.0.3 to 2.0.4
# v2.x | ||
## v2.0.4 | ||
* Conditionally calling _.noConflict (only if previous global._ was truthy and not equal to postal's lodash version) | ||
## v2.0.3 | ||
@@ -4,0 +7,0 @@ * Fixed lodash isEqual file name casing. |
/** | ||
* postal - Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side. | ||
* Author: Jim Cowart (http://ifandelse.com) | ||
* Version: v2.0.3 | ||
* Version: v2.0.4 | ||
* Url: http://github.com/postaljs/postal.js | ||
@@ -25,4 +25,7 @@ * License(s): MIT | ||
}( this, function( _, global, undefined ) { | ||
_ = _.noConflict(); | ||
var prevPostal = global && global.postal; | ||
var prevLodash = global && global._; | ||
if ( prevLodash && prevLodash !== _ ) { | ||
_ = _.noConflict(); | ||
} | ||
var _defaultConfig = { | ||
@@ -29,0 +32,0 @@ DEFAULT_CHANNEL: "/", |
/** | ||
* postal - Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side. | ||
* Author: Jim Cowart (http://ifandelse.com) | ||
* Version: v2.0.3 | ||
* Version: v2.0.4 | ||
* Url: http://github.com/postaljs/postal.js | ||
@@ -6,0 +6,0 @@ * License(s): MIT |
/** | ||
* postal - Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side. | ||
* Author: Jim Cowart (http://ifandelse.com) | ||
* Version: v2.0.3 | ||
* Version: v2.0.4 | ||
* Url: http://github.com/postaljs/postal.js | ||
@@ -6,0 +6,0 @@ * License(s): MIT |
/** | ||
* postal - Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side. | ||
* Author: Jim Cowart (http://ifandelse.com) | ||
* Version: v2.0.3 | ||
* Version: v2.0.4 | ||
* Url: http://github.com/postaljs/postal.js | ||
* License(s): MIT | ||
*/ | ||
(function(e,t){"function"==typeof define&&define.amd?define(["lodash"],function(n){return t(n,e)}):"object"==typeof module&&module.exports?module.exports=t(require("lodash"),this):e.postal=t(e._,e)})(this,function(e,t,n){function i(){for(;y.length;)h.unsubscribe(y.shift())}function c(e,t,n){return function(i,c,r){i===e&&r.splice(c,1),0===r.length&&delete n[t]}}function r(e,t,n,i,c){var r=c&&c.headers||{};return function(c){var o;l.resolver.compare(c.topic,e,r)&&(r.resolverNoCache||(o=t[n]=t[n]||[],o.push(c)),c.cacheKeys.push(n),i&&i(c))}}function o(e,t){return{channel:l.SYSTEM_CHANNEL,topic:"subscription."+e,data:{event:"subscription."+e,channel:t.channel,topic:t.topic}}}function s(t,n){return"function"==typeof t?t:t?function(i){var c=0,r=0;return e.each(t,function(e,o){c+=1,("topic"===o&&n.compare(i.topic,t.topic,{resolverNoCache:!0})||"context"===o&&t.context===i._context||i[o]===t[o])&&(r+=1)}),c===r}:function(){return!0}}e=e.noConflict();var a=t&&t.postal,u={DEFAULT_CHANNEL:"/",SYSTEM_CHANNEL:"postal",enableSystemMessages:!0,cacheKeyDelimiter:"|",autoCompactResolver:!1},h={configuration:e.extend({},u)},l=h.configuration,f=function(e,t){this.bus=t,this.channel=e||l.DEFAULT_CHANNEL};f.prototype.subscribe=function(){return this.bus.subscribe({channel:this.channel,topic:1===arguments.length?arguments[0].topic:arguments[0],callback:1===arguments.length?arguments[0].callback:arguments[1]})},f.prototype.publish=function(){var e,t={};if("string"==typeof arguments[0]?(t.topic=arguments[0],t.data=arguments[1],e=arguments[2]):(t=arguments[0],e=arguments[1]),"object"!=typeof t)throw new Error("The first argument to ChannelDefinition.publish should be either an envelope object or a string topic.");t.channel=this.channel,this.bus.publish(t,e)};var p=function(e,t,i){if(3!==arguments.length)throw new Error("You must provide a channel, topic and callback when creating a SubscriptionDefinition instance.");if(0===t.length)throw new Error("Topics cannot be empty");this.channel=e,this.topic=t,this.callback=i,this.pipeline=[],this.cacheKeys=[],this._context=n},b=function(){var t;return function(n){var i=!1;return"string"==typeof n?(i=n===t,t=n):(i=e.isEqual(n,t),t=e.extend({},n)),!i}},d=function(){var t=[];return function(n){var i=!e.some(t,function(t){return e.isEqual(n,t)});return i&&t.push(n),i}};p.prototype={"catch":function(e){var t=this.callback,n=function(){try{t.apply(this,arguments)}catch(n){e(n,arguments[0])}};return this.callback=n,this},defer:function(){return this.delay(0)},disposeAfter:function(t){if("number"!=typeof t||0>=t)throw new Error("The value provided to disposeAfter (maxCalls) must be a number greater than zero.");var n=e.after(t,this.unsubscribe.bind(this));return this.pipeline.push(function(e,t,i){i(e,t),n()}),this},distinct:function(){return this.constraint(new d)},distinctUntilChanged:function(){return this.constraint(new b)},invokeSubscriber:function(e,t){if(!this.inactive){var n=this,i=n.pipeline,c=i.length,r=n._context,o=-1,s=!1;if(c){i=i.concat([n.callback]);var a=function u(e,t){o+=1,c>o?i[o].call(r,e,t,u):(n.callback.call(r,e,t),s=!0)};a(e,t,0)}else n.callback.call(r,e,t),s=!0;return s}},logError:function(){if(console){var e;e=console.warn?console.warn:console.log,this["catch"](e)}return this},once:function(){return this.disposeAfter(1)},subscribe:function(e){return this.callback=e,this},unsubscribe:function(){this.inactive||h.unsubscribe(this)},constraint:function(e){if("function"!=typeof e)throw new Error("Predicate constraint must be a function");return this.pipeline.push(function(t,n,i){e.call(this,t,n)&&i(t,n)}),this},constraints:function(t){var n=this;return e.each(t,function(e){n.constraint(e)}),n},context:function(e){return this._context=e,this},debounce:function(t,n){if("number"!=typeof t)throw new Error("Milliseconds must be a number");var i={};return!!n==!0&&(i.leading=!0,i.trailing=!1),this.pipeline.push(e.debounce(function(e,t,n){n(e,t)},t,i)),this},delay:function(e){if("number"!=typeof e)throw new Error("Milliseconds must be a number");var t=this;return t.pipeline.push(function(t,n,i){setTimeout(function(){i(t,n)},e)}),this},throttle:function(t){if("number"!=typeof t)throw new Error("Milliseconds must be a number");var n=function(e,t,n){n(e,t)};return this.pipeline.push(e.throttle(n,t)),this}};var v=(l.resolver={cache:{},regex:{},enableCache:!0,compare:function(t,n,i){var c,r,o,s=n+l.cacheKeyDelimiter+t,a=this.cache[s],u=i||{},h=this.enableCache&&!u.resolverNoCache;return a===!0?a:-1===t.indexOf("#")&&-1===t.indexOf("*")?(a=n===t,h&&(this.cache[s]=a),a):((r=this.regex[t])||(c="^"+e.map(t.split("."),function(e){var t="";return o&&(t="#"!==o?"\\.\\b":"\\b"),t+="#"===e?"[\\s\\S]*":"*"===e?"[^.]+":e,o=e,t}).join("")+"$",r=this.regex[t]=new RegExp(c)),a=r.test(n),h&&(this.cache[s]=a),a)},reset:function(){this.cache={},this.regex={}},purge:function(t){var n=this,i=l.cacheKeyDelimiter,c=function(e,c){var r=c.split(i),o=r[0],s=r[1];"undefined"!=typeof t.topic&&t.topic!==o||"undefined"!=typeof t.binding&&t.binding!==s||delete n.cache[c]},r=function(e,t){var c=t.split(i);0===h.getSubscribersFor({topic:c[0]}).length&&delete n.cache[t]};if("undefined"==typeof t)this.reset();else{var o=t.compact===!0?r:c;e.each(this.cache,o)}}},0),y=[],m=0,g=o.bind(n,"created"),w=o.bind(n,"removed");if(e.extend(h,{cache:{},subscriptions:{},wireTaps:[],ChannelDefinition:f,SubscriptionDefinition:p,channel:function(e){return new f(e,this)},addWireTap:function(e){var t=this;return t.wireTaps.push(e),function(){var n=t.wireTaps.indexOf(e);-1!==n&&t.wireTaps.splice(n,1)}},noConflict:function(){if("undefined"==typeof window||"undefined"!=typeof window&&"function"==typeof define&&define.amd)throw new Error("noConflict can only be used in browser clients which aren't using AMD modules");return t.postal=a,this},getSubscribersFor:function(t){var n=[],i=this;return e.each(i.subscriptions,function(i){e.each(i,function(i){n=n.concat(e.filter(i,s(t,l.resolver)))})}),n},publish:function(t,n){++v;var c=t.channel=t.channel||l.DEFAULT_CHANNEL,o=t.topic;t.timeStamp=new Date,this.wireTaps.length&&e.each(this.wireTaps,function(e){e(t.data,t,v)});var s=c+l.cacheKeyDelimiter+o,a=this.cache[s],u=0,h=0;if(a)e.each(a,function(e){e.invokeSubscriber(t.data,t)?h++:u++});else{var f=r(o,this.cache,s,function(e){e.invokeSubscriber(t.data,t)?h++:u++},t);e.each(this.subscriptions[c],function(t){e.each(t,f)})}0===--v&&i(),n&&n({activated:h,skipped:u})},reset:function(){this.unsubscribeFor(),l.resolver.reset(),this.subscriptions={},this.cache={}},subscribe:function(t){var n,i=this.subscriptions,c=new p(t.channel||l.DEFAULT_CHANNEL,t.topic,t.callback),o=i[c.channel],s=c.channel.length;o||(o=i[c.channel]={}),n=i[c.channel][c.topic],n||(n=i[c.channel][c.topic]=[]),n.push(c);var a=this.cache;return e.each(e.keys(a),function(e){e.substr(0,s)===c.channel&&r(e.split(l.cacheKeyDelimiter)[1],a,e)(c)}),l.enableSystemMessages&&this.publish(g(c)),c},unsubscribe:function(){for(var t,n,i,r,o=arguments.length,s=0;o>s;s++){if(t=arguments[s],t.inactive=!0,v)return void y.push(t);if(n=this.subscriptions[t.channel],i=n&&n[t.topic]){var a=i.length;for(r=0;a>r;){if(i[r]===t){i.splice(r,1);break}r+=1}if(0===i.length&&(delete n[t.topic],e.keys(n).length||delete this.subscriptions[t.channel]),t.cacheKeys&&t.cacheKeys.length)for(var u;u=t.cacheKeys.pop();)e.each(this.cache[u],c(t,u,this.cache));if("function"==typeof l.resolver.purge){var h=l.autoCompactResolver===!0?0:"number"==typeof l.autoCompactResolver?l.autoCompactResolver-1:!1;h>=0&&m===h?(l.resolver.purge({compact:!0}),m=0):h>=0&&h>m&&(m+=1)}}l.enableSystemMessages&&this.publish(w(t))}},unsubscribeFor:function(e){var t=[];this.subscriptions&&(t=this.getSubscribersFor(e),this.unsubscribe.apply(this,t))}}),t&&Object.prototype.hasOwnProperty.call(t,"__postalReady__")&&e.isArray(t.__postalReady__))for(;t.__postalReady__.length;)t.__postalReady__.shift().onReady(h);return h}); | ||
(function(e,t){"function"==typeof define&&define.amd?define(["lodash"],function(n){return t(n,e)}):"object"==typeof module&&module.exports?module.exports=t(require("lodash"),this):e.postal=t(e._,e)})(this,function(e,t,n){function i(){for(;m.length;)l.unsubscribe(m.shift())}function c(e,t,n){return function(i,c,r){i===e&&r.splice(c,1),0===r.length&&delete n[t]}}function r(e,t,n,i,c){var r=c&&c.headers||{};return function(c){var o;f.resolver.compare(c.topic,e,r)&&(r.resolverNoCache||(o=t[n]=t[n]||[],o.push(c)),c.cacheKeys.push(n),i&&i(c))}}function o(e,t){return{channel:f.SYSTEM_CHANNEL,topic:"subscription."+e,data:{event:"subscription."+e,channel:t.channel,topic:t.topic}}}function s(t,n){return"function"==typeof t?t:t?function(i){var c=0,r=0;return e.each(t,function(e,o){c+=1,("topic"===o&&n.compare(i.topic,t.topic,{resolverNoCache:!0})||"context"===o&&t.context===i._context||i[o]===t[o])&&(r+=1)}),c===r}:function(){return!0}}var a=t&&t.postal,u=t&&t._;u&&u!==e&&(e=e.noConflict());var h={DEFAULT_CHANNEL:"/",SYSTEM_CHANNEL:"postal",enableSystemMessages:!0,cacheKeyDelimiter:"|",autoCompactResolver:!1},l={configuration:e.extend({},h)},f=l.configuration,p=function(e,t){this.bus=t,this.channel=e||f.DEFAULT_CHANNEL};p.prototype.subscribe=function(){return this.bus.subscribe({channel:this.channel,topic:1===arguments.length?arguments[0].topic:arguments[0],callback:1===arguments.length?arguments[0].callback:arguments[1]})},p.prototype.publish=function(){var e,t={};if("string"==typeof arguments[0]?(t.topic=arguments[0],t.data=arguments[1],e=arguments[2]):(t=arguments[0],e=arguments[1]),"object"!=typeof t)throw new Error("The first argument to ChannelDefinition.publish should be either an envelope object or a string topic.");t.channel=this.channel,this.bus.publish(t,e)};var b=function(e,t,i){if(3!==arguments.length)throw new Error("You must provide a channel, topic and callback when creating a SubscriptionDefinition instance.");if(0===t.length)throw new Error("Topics cannot be empty");this.channel=e,this.topic=t,this.callback=i,this.pipeline=[],this.cacheKeys=[],this._context=n},d=function(){var t;return function(n){var i=!1;return"string"==typeof n?(i=n===t,t=n):(i=e.isEqual(n,t),t=e.extend({},n)),!i}},v=function(){var t=[];return function(n){var i=!e.some(t,function(t){return e.isEqual(n,t)});return i&&t.push(n),i}};b.prototype={"catch":function(e){var t=this.callback,n=function(){try{t.apply(this,arguments)}catch(n){e(n,arguments[0])}};return this.callback=n,this},defer:function(){return this.delay(0)},disposeAfter:function(t){if("number"!=typeof t||0>=t)throw new Error("The value provided to disposeAfter (maxCalls) must be a number greater than zero.");var n=e.after(t,this.unsubscribe.bind(this));return this.pipeline.push(function(e,t,i){i(e,t),n()}),this},distinct:function(){return this.constraint(new v)},distinctUntilChanged:function(){return this.constraint(new d)},invokeSubscriber:function(e,t){if(!this.inactive){var n=this,i=n.pipeline,c=i.length,r=n._context,o=-1,s=!1;if(c){i=i.concat([n.callback]);var a=function u(e,t){o+=1,c>o?i[o].call(r,e,t,u):(n.callback.call(r,e,t),s=!0)};a(e,t,0)}else n.callback.call(r,e,t),s=!0;return s}},logError:function(){if(console){var e;e=console.warn?console.warn:console.log,this["catch"](e)}return this},once:function(){return this.disposeAfter(1)},subscribe:function(e){return this.callback=e,this},unsubscribe:function(){this.inactive||l.unsubscribe(this)},constraint:function(e){if("function"!=typeof e)throw new Error("Predicate constraint must be a function");return this.pipeline.push(function(t,n,i){e.call(this,t,n)&&i(t,n)}),this},constraints:function(t){var n=this;return e.each(t,function(e){n.constraint(e)}),n},context:function(e){return this._context=e,this},debounce:function(t,n){if("number"!=typeof t)throw new Error("Milliseconds must be a number");var i={};return!!n==!0&&(i.leading=!0,i.trailing=!1),this.pipeline.push(e.debounce(function(e,t,n){n(e,t)},t,i)),this},delay:function(e){if("number"!=typeof e)throw new Error("Milliseconds must be a number");var t=this;return t.pipeline.push(function(t,n,i){setTimeout(function(){i(t,n)},e)}),this},throttle:function(t){if("number"!=typeof t)throw new Error("Milliseconds must be a number");var n=function(e,t,n){n(e,t)};return this.pipeline.push(e.throttle(n,t)),this}};var y=(f.resolver={cache:{},regex:{},enableCache:!0,compare:function(t,n,i){var c,r,o,s=n+f.cacheKeyDelimiter+t,a=this.cache[s],u=i||{},h=this.enableCache&&!u.resolverNoCache;return a===!0?a:-1===t.indexOf("#")&&-1===t.indexOf("*")?(a=n===t,h&&(this.cache[s]=a),a):((r=this.regex[t])||(c="^"+e.map(t.split("."),function(e){var t="";return o&&(t="#"!==o?"\\.\\b":"\\b"),t+="#"===e?"[\\s\\S]*":"*"===e?"[^.]+":e,o=e,t}).join("")+"$",r=this.regex[t]=new RegExp(c)),a=r.test(n),h&&(this.cache[s]=a),a)},reset:function(){this.cache={},this.regex={}},purge:function(t){var n=this,i=f.cacheKeyDelimiter,c=function(e,c){var r=c.split(i),o=r[0],s=r[1];"undefined"!=typeof t.topic&&t.topic!==o||"undefined"!=typeof t.binding&&t.binding!==s||delete n.cache[c]},r=function(e,t){var c=t.split(i);0===l.getSubscribersFor({topic:c[0]}).length&&delete n.cache[t]};if("undefined"==typeof t)this.reset();else{var o=t.compact===!0?r:c;e.each(this.cache,o)}}},0),m=[],g=0,w=o.bind(n,"created"),_=o.bind(n,"removed");if(e.extend(l,{cache:{},subscriptions:{},wireTaps:[],ChannelDefinition:p,SubscriptionDefinition:b,channel:function(e){return new p(e,this)},addWireTap:function(e){var t=this;return t.wireTaps.push(e),function(){var n=t.wireTaps.indexOf(e);-1!==n&&t.wireTaps.splice(n,1)}},noConflict:function(){if("undefined"==typeof window||"undefined"!=typeof window&&"function"==typeof define&&define.amd)throw new Error("noConflict can only be used in browser clients which aren't using AMD modules");return t.postal=a,this},getSubscribersFor:function(t){var n=[],i=this;return e.each(i.subscriptions,function(i){e.each(i,function(i){n=n.concat(e.filter(i,s(t,f.resolver)))})}),n},publish:function(t,n){++y;var c=t.channel=t.channel||f.DEFAULT_CHANNEL,o=t.topic;t.timeStamp=new Date,this.wireTaps.length&&e.each(this.wireTaps,function(e){e(t.data,t,y)});var s=c+f.cacheKeyDelimiter+o,a=this.cache[s],u=0,h=0;if(a)e.each(a,function(e){e.invokeSubscriber(t.data,t)?h++:u++});else{var l=r(o,this.cache,s,function(e){e.invokeSubscriber(t.data,t)?h++:u++},t);e.each(this.subscriptions[c],function(t){e.each(t,l)})}0===--y&&i(),n&&n({activated:h,skipped:u})},reset:function(){this.unsubscribeFor(),f.resolver.reset(),this.subscriptions={},this.cache={}},subscribe:function(t){var n,i=this.subscriptions,c=new b(t.channel||f.DEFAULT_CHANNEL,t.topic,t.callback),o=i[c.channel],s=c.channel.length;o||(o=i[c.channel]={}),n=i[c.channel][c.topic],n||(n=i[c.channel][c.topic]=[]),n.push(c);var a=this.cache;return e.each(e.keys(a),function(e){e.substr(0,s)===c.channel&&r(e.split(f.cacheKeyDelimiter)[1],a,e)(c)}),f.enableSystemMessages&&this.publish(w(c)),c},unsubscribe:function(){for(var t,n,i,r,o=arguments.length,s=0;o>s;s++){if(t=arguments[s],t.inactive=!0,y)return void m.push(t);if(n=this.subscriptions[t.channel],i=n&&n[t.topic]){var a=i.length;for(r=0;a>r;){if(i[r]===t){i.splice(r,1);break}r+=1}if(0===i.length&&(delete n[t.topic],e.keys(n).length||delete this.subscriptions[t.channel]),t.cacheKeys&&t.cacheKeys.length)for(var u;u=t.cacheKeys.pop();)e.each(this.cache[u],c(t,u,this.cache));if("function"==typeof f.resolver.purge){var h=f.autoCompactResolver===!0?0:"number"==typeof f.autoCompactResolver?f.autoCompactResolver-1:!1;h>=0&&g===h?(f.resolver.purge({compact:!0}),g=0):h>=0&&h>g&&(g+=1)}}f.enableSystemMessages&&this.publish(_(t))}},unsubscribeFor:function(e){var t=[];this.subscriptions&&(t=this.getSubscribersFor(e),this.unsubscribe.apply(this,t))}}),t&&Object.prototype.hasOwnProperty.call(t,"__postalReady__")&&e.isArray(t.__postalReady__))for(;t.__postalReady__.length;)t.__postalReady__.shift().onReady(l);return l}); |
{ | ||
"name": "postal", | ||
"description": "Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side.", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"homepage": "http://github.com/postaljs/postal.js", | ||
@@ -118,2 +118,3 @@ "repository": { | ||
"istanbul": "^0.3.13", | ||
"jquery": "^2.2.4", | ||
"jshint-stylish": "^1.0.2", | ||
@@ -123,2 +124,3 @@ "karma": "^0.12.31", | ||
"open": "~0.0.4", | ||
"postal.diagnostics": "^0.7.4", | ||
"should": "^6.0.1", | ||
@@ -125,0 +127,0 @@ "sinon": "~1.14.1" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82499
1231
23