Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postal

Package Overview
Dependencies
Maintainers
3
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postal - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

4

changelog.md

@@ -0,1 +1,5 @@

## v1.0.9
* Merged #148 - Updated to lodash 4.x
* Merged #128 - Remove unused bower.json version prop
## v1.0.8

@@ -2,0 +6,0 @@ * Fixed #136, where `global` was undefined when setting `prevPostal` for noConflict situations.

/**
* postal - Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side.
* Author: Jim Cowart (http://ifandelse.com)
* Version: v1.0.8
* Version: v1.0.9
* Url: http://github.com/postaljs/postal.js

@@ -249,2 +249,10 @@ * License(s): MIT

}
var options = {};
if ( !!immediate === true ) {
options.leading = true;
options.trailing = false;
}
this.pipeline.push(

@@ -255,3 +263,3 @@ _.debounce( function( data, env, next ) {

milliseconds,
!!immediate
options
)

@@ -258,0 +266,0 @@ );

/**
* postal - Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side.
* Author: Jim Cowart (http://ifandelse.com)
* Version: v1.0.8
* Version: v1.0.9
* Url: http://github.com/postaljs/postal.js

@@ -272,2 +272,10 @@ * License(s): MIT

}
var options = {};
if ( !!immediate === true ) {
options.leading = true;
options.trailing = false;
}
this.pipeline.push(

@@ -278,3 +286,3 @@ _.debounce( function( data, env, next ) {

milliseconds,
!!immediate
options
)

@@ -281,0 +289,0 @@ );

4

lib/postal.lodash.min.js
/**
* postal - Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side.
* Author: Jim Cowart (http://ifandelse.com)
* Version: v1.0.8
* Version: v1.0.9
* Url: http://github.com/postaljs/postal.js
* License(s): MIT
*/
(function(e,t){var n=require("lodash/internal/createPartialWrapper"),i={after:require("lodash/function/after"),any:require("lodash/internal/arraySome"),bind:function(e,t,i){return n(e,33,t,[i])},debounce:require("lodash/function/debounce"),each:require("lodash/internal/createForEach")(require("lodash/internal/arrayEach"),require("lodash/internal/baseEach")),extend:require("lodash/internal/baseAssign"),filter:require("lodash/internal/arrayFilter"),isEqual:require("lodash/lang/isEqual"),keys:require("lodash/object/keys"),map:require("lodash/internal/arrayMap"),throttle:require("lodash/function/throttle")};"function"==typeof define&&define.amd?define(function(){return t(i,e)}):"object"==typeof module&&module.exports?module.exports=t(i,this):e.postal=t(i,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(;_.length;)l.unsubscribe(_.shift())}function c(e,t,n){return function(i,r,c){i===e&&c.splice(r,1),0===c.length&&delete n[t]}}function o(e,t,n,i,r){var c=r&&r.headers||{};return function(r){var o;f.resolver.compare(r.topic,e,c)&&(c.resolverNoCache||(o=t[n]=t[n]||[],o.push(r)),r.cacheKeys.push(n),i&&i(r))}}function s(e,t){return{channel:f.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,o){r+=1,("topic"===o&&n.compare(i.topic,t.topic,{resolverNoCache:!0})||"context"===o&&t.context===i._context||i[o]===t[o])&&(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)},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.any(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=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 v)},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,o=-1,s=!1;if(r){i=i.concat([n.callback]);var a=function u(e,t){o+=1,r>o?i[o].call(c,e,t,u):(n.callback.call(c,e,t),s=!0)};a(e,t,0)}else n.callback.call(c,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");return this.pipeline.push(e.debounce(function(e,t,n){n(e,t)},t,!!n)),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}};for(var g=["withConstraint","withConstraints","withContext","withDebounce","withDelay","withThrottle"],m=["constraint","constraints","context","debounce","delay","throttle"],y=0;6>y;y++){var w=g[y];b.prototype[w]=i(w,m[y])}var E=(f.resolver={cache:{},regex:{},enableCache:!0,compare:function(t,n,i){var r,c,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):((c=this.regex[t])||(r="^"+e.map(t.split("."),function(e){var t="";return o&&(t="#"!==o?"\\.\\b":"\\b"),t+="#"===e?"[\\s\\S]*":"*"===e?"[^.]+":e,o=e,t}).join("")+"$",c=this.regex[t]=new RegExp(r)),a=c.test(n),h&&(this.cache[s]=a),a)},reset:function(){this.cache={},this.regex={}},purge:function(t){var n=this,i=f.cacheKeyDelimiter,r=function(e,r){var c=r.split(i),o=c[0],s=c[1];"undefined"!=typeof t.topic&&t.topic!==o||"undefined"!=typeof t.binding&&t.binding!==s||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 o=t.compact===!0?c:r;e.each(this.cache,o)}}},0),_=[],x=0,C=e.bind(s,this,"created"),k=e.bind(s,this,"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=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,f.resolver)))})}),n},publish:function(t,n){++E;var i=t.channel=t.channel||f.DEFAULT_CHANNEL,c=t.topic;t.timeStamp=new Date,this.wireTaps.length&&e.each(this.wireTaps,function(e){e(t.data,t,E)});var s=i+f.cacheKeyDelimiter+c,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=o(c,this.cache,s,function(e){e.invokeSubscriber(t.data,t)?h++:u++},t);e.each(this.subscriptions[i],function(t){e.each(t,l)})}0===--E&&r(),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,r=new b(t.channel||f.DEFAULT_CHANNEL,t.topic,t.callback),c=i[r.channel],s=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(e.keys(this.cache),function(e){e.substr(0,s)===r.channel&&o(e.split(f.cacheKeyDelimiter)[1],this.cache,e)(r)},this),f.enableSystemMessages&&this.publish(C(r)),r},unsubscribe:function(){for(var t,n,i,r,o=arguments.length,s=0;o>s;s++){if(t=arguments[s],t.inactive=!0,E)return void _.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&&x===h?(f.resolver.purge({compact:!0}),x=0):h>=0&&h>x&&(x+=1)}}f.enableSystemMessages&&this.publish(k(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){var n=require("lodash/internal/createPartialWrapper"),i={after:require("lodash/function/after"),any:require("lodash/internal/arraySome"),bind:function(e,t,i){return n(e,33,t,[i])},debounce:require("lodash/function/debounce"),each:require("lodash/internal/createForEach")(require("lodash/internal/arrayEach"),require("lodash/internal/baseEach")),extend:require("lodash/internal/baseAssign"),filter:require("lodash/internal/arrayFilter"),isEqual:require("lodash/lang/isEqual"),keys:require("lodash/object/keys"),map:require("lodash/internal/arrayMap"),throttle:require("lodash/function/throttle")};"function"==typeof define&&define.amd?define(function(){return t(i,e)}):"object"==typeof module&&module.exports?module.exports=t(i,this):e.postal=t(i,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(;_.length;)l.unsubscribe(_.shift())}function c(e,t,n){return function(i,r,c){i===e&&c.splice(r,1),0===c.length&&delete n[t]}}function o(e,t,n,i,r){var c=r&&r.headers||{};return function(r){var o;f.resolver.compare(r.topic,e,c)&&(c.resolverNoCache||(o=t[n]=t[n]||[],o.push(r)),r.cacheKeys.push(n),i&&i(r))}}function s(e,t){return{channel:f.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,o){r+=1,("topic"===o&&n.compare(i.topic,t.topic,{resolverNoCache:!0})||"context"===o&&t.context===i._context||i[o]===t[o])&&(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)},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.any(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=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 v)},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,o=-1,s=!1;if(r){i=i.concat([n.callback]);var a=function u(e,t){o+=1,r>o?i[o].call(c,e,t,u):(n.callback.call(c,e,t),s=!0)};a(e,t,0)}else n.callback.call(c,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}};for(var y=["withConstraint","withConstraints","withContext","withDebounce","withDelay","withThrottle"],g=["constraint","constraints","context","debounce","delay","throttle"],m=0;6>m;m++){var w=y[m];b.prototype[w]=i(w,g[m])}var E=(f.resolver={cache:{},regex:{},enableCache:!0,compare:function(t,n,i){var r,c,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):((c=this.regex[t])||(r="^"+e.map(t.split("."),function(e){var t="";return o&&(t="#"!==o?"\\.\\b":"\\b"),t+="#"===e?"[\\s\\S]*":"*"===e?"[^.]+":e,o=e,t}).join("")+"$",c=this.regex[t]=new RegExp(r)),a=c.test(n),h&&(this.cache[s]=a),a)},reset:function(){this.cache={},this.regex={}},purge:function(t){var n=this,i=f.cacheKeyDelimiter,r=function(e,r){var c=r.split(i),o=c[0],s=c[1];"undefined"!=typeof t.topic&&t.topic!==o||"undefined"!=typeof t.binding&&t.binding!==s||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 o=t.compact===!0?c:r;e.each(this.cache,o)}}},0),_=[],x=0,C=e.bind(s,this,"created"),k=e.bind(s,this,"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=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,f.resolver)))})}),n},publish:function(t,n){++E;var i=t.channel=t.channel||f.DEFAULT_CHANNEL,c=t.topic;t.timeStamp=new Date,this.wireTaps.length&&e.each(this.wireTaps,function(e){e(t.data,t,E)});var s=i+f.cacheKeyDelimiter+c,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=o(c,this.cache,s,function(e){e.invokeSubscriber(t.data,t)?h++:u++},t);e.each(this.subscriptions[i],function(t){e.each(t,l)})}0===--E&&r(),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,r=new b(t.channel||f.DEFAULT_CHANNEL,t.topic,t.callback),c=i[r.channel],s=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(e.keys(this.cache),function(e){e.substr(0,s)===r.channel&&o(e.split(f.cacheKeyDelimiter)[1],this.cache,e)(r)},this),f.enableSystemMessages&&this.publish(C(r)),r},unsubscribe:function(){for(var t,n,i,r,o=arguments.length,s=0;o>s;s++){if(t=arguments[s],t.inactive=!0,E)return void _.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&&x===h?(f.resolver.purge({compact:!0}),x=0):h>=0&&h>x&&(x+=1)}}f.enableSystemMessages&&this.publish(k(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});
/**
* postal - Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side.
* Author: Jim Cowart (http://ifandelse.com)
* Version: v1.0.8
* Version: v1.0.9
* 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(;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){var s;f.resolver.compare(r.topic,e,c)&&(c.resolverNoCache||(s=t[n]=t[n]||[],s.push(r)),r.cacheKeys.push(n),i&&i(r))}}function o(e,t){return{channel:f.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&&t.postal,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.any(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=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 v)},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,o=!1;if(r){i=i.concat([n.callback]);var a=function u(e,t){s+=1,r>s?i[s].call(c,e,t,u):(n.callback.call(c,e,t),o=!0)};a(e,t,0)}else n.callback.call(c,e,t),o=!0;return o}},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");return this.pipeline.push(e.debounce(function(e,t,n){n(e,t)},t,!!n)),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}};for(var g=["withConstraint","withConstraints","withContext","withDebounce","withDelay","withThrottle"],m=["constraint","constraints","context","debounce","delay","throttle"],y=0;6>y;y++){var w=g[y];b.prototype[w]=i(w,m[y])}var _=(f.resolver={cache:{},regex:{},enableCache:!0,compare:function(t,n,i){var r,c,s,o=n+f.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=f.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=[],C=0,x=e.bind(o,this,"created"),k=e.bind(o,this,"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=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,f.resolver)))})}),n},publish:function(t,n){++_;var i=t.channel=t.channel||f.DEFAULT_CHANNEL,c=t.topic;t.timeStamp=new Date,this.wireTaps.length&&e.each(this.wireTaps,function(e){e(t.data,t,_)});var o=i+f.cacheKeyDelimiter+c,a=this.cache[o],u=0,h=0;if(a)e.each(a,function(e){e.invokeSubscriber(t.data,t)?h++:u++});else{var l=s(c,this.cache,o,function(e){e.invokeSubscriber(t.data,t)?h++:u++},t);e.each(this.subscriptions[i],function(t){e.each(t,l)})}0===--_&&r(),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,r=new b(t.channel||f.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(e.keys(this.cache),function(e){e.substr(0,o)===r.channel&&s(e.split(f.cacheKeyDelimiter)[1],this.cache,e)(r)},this),f.enableSystemMessages&&this.publish(x(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 void E.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&&C===h?(f.resolver.purge({compact:!0}),C=0):h>=0&&h>C&&(C+=1)}}f.enableSystemMessages&&this.publish(k(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 c(){for(;E.length;)l.unsubscribe(E.shift())}function r(e,t,n){return function(i,c,r){i===e&&r.splice(c,1),0===r.length&&delete n[t]}}function o(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 s(e,t){return{channel:f.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 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 u=t&&t.postal,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.any(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=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 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}};for(var y=["withConstraint","withConstraints","withContext","withDebounce","withDelay","withThrottle"],g=["constraint","constraints","context","debounce","delay","throttle"],w=0;6>w;w++){var m=y[w];b.prototype[m]=i(m,g[w])}var _=(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),E=[],C=0,x=e.bind(s,this,"created"),k=e.bind(s,this,"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=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,f.resolver)))})}),n},publish:function(t,n){++_;var i=t.channel=t.channel||f.DEFAULT_CHANNEL,r=t.topic;t.timeStamp=new Date,this.wireTaps.length&&e.each(this.wireTaps,function(e){e(t.data,t,_)});var s=i+f.cacheKeyDelimiter+r,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=o(r,this.cache,s,function(e){e.invokeSubscriber(t.data,t)?h++:u++},t);e.each(this.subscriptions[i],function(t){e.each(t,l)})}0===--_&&c(),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),r=i[c.channel],s=c.channel.length;return r||(r=i[c.channel]={}),n=i[c.channel][c.topic],n||(n=i[c.channel][c.topic]=[]),n.push(c),e.each(e.keys(this.cache),function(e){e.substr(0,s)===c.channel&&o(e.split(f.cacheKeyDelimiter)[1],this.cache,e)(c)},this),f.enableSystemMessages&&this.publish(x(c)),c},unsubscribe:function(){for(var t,n,i,c,o=arguments.length,s=0;o>s;s++){if(t=arguments[s],t.inactive=!0,_)return void E.push(t);if(n=this.subscriptions[t.channel],i=n&&n[t.topic]){var a=i.length;for(c=0;a>c;){if(i[c]===t){i.splice(c,1);break}c+=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],r(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&&C===h?(f.resolver.purge({compact:!0}),C=0):h>=0&&h>C&&(C+=1)}}f.enableSystemMessages&&this.publish(k(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": "1.0.8",
"version": "1.0.9",
"homepage": "http://github.com/postaljs/postal.js",

@@ -66,2 +66,6 @@ "repository": {

"url": "http://derickbailey.com/"
},
{
"name": "Kamil Biela",
"url": "https://github.com/kamilbiela"
}

@@ -93,3 +97,3 @@ ],

"dependencies": {
"lodash": "3.x"
"lodash": "4.x"
},

@@ -96,0 +100,0 @@ "devDependencies": {

@@ -5,3 +5,3 @@ # Postal.js

## Version 1.0.8 ([MIT](http://www.opensource.org/licenses/mit-license))
## Version 1.0.9 ([MIT](http://www.opensource.org/licenses/mit-license))

@@ -8,0 +8,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. Version 1.0+ added an optional embedded-and-customized-lodash build.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc