Comparing version 0.12.2 to 0.12.3
/** | ||
* postal - Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side. | ||
* Author: Jim Cowart (http://ifandelse.com) | ||
* Version: v0.12.2 | ||
* Version: v0.12.3 | ||
* Url: http://github.com/postaljs/postal.js | ||
@@ -262,6 +262,6 @@ * License(s): MIT | ||
} | ||
var keyDelimiter = _config.cacheKeyDelimiter; | ||
var bindingsResolver = _config.resolver = { | ||
cache: {}, | ||
regex: {}, | ||
enableCache: true, | ||
compare: function compare(binding, topic, headerOptions) { | ||
@@ -271,5 +271,6 @@ var pattern; | ||
var prevSegment; | ||
var cacheKey = topic + keyDelimiter + binding; | ||
var cacheKey = topic + _config.cacheKeyDelimiter + binding; | ||
var result = (this.cache[cacheKey]); | ||
var opt = headerOptions || {}; | ||
var saveToCache = this.enableCache && !opt.resolverNoCache; | ||
// result is cached? | ||
@@ -282,3 +283,3 @@ if (result === true) { | ||
result = (topic === binding); | ||
if (!opt.resolverNoCache) { | ||
if (saveToCache) { | ||
this.cache[cacheKey] = result; | ||
@@ -308,3 +309,3 @@ } | ||
result = rgx.test(topic); | ||
if (!opt.resolverNoCache) { | ||
if (saveToCache) { | ||
this.cache[cacheKey] = result; | ||
@@ -320,2 +321,3 @@ } | ||
var self = this; | ||
var keyDelimiter = _config.cacheKeyDelimiter; | ||
var matchPredicate = function (val, key) { | ||
@@ -322,0 +324,0 @@ var split = key.split(keyDelimiter); |
/** | ||
* postal - Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side. | ||
* Author: Jim Cowart (http://ifandelse.com) | ||
* Version: v0.12.2 | ||
* Version: v0.12.3 | ||
* 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(e,t){return function(){if(console.warn||console.log){var n="Warning, the "+e+" method has been deprecated. Please use "+t+" instead.";console.warn?console.warn(n):console.log(n)}return b.prototype[t].apply(this,arguments)}}function r(){for(;x.length;)l.unsubscribe(x.shift())}function c(e,t,n){return function(i,r,c){i===e&&c.splice(r,1),0===c.length&&delete n[t]}}function s(e,t,n,i,r){var c=r&&r.headers||{};return function(r){p.resolver.compare(r.topic,e,c)&&(t.push(r),r.cacheKeys.push(n),i&&i(r))}}function o(e,t){return{channel:p.SYSTEM_CHANNEL,topic:"subscription."+e,data:{event:"subscription."+e,channel:t.channel,topic:t.topic}}}function a(t,n){return"function"==typeof t?t:t?function(i){var r=0,c=0;return e.each(t,function(e,s){r+=1,("topic"===s&&n.compare(i.topic,t.topic,{resolverNoCache:!0})||"context"===s&&t.context===i._context||i[s]===t[s])&&(c+=1)}),r===c}:function(){return!0}}var u=t.postal,h={DEFAULT_CHANNEL:"/",SYSTEM_CHANNEL:"postal",enableSystemMessages:!0,cacheKeyDelimiter:"|",autoCompactResolver:!1},l={configuration:e.extend({},h)},p=l.configuration,f=function(e,t){this.bus=t,this.channel=e||p.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=1===arguments.length?"[object String]"===Object.prototype.toString.call(arguments[0])?{topic:arguments[0]}:arguments[0]:{topic:arguments[0],data:arguments[1]};e.channel=this.channel,this.bus.publish(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 e.isString(n)?(i=n===t,t=n):(i=e.isEqual(n,t),t=e.clone(n)),!i}},g=function(){var t=[];return function(n){var i=!e.any(t,function(t){return e.isObject(n)||e.isArray(n)?e.isEqual(n,t):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(!e.isNumber(t)||0>=t)throw new Error("The value provided to disposeAfter (maxCalls) must be a number greater than zero.");var n=this,i=e.after(t,e.bind(function(){n.unsubscribe()}));return n.pipeline.push(function(e,t,n){n(e,t),i()}),n},distinct:function(){return this.constraint(new g)},distinctUntilChanged:function(){return this.constraint(new d)},invokeSubscriber:function(e,t){if(!this.inactive){var n=this,i=n.pipeline,r=i.length,c=n._context,s=-1;if(r){i=i.concat([n.callback]);var o=function a(e,t){s+=1,r>s?i[s].call(c,e,t,a):n.callback.call(c,e,t)};o(e,t,0)}else n.callback.call(c,e,t)}},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(t){if(!e.isFunction(t))throw new Error("Predicate constraint must be a function");return this.pipeline.push(function(e,n,i){t.call(this,e,n)&&i(e,n)}),this},constraints:function(t){var n=this;return e.isArray(t)&&e.each(t,function(e){n.constraint(e)}),n},context:function(e){return this._context=e,this},debounce:function(t,n){if(!e.isNumber(t))throw new Error("Milliseconds must be a number");return this.pipeline.push(e.debounce(function(e,t,n){n(e,t)},t,!!n)),this},delay:function(t){if(!e.isNumber(t))throw new Error("Milliseconds must be a number");var n=this;return n.pipeline.push(function(e,n,i){setTimeout(function(){i(e,n)},t)}),this},throttle:function(t){if(!e.isNumber(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}};for(var m=["withConstraint","withConstraints","withContext","withDebounce","withDelay","withThrottle"],v=["constraint","constraints","context","debounce","delay","throttle"],y=0;6>y;y++){var w=m[y];b.prototype[w]=i(w,v[y])}var _=p.cacheKeyDelimiter,E=(p.resolver={cache:{},regex:{},compare:function(t,n,i){var r,c,s,o=n+_+t,a=this.cache[o],u=i||{};return a===!0?a:-1===t.indexOf("#")&&-1===t.indexOf("*")?(a=n===t,u.resolverNoCache||(this.cache[o]=a),a):((c=this.regex[t])||(r="^"+e.map(t.split("."),function(e){var t="";return s&&(t="#"!==s?"\\.\\b":"\\b"),t+="#"===e?"[\\s\\S]*":"*"===e?"[^.]+":e,s=e,t}).join("")+"$",c=this.regex[t]=new RegExp(r)),a=c.test(n),u.resolverNoCache||(this.cache[o]=a),a)},reset:function(){this.cache={},this.regex={}},purge:function(t){var n=this,i=function(e,i){var r=i.split(_),c=r[0],s=r[1];"undefined"!=typeof t.topic&&t.topic!==c||"undefined"!=typeof t.binding&&t.binding!==s||delete n.cache[i]},r=function(e,t){var i=t.split(_);0===l.getSubscribersFor({topic:i[0]}).length&&delete n.cache[t]};if("undefined"==typeof t)this.reset();else{var c=t.compact===!0?r:i;e.each(this.cache,c)}}},0),x=[],C=0,S=e.bind(o,this,"created"),N=e.bind(o,this,"removed");if(e.extend(l,{cache:{},subscriptions:{},wireTaps:[],ChannelDefinition:f,SubscriptionDefinition:b,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=u,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,a(t,p.resolver)))})}),n},publish:function(t){++E;var n=t.channel=t.channel||p.DEFAULT_CHANNEL,i=t.topic;t.timeStamp=new Date,this.wireTaps.length&&e.each(this.wireTaps,function(e){e(t.data,t,E)});var c=n+p.cacheKeyDelimiter+i,o=this.cache[c];if(o)e.each(o,function(e){e.invokeSubscriber(t.data,t)});else{o=this.cache[c]=[];var a=s(i,o,c,function(e){e.invokeSubscriber(t.data,t)},t);e.each(this.subscriptions[n],function(t){e.each(t,a)})}0===--E&&r()},reset:function(){this.unsubscribeFor(),p.resolver.reset(),this.subscriptions={}},subscribe:function(t){var n,i=this.subscriptions,r=new b(t.channel||p.DEFAULT_CHANNEL,t.topic,t.callback),c=i[r.channel],o=r.channel.length;return c||(c=i[r.channel]={}),n=i[r.channel][r.topic],n||(n=i[r.channel][r.topic]=[]),n.push(r),e.each(this.cache,function(e,t){t.substr(0,o)===r.channel&&s(t.split(p.cacheKeyDelimiter)[1],e,t)(r)}),p.enableSystemMessages&&this.publish(S(r)),r},unsubscribe:function(){for(var t,n,i,r,s=arguments.length,o=0;s>o;o++){if(t=arguments[o],t.inactive=!0,E)return x.push(t),void 0;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.isEmpty(n)&&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 p.resolver.purge){var h=p.autoCompactResolver===!0?0:"number"==typeof p.autoCompactResolver?p.autoCompactResolver-1:!1;h>=0&&C===h?(p.resolver.purge({compact:!0}),C=0):h>=0&&h>C&&(C+=1)}}p.enableSystemMessages&&this.publish(N(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}); | ||
(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(e,t){return function(){if(console.warn||console.log){var n="Warning, the "+e+" method has been deprecated. Please use "+t+" instead.";console.warn?console.warn(n):console.log(n)}return b.prototype[t].apply(this,arguments)}}function r(){for(;E.length;)l.unsubscribe(E.shift())}function c(e,t,n){return function(i,r,c){i===e&&c.splice(r,1),0===c.length&&delete n[t]}}function s(e,t,n,i,r){var c=r&&r.headers||{};return function(r){p.resolver.compare(r.topic,e,c)&&(t.push(r),r.cacheKeys.push(n),i&&i(r))}}function o(e,t){return{channel:p.SYSTEM_CHANNEL,topic:"subscription."+e,data:{event:"subscription."+e,channel:t.channel,topic:t.topic}}}function a(t,n){return"function"==typeof t?t:t?function(i){var r=0,c=0;return e.each(t,function(e,s){r+=1,("topic"===s&&n.compare(i.topic,t.topic,{resolverNoCache:!0})||"context"===s&&t.context===i._context||i[s]===t[s])&&(c+=1)}),r===c}:function(){return!0}}var u=t.postal,h={DEFAULT_CHANNEL:"/",SYSTEM_CHANNEL:"postal",enableSystemMessages:!0,cacheKeyDelimiter:"|",autoCompactResolver:!1},l={configuration:e.extend({},h)},p=l.configuration,f=function(e,t){this.bus=t,this.channel=e||p.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=1===arguments.length?"[object String]"===Object.prototype.toString.call(arguments[0])?{topic:arguments[0]}:arguments[0]:{topic:arguments[0],data:arguments[1]};e.channel=this.channel,this.bus.publish(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 e.isString(n)?(i=n===t,t=n):(i=e.isEqual(n,t),t=e.clone(n)),!i}},m=function(){var t=[];return function(n){var i=!e.any(t,function(t){return e.isObject(n)||e.isArray(n)?e.isEqual(n,t):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(!e.isNumber(t)||0>=t)throw new Error("The value provided to disposeAfter (maxCalls) must be a number greater than zero.");var n=this,i=e.after(t,e.bind(function(){n.unsubscribe()}));return n.pipeline.push(function(e,t,n){n(e,t),i()}),n},distinct:function(){return this.constraint(new m)},distinctUntilChanged:function(){return this.constraint(new d)},invokeSubscriber:function(e,t){if(!this.inactive){var n=this,i=n.pipeline,r=i.length,c=n._context,s=-1;if(r){i=i.concat([n.callback]);var o=function a(e,t){s+=1,r>s?i[s].call(c,e,t,a):n.callback.call(c,e,t)};o(e,t,0)}else n.callback.call(c,e,t)}},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(t){if(!e.isFunction(t))throw new Error("Predicate constraint must be a function");return this.pipeline.push(function(e,n,i){t.call(this,e,n)&&i(e,n)}),this},constraints:function(t){var n=this;return e.isArray(t)&&e.each(t,function(e){n.constraint(e)}),n},context:function(e){return this._context=e,this},debounce:function(t,n){if(!e.isNumber(t))throw new Error("Milliseconds must be a number");return this.pipeline.push(e.debounce(function(e,t,n){n(e,t)},t,!!n)),this},delay:function(t){if(!e.isNumber(t))throw new Error("Milliseconds must be a number");var n=this;return n.pipeline.push(function(e,n,i){setTimeout(function(){i(e,n)},t)}),this},throttle:function(t){if(!e.isNumber(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}};for(var g=["withConstraint","withConstraints","withContext","withDebounce","withDelay","withThrottle"],v=["constraint","constraints","context","debounce","delay","throttle"],y=0;6>y;y++){var w=g[y];b.prototype[w]=i(w,v[y])}var _=(p.resolver={cache:{},regex:{},enableCache:!0,compare:function(t,n,i){var r,c,s,o=n+p.cacheKeyDelimiter+t,a=this.cache[o],u=i||{},h=this.enableCache&&!u.resolverNoCache;return a===!0?a:-1===t.indexOf("#")&&-1===t.indexOf("*")?(a=n===t,h&&(this.cache[o]=a),a):((c=this.regex[t])||(r="^"+e.map(t.split("."),function(e){var t="";return s&&(t="#"!==s?"\\.\\b":"\\b"),t+="#"===e?"[\\s\\S]*":"*"===e?"[^.]+":e,s=e,t}).join("")+"$",c=this.regex[t]=new RegExp(r)),a=c.test(n),h&&(this.cache[o]=a),a)},reset:function(){this.cache={},this.regex={}},purge:function(t){var n=this,i=p.cacheKeyDelimiter,r=function(e,r){var c=r.split(i),s=c[0],o=c[1];"undefined"!=typeof t.topic&&t.topic!==s||"undefined"!=typeof t.binding&&t.binding!==o||delete n.cache[r]},c=function(e,t){var r=t.split(i);0===l.getSubscribersFor({topic:r[0]}).length&&delete n.cache[t]};if("undefined"==typeof t)this.reset();else{var s=t.compact===!0?c:r;e.each(this.cache,s)}}},0),E=[],x=0,C=e.bind(o,this,"created"),S=e.bind(o,this,"removed");if(e.extend(l,{cache:{},subscriptions:{},wireTaps:[],ChannelDefinition:f,SubscriptionDefinition:b,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=u,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,a(t,p.resolver)))})}),n},publish:function(t){++_;var n=t.channel=t.channel||p.DEFAULT_CHANNEL,i=t.topic;t.timeStamp=new Date,this.wireTaps.length&&e.each(this.wireTaps,function(e){e(t.data,t,_)});var c=n+p.cacheKeyDelimiter+i,o=this.cache[c];if(o)e.each(o,function(e){e.invokeSubscriber(t.data,t)});else{o=this.cache[c]=[];var a=s(i,o,c,function(e){e.invokeSubscriber(t.data,t)},t);e.each(this.subscriptions[n],function(t){e.each(t,a)})}0===--_&&r()},reset:function(){this.unsubscribeFor(),p.resolver.reset(),this.subscriptions={}},subscribe:function(t){var n,i=this.subscriptions,r=new b(t.channel||p.DEFAULT_CHANNEL,t.topic,t.callback),c=i[r.channel],o=r.channel.length;return c||(c=i[r.channel]={}),n=i[r.channel][r.topic],n||(n=i[r.channel][r.topic]=[]),n.push(r),e.each(this.cache,function(e,t){t.substr(0,o)===r.channel&&s(t.split(p.cacheKeyDelimiter)[1],e,t)(r)}),p.enableSystemMessages&&this.publish(C(r)),r},unsubscribe:function(){for(var t,n,i,r,s=arguments.length,o=0;s>o;o++){if(t=arguments[o],t.inactive=!0,_)return E.push(t),void 0;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.isEmpty(n)&&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 p.resolver.purge){var h=p.autoCompactResolver===!0?0:"number"==typeof p.autoCompactResolver?p.autoCompactResolver-1:!1;h>=0&&x===h?(p.resolver.purge({compact:!0}),x=0):h>=0&&h>x&&(x+=1)}}p.enableSystemMessages&&this.publish(S(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": "0.12.2", | ||
"version": "0.12.3", | ||
"homepage": "http://github.com/postaljs/postal.js", | ||
@@ -6,0 +6,0 @@ "repository": { |
# Postal.js | ||
## Version 0.12.2 ([MIT](http://www.opensource.org/licenses/mit-license)) | ||
## Version 0.12.3 ([MIT](http://www.opensource.org/licenses/mit-license)) | ||
@@ -5,0 +5,0 @@ > See the [changelog](https://github.com/postaljs/postal.js/blob/master/changelog.md) for information on if the current version of postal has breaking changes compared to any older version(s) you might be using. Version 0.11+ removed the dependency on ConduitJS and significantly improved publishing performance. |
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
52207
586