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

postal

Package Overview
Dependencies
Maintainers
1
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 0.11.2 to 0.12.0

139

lib/postal.js
/**
* postal - Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side.
* Author: Jim Cowart (http://freshbrewedcode.com/jimcowart)
* Version: v0.11.2
* Author: Jim Cowart (http://ifandelse.com)
* Version: v0.12.0
* Url: http://github.com/postaljs/postal.js

@@ -22,7 +22,17 @@ * License(s): MIT

}(this, function (_, global, undefined) {
var _postal;
var prevPostal = global.postal;
var _defaultConfig = {
DEFAULT_CHANNEL: "/",
SYSTEM_CHANNEL: "postal",
enableSystemMessages: true,
cacheKeyDelimiter: "|",
autoCompactResolver: false
};
var postal = {
configuration: _.extend({}, _defaultConfig)
};
var _config = postal.configuration;
var ChannelDefinition = function (channelName, bus) {
this.bus = bus;
this.channel = channelName || _postal.configuration.DEFAULT_CHANNEL;
this.channel = channelName || _config.DEFAULT_CHANNEL;
};

@@ -80,4 +90,5 @@ ChannelDefinition.prototype.subscribe = function () {

return _.isEqual(data, p);
} else {
return data === p;
}
return data === p;
});

@@ -170,3 +181,3 @@ if (isDistinct) {

if (!this.inactive) {
_postal.unsubscribe(this);
postal.unsubscribe(this);
}

@@ -202,5 +213,2 @@ },

}
var fn = function (data, env, next) {
next(data, env);
};
this.pipeline.push(

@@ -258,10 +266,13 @@ _.debounce(function (data, env, next) {

}
var bindingsResolver = {
var keyDelimiter = _config.cacheKeyDelimiter;
var bindingsResolver = _config.resolver = {
cache: {},
regex: {},
compare: function compare(binding, topic) {
compare: function compare(binding, topic, options) {
var pattern;
var rgx;
var prevSegment;
var result = (this.cache[topic + "-" + binding]);
var cacheKey = topic + keyDelimiter + binding;
var result = (this.cache[cacheKey]);
var opt = options || {};
// result is cached?

@@ -273,3 +284,5 @@ if (result === true) {

if (binding.indexOf("#") === -1 && binding.indexOf("*") === -1) {
result = this.cache[topic + "-" + binding] = (topic === binding);
if (!opt.preventCache) {
result = this.cache[cacheKey] = (topic === binding);
}
return result;

@@ -296,3 +309,5 @@ }

}
result = this.cache[topic + "-" + binding] = rgx.test(topic);
if (!opt.preventCache) {
result = this.cache[cacheKey] = rgx.test(topic);
}
return result;

@@ -303,2 +318,27 @@ },

this.regex = {};
},
purge: function (options) {
var self = this;
var matchPredicate = function (val, key) {
var split = key.split(keyDelimiter);
var topic = split[0];
var binding = split[1];
if ((typeof options.topic === "undefined" || options.topic === topic) && (typeof options.binding === "undefined" || options.binding === binding)) {
delete self.cache[key];
}
};
var compactPredicate = function (val, key) {
var split = key.split(keyDelimiter);
if (postal.getSubscribersFor({
topic: split[0]
}).length === 0) {
delete self.cache[key];
}
};
if (typeof options === "undefined") {
this.reset();
} else {
var handler = options.compact === true ? compactPredicate : matchPredicate;
_.each(this.cache, handler);
}
}

@@ -308,5 +348,6 @@ };

var unSubQueue = [];
var autoCompactIndex = 0;
function clearUnSubQueue() {
while (unSubQueue.length) {
_postal.unsubscribe(unSubQueue.shift());
postal.unsubscribe(unSubQueue.shift());
}

@@ -324,5 +365,5 @@ }

}
function getCacher(configuration, topic, cache, cacheKey, done) {
function getCacher(topic, cache, cacheKey, done) {
return function (subDef) {
if (configuration.resolver.compare(subDef.topic, topic)) {
if (_config.resolver.compare(subDef.topic, topic)) {
cache.push(subDef);

@@ -338,3 +379,3 @@ subDef.cacheKeys.push(cacheKey);

return {
channel: _postal.configuration.SYSTEM_CHANNEL,
channel: _config.SYSTEM_CHANNEL,
topic: "subscription." + kind,

@@ -365,3 +406,5 @@ data: {

// We use the bindings resolver to compare the options.topic to subDef.topic
(prop === "topic" && resolver.compare(sub.topic, options.topic)) || (prop === "context" && options.context === sub._context)
(prop === "topic" && resolver.compare(sub.topic, options.topic, {
preventCache: true
})) || (prop === "context" && options.context === sub._context)
// Any other potential prop/value matching outside topic & context...

@@ -376,11 +419,4 @@ || (sub[prop] === options[prop])) {

}
_postal = {
_.extend(postal, {
cache: {},
configuration: {
resolver: bindingsResolver,
DEFAULT_CHANNEL: "/",
SYSTEM_CHANNEL: "postal",
enableSystemMessages: true,
cacheKeyDelimiter: "|"
},
subscriptions: {},

@@ -415,3 +451,3 @@ wireTaps: [],

_.each(channel, function (subList) {
result = result.concat(_.filter(subList, getPredicate(options, self.configuration.resolver)));
result = result.concat(_.filter(subList, getPredicate(options, _config.resolver)));
});

@@ -423,4 +459,3 @@ });

++pubInProgress;
var configuration = this.configuration;
var channel = envelope.channel = envelope.channel || configuration.DEFAULT_CHANNEL;
var channel = envelope.channel = envelope.channel || _config.DEFAULT_CHANNEL;
var topic = envelope.topic;

@@ -433,3 +468,3 @@ envelope.timeStamp = new Date();

}
var cacheKey = channel + configuration.cacheKeyDelimiter + topic;
var cacheKey = channel + _config.cacheKeyDelimiter + topic;
var cache = this.cache[cacheKey];

@@ -439,3 +474,3 @@ if (!cache) {

var cacherFn = getCacher(
configuration, topic, cache, cacheKey, function (candidate) {
topic, cache, cacheKey, function (candidate) {
candidate.invokeSubscriber(envelope.data, envelope);

@@ -457,3 +492,3 @@ });

this.unsubscribeFor();
this.configuration.resolver.reset();
_config.resolver.reset();
this.subscriptions = {};

@@ -463,6 +498,5 @@ },

var subscriptions = this.subscriptions;
var subDef = new SubscriptionDefinition(options.channel || this.configuration.DEFAULT_CHANNEL, options.topic, options.callback);
var subDef = new SubscriptionDefinition(options.channel || _config.DEFAULT_CHANNEL, options.topic, options.callback);
var channel = subscriptions[subDef.channel];
var channelLen = subDef.channel.length;
var configuration = this.configuration;
var subs;

@@ -482,6 +516,6 @@ if (!channel) {

getCacher(
configuration, cacheKey.split(configuration.cacheKeyDelimiter)[1], list, cacheKey)(subDef);
cacheKey.split(_config.cacheKeyDelimiter)[1], list, cacheKey)(subDef);
}
}); /* istanbul ignore else */
if (this.configuration.enableSystemMessages) {
if (_config.enableSystemMessages) {
this.publish(sysCreatedMessage(subDef));

@@ -518,3 +552,9 @@ }

}
// remove SubscriptionDefinition from cache
if (topicSubs.length === 0) {
delete channelSubs[subDef.topic];
if (_.isEmpty(channelSubs)) {
delete this.subscriptions[subDef.channel];
}
}
// remove SubscriptionDefinition from postal cache
if (subDef.cacheKeys && subDef.cacheKeys.length) {

@@ -526,10 +566,16 @@ var key;

}
if (topicSubs.length === 0) {
delete channelSubs[subDef.topic];
if (_.isEmpty(channelSubs)) {
delete this.subscriptions[subDef.channel];
if (typeof _config.resolver.purge === "function") {
// check to see if relevant resolver cache entries can be purged
var autoCompact = _config.autoCompactResolver === true ? 0 : typeof _config.autoCompactResolver === "number" ? (_config.autoCompactResolver - 1) : false;
if (autoCompact >= 0 && autoCompactIndex === autoCompact) {
_config.resolver.purge({
compact: true
});
autoCompactIndex = 0;
} else if (autoCompact >= 0 && autoCompactIndex < autoCompact) {
autoCompactIndex += 1;
}
}
}
if (this.configuration.enableSystemMessages) {
if (_config.enableSystemMessages) {
this.publish(sysRemovedMessage(subDef));

@@ -546,10 +592,9 @@ }

}
};
_postal.subscriptions[_postal.configuration.SYSTEM_CHANNEL] = {};
});
if (global && Object.prototype.hasOwnProperty.call(global, "__postalReady__") && _.isArray(global.__postalReady__)) {
while (global.__postalReady__.length) {
global.__postalReady__.shift().onReady(_postal);
global.__postalReady__.shift().onReady(postal);
}
}
return _postal;
return postal;
}));
/**
* postal - Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side.
* Author: Jim Cowart (http://freshbrewedcode.com/jimcowart)
* Version: v0.11.2
* Author: Jim Cowart (http://ifandelse.com)
* Version: v0.12.0
* Url: http://github.com/postaljs/postal.js
* License(s): MIT
*/
(function(n,t){"function"==typeof define&&define.amd?define(["lodash"],function(e){return t(e,n)}):"object"==typeof module&&module.exports?module.exports=t(require("lodash"),this):n.postal=t(n._,n)})(this,function(n,t,e){function i(n,t){return function(){if(console.warn||console.log){var e="Warning, the "+n+" method has been deprecated. Please use "+t+" instead.";console.warn?console.warn(e):console.log(e)}return f.prototype[t].apply(this,arguments)}}function r(){for(;_.length;)u.unsubscribe(_.shift())}function s(n,t,e){return function(i,r,s){i===n&&s.splice(r,1),0===s.length&&delete e[t]}}function c(n,t,e,i,r){return function(s){n.resolver.compare(s.topic,t)&&(e.push(s),s.cacheKeys.push(i),r&&r(s))}}function o(n,t){return{channel:u.configuration.SYSTEM_CHANNEL,topic:"subscription."+n,data:{event:"subscription."+n,channel:t.channel,topic:t.topic}}}function a(t,e){return"function"==typeof t?t:t?function(i){var r=0,s=0;return n.each(t,function(n,c){r+=1,("topic"===c&&e.compare(i.topic,t.topic)||"context"===c&&t.context===i._context||i[c]===t[c])&&(s+=1)}),r===s}:function(){return!0}}var u,h=t.postal,l=function(n,t){this.bus=t,this.channel=n||u.configuration.DEFAULT_CHANNEL};l.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]})},l.prototype.publish=function(){var n=1===arguments.length?"[object String]"===Object.prototype.toString.call(arguments[0])?{topic:arguments[0]}:arguments[0]:{topic:arguments[0],data:arguments[1]};n.channel=this.channel,this.bus.publish(n)};var f=function(n,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=n,this.topic=t,this.callback=i,this.pipeline=[],this.cacheKeys=[],this._context=e},p=function(){var t;return function(e){var i=!1;return n.isString(e)?(i=e===t,t=e):(i=n.isEqual(e,t),t=n.clone(e)),!i}},b=function(){var t=[];return function(e){var i=!n.any(t,function(t){return n.isObject(e)||n.isArray(e)?n.isEqual(e,t):e===t});return i&&t.push(e),i}};f.prototype={"catch":function(n){var t=this.callback,e=function(){try{t.apply(this,arguments)}catch(e){n(e,arguments[0])}};return this.callback=e,this},defer:function(){return this.delay(0)},disposeAfter:function(t){if(!n.isNumber(t)||0>=t)throw new Error("The value provided to disposeAfter (maxCalls) must be a number greater than zero.");var e=this,i=n.after(t,n.bind(function(){e.unsubscribe()}));return e.pipeline.push(function(n,t,e){e(n,t),i()}),e},distinct:function(){return this.constraint(new b)},distinctUntilChanged:function(){return this.constraint(new p)},invokeSubscriber:function(n,t){if(!this.inactive){var e=this,i=e.pipeline,r=i.length,s=e._context,c=-1;if(r){i=i.concat([e.callback]);var o=function a(n,t){c+=1,r>c?i[c].call(s,n,t,a):e.callback.call(s,n,t)};o(n,t,0)}else e.callback.call(s,n,t)}},logError:function(){if(console){var n;n=console.warn?console.warn:console.log,this["catch"](n)}return this},once:function(){return this.disposeAfter(1)},subscribe:function(n){return this.callback=n,this},unsubscribe:function(){this.inactive||u.unsubscribe(this)},constraint:function(t){if(!n.isFunction(t))throw new Error("Predicate constraint must be a function");return this.pipeline.push(function(n,e,i){t.call(this,n,e)&&i(n,e)}),this},constraints:function(t){var e=this;return n.isArray(t)&&n.each(t,function(n){e.constraint(n)}),e},context:function(n){return this._context=n,this},debounce:function(t,e){if(!n.isNumber(t))throw new Error("Milliseconds must be a number");return this.pipeline.push(n.debounce(function(n,t,e){e(n,t)},t,!!e)),this},delay:function(t){if(!n.isNumber(t))throw new Error("Milliseconds must be a number");var e=this;return e.pipeline.push(function(n,e,i){setTimeout(function(){i(n,e)},t)}),this},throttle:function(t){if(!n.isNumber(t))throw new Error("Milliseconds must be a number");var e=function(n,t,e){e(n,t)};return this.pipeline.push(n.throttle(e,t)),this}};for(var d=["withConstraint","withConstraints","withContext","withDebounce","withDelay","withThrottle"],g=["constraint","constraints","context","debounce","delay","throttle"],m=0;6>m;m++){var v=d[m];f.prototype[v]=i(v,g[m])}var w={cache:{},regex:{},compare:function(t,e){var i,r,s,c=this.cache[e+"-"+t];return c===!0?c:-1===t.indexOf("#")&&-1===t.indexOf("*")?c=this.cache[e+"-"+t]=e===t:((r=this.regex[t])||(i="^"+n.map(t.split("."),function(n){var t="";return s&&(t="#"!==s?"\\.\\b":"\\b"),t+="#"===n?"[\\s\\S]*":"*"===n?"[^.]+":n,s=n,t}).join("")+"$",r=this.regex[t]=new RegExp(i)),c=this.cache[e+"-"+t]=r.test(e))},reset:function(){this.cache={},this.regex={}}},y=0,_=[],E=n.bind(o,this,"created"),S=n.bind(o,this,"removed");if(u={cache:{},configuration:{resolver:w,DEFAULT_CHANNEL:"/",SYSTEM_CHANNEL:"postal",enableSystemMessages:!0,cacheKeyDelimiter:"|"},subscriptions:{},wireTaps:[],ChannelDefinition:l,SubscriptionDefinition:f,channel:function(n){return new l(n,this)},addWireTap:function(n){var t=this;return t.wireTaps.push(n),function(){var e=t.wireTaps.indexOf(n);-1!==e&&t.wireTaps.splice(e,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=h,this},getSubscribersFor:function(t){var e=[],i=this;return n.each(i.subscriptions,function(r){n.each(r,function(r){e=e.concat(n.filter(r,a(t,i.configuration.resolver)))})}),e},publish:function(t){++y;var e=this.configuration,i=t.channel=t.channel||e.DEFAULT_CHANNEL,s=t.topic;t.timeStamp=new Date,this.wireTaps.length&&n.each(this.wireTaps,function(n){n(t.data,t,y)});var o=i+e.cacheKeyDelimiter+s,a=this.cache[o];if(a)n.each(a,function(n){n.invokeSubscriber(t.data,t)});else{a=this.cache[o]=[];var u=c(e,s,a,o,function(n){n.invokeSubscriber(t.data,t)});n.each(this.subscriptions[i],function(t){n.each(t,u)})}0===--y&&r()},reset:function(){this.unsubscribeFor(),this.configuration.resolver.reset(),this.subscriptions={}},subscribe:function(t){var e,i=this.subscriptions,r=new f(t.channel||this.configuration.DEFAULT_CHANNEL,t.topic,t.callback),s=i[r.channel],o=r.channel.length,a=this.configuration;return s||(s=i[r.channel]={}),e=i[r.channel][r.topic],e||(e=i[r.channel][r.topic]=[]),e.push(r),n.each(this.cache,function(n,t){t.substr(0,o)===r.channel&&c(a,t.split(a.cacheKeyDelimiter)[1],n,t)(r)}),this.configuration.enableSystemMessages&&this.publish(E(r)),r},unsubscribe:function(){for(var t,e,i,r,c=arguments.length,o=0;c>o;o++){if(t=arguments[o],t.inactive=!0,y)return _.push(t),void 0;if(e=this.subscriptions[t.channel],i=e&&e[t.topic]){var a=i.length;for(r=0;a>r;){if(i[r]===t){i.splice(r,1);break}r+=1}if(t.cacheKeys&&t.cacheKeys.length)for(var u;u=t.cacheKeys.pop();)n.each(this.cache[u],s(t,u,this.cache));0===i.length&&(delete e[t.topic],n.isEmpty(e)&&delete this.subscriptions[t.channel])}this.configuration.enableSystemMessages&&this.publish(S(t))}},unsubscribeFor:function(n){var t=[];this.subscriptions&&(t=this.getSubscribersFor(n),this.unsubscribe.apply(this,t))}},u.subscriptions[u.configuration.SYSTEM_CHANNEL]={},t&&Object.prototype.hasOwnProperty.call(t,"__postalReady__")&&n.isArray(t.__postalReady__))for(;t.__postalReady__.length;)t.__postalReady__.shift().onReady(u);return u});
(function(t,e){"function"==typeof define&&define.amd?define(["lodash"],function(n){return e(n,t)}):"object"==typeof module&&module.exports?module.exports=e(require("lodash"),this):t.postal=e(t._,t)})(this,function(t,e,n){function i(t,e){return function(){if(console.warn||console.log){var n="Warning, the "+t+" method has been deprecated. Please use "+e+" instead.";console.warn?console.warn(n):console.log(n)}return b.prototype[e].apply(this,arguments)}}function r(){for(;x.length;)l.unsubscribe(x.shift())}function c(t,e,n){return function(i,r,c){i===t&&c.splice(r,1),0===c.length&&delete n[e]}}function s(t,e,n,i){return function(r){p.resolver.compare(r.topic,t)&&(e.push(r),r.cacheKeys.push(n),i&&i(r))}}function o(t,e){return{channel:p.SYSTEM_CHANNEL,topic:"subscription."+t,data:{event:"subscription."+t,channel:e.channel,topic:e.topic}}}function a(e,n){return"function"==typeof e?e:e?function(i){var r=0,c=0;return t.each(e,function(t,s){r+=1,("topic"===s&&n.compare(i.topic,e.topic,{preventCache:!0})||"context"===s&&e.context===i._context||i[s]===e[s])&&(c+=1)}),r===c}:function(){return!0}}var u=e.postal,h={DEFAULT_CHANNEL:"/",SYSTEM_CHANNEL:"postal",enableSystemMessages:!0,cacheKeyDelimiter:"|",autoCompactResolver:!1},l={configuration:t.extend({},h)},p=l.configuration,f=function(t,e){this.bus=e,this.channel=t||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 t=1===arguments.length?"[object String]"===Object.prototype.toString.call(arguments[0])?{topic:arguments[0]}:arguments[0]:{topic:arguments[0],data:arguments[1]};t.channel=this.channel,this.bus.publish(t)};var b=function(t,e,i){if(3!==arguments.length)throw new Error("You must provide a channel, topic and callback when creating a SubscriptionDefinition instance.");if(0===e.length)throw new Error("Topics cannot be empty");this.channel=t,this.topic=e,this.callback=i,this.pipeline=[],this.cacheKeys=[],this._context=n},d=function(){var e;return function(n){var i=!1;return t.isString(n)?(i=n===e,e=n):(i=t.isEqual(n,e),e=t.clone(n)),!i}},g=function(){var e=[];return function(n){var i=!t.any(e,function(e){return t.isObject(n)||t.isArray(n)?t.isEqual(n,e):n===e});return i&&e.push(n),i}};b.prototype={"catch":function(t){var e=this.callback,n=function(){try{e.apply(this,arguments)}catch(n){t(n,arguments[0])}};return this.callback=n,this},defer:function(){return this.delay(0)},disposeAfter:function(e){if(!t.isNumber(e)||0>=e)throw new Error("The value provided to disposeAfter (maxCalls) must be a number greater than zero.");var n=this,i=t.after(e,t.bind(function(){n.unsubscribe()}));return n.pipeline.push(function(t,e,n){n(t,e),i()}),n},distinct:function(){return this.constraint(new g)},distinctUntilChanged:function(){return this.constraint(new d)},invokeSubscriber:function(t,e){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(t,e){s+=1,r>s?i[s].call(c,t,e,a):n.callback.call(c,t,e)};o(t,e,0)}else n.callback.call(c,t,e)}},logError:function(){if(console){var t;t=console.warn?console.warn:console.log,this["catch"](t)}return this},once:function(){return this.disposeAfter(1)},subscribe:function(t){return this.callback=t,this},unsubscribe:function(){this.inactive||l.unsubscribe(this)},constraint:function(e){if(!t.isFunction(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(e){var n=this;return t.isArray(e)&&t.each(e,function(t){n.constraint(t)}),n},context:function(t){return this._context=t,this},debounce:function(e,n){if(!t.isNumber(e))throw new Error("Milliseconds must be a number");return this.pipeline.push(t.debounce(function(t,e,n){n(t,e)},e,!!n)),this},delay:function(e){if(!t.isNumber(e))throw new Error("Milliseconds must be a number");var n=this;return n.pipeline.push(function(t,n,i){setTimeout(function(){i(t,n)},e)}),this},throttle:function(e){if(!t.isNumber(e))throw new Error("Milliseconds must be a number");var n=function(t,e,n){n(t,e)};return this.pipeline.push(t.throttle(n,e)),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(e,n,i){var r,c,s,o=n+_+e,a=this.cache[o],u=i||{};return a===!0?a:-1===e.indexOf("#")&&-1===e.indexOf("*")?(u.preventCache||(a=this.cache[o]=n===e),a):((c=this.regex[e])||(r="^"+t.map(e.split("."),function(t){var e="";return s&&(e="#"!==s?"\\.\\b":"\\b"),e+="#"===t?"[\\s\\S]*":"*"===t?"[^.]+":t,s=t,e}).join("")+"$",c=this.regex[e]=new RegExp(r)),u.preventCache||(a=this.cache[o]=c.test(n)),a)},reset:function(){this.cache={},this.regex={}},purge:function(e){var n=this,i=function(t,i){var r=i.split(_),c=r[0],s=r[1];"undefined"!=typeof e.topic&&e.topic!==c||"undefined"!=typeof e.binding&&e.binding!==s||delete n.cache[i]},r=function(t,e){var i=e.split(_);0===l.getSubscribersFor({topic:i[0]}).length&&delete n.cache[e]};if("undefined"==typeof e)this.reset();else{var c=e.compact===!0?r:i;t.each(this.cache,c)}}},0),x=[],C=0,S=t.bind(o,this,"created"),A=t.bind(o,this,"removed");if(t.extend(l,{cache:{},subscriptions:{},wireTaps:[],ChannelDefinition:f,SubscriptionDefinition:b,channel:function(t){return new f(t,this)},addWireTap:function(t){var e=this;return e.wireTaps.push(t),function(){var n=e.wireTaps.indexOf(t);-1!==n&&e.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 e.postal=u,this},getSubscribersFor:function(e){var n=[],i=this;return t.each(i.subscriptions,function(i){t.each(i,function(i){n=n.concat(t.filter(i,a(e,p.resolver)))})}),n},publish:function(e){++E;var n=e.channel=e.channel||p.DEFAULT_CHANNEL,i=e.topic;e.timeStamp=new Date,this.wireTaps.length&&t.each(this.wireTaps,function(t){t(e.data,e,E)});var c=n+p.cacheKeyDelimiter+i,o=this.cache[c];if(o)t.each(o,function(t){t.invokeSubscriber(e.data,e)});else{o=this.cache[c]=[];var a=s(i,o,c,function(t){t.invokeSubscriber(e.data,e)});t.each(this.subscriptions[n],function(e){t.each(e,a)})}0===--E&&r()},reset:function(){this.unsubscribeFor(),p.resolver.reset(),this.subscriptions={}},subscribe:function(e){var n,i=this.subscriptions,r=new b(e.channel||p.DEFAULT_CHANNEL,e.topic,e.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),t.each(this.cache,function(t,e){e.substr(0,o)===r.channel&&s(e.split(p.cacheKeyDelimiter)[1],t,e)(r)}),p.enableSystemMessages&&this.publish(S(r)),r},unsubscribe:function(){for(var e,n,i,r,s=arguments.length,o=0;s>o;o++){if(e=arguments[o],e.inactive=!0,E)return x.push(e),void 0;if(n=this.subscriptions[e.channel],i=n&&n[e.topic]){var a=i.length;for(r=0;a>r;){if(i[r]===e){i.splice(r,1);break}r+=1}if(0===i.length&&(delete n[e.topic],t.isEmpty(n)&&delete this.subscriptions[e.channel]),e.cacheKeys&&e.cacheKeys.length)for(var u;u=e.cacheKeys.pop();)t.each(this.cache[u],c(e,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(A(e))}},unsubscribeFor:function(t){var e=[];this.subscriptions&&(e=this.getSubscribersFor(t),this.unsubscribe.apply(this,e))}}),e&&Object.prototype.hasOwnProperty.call(e,"__postalReady__")&&t.isArray(e.__postalReady__))for(;e.__postalReady__.length;)e.__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.11.2",
"version": "0.12.0",
"homepage": "http://github.com/postaljs/postal.js",

@@ -10,3 +10,3 @@ "repository": {

},
"author": "Jim Cowart (http://freshbrewedcode.com/jimcowart)",
"author": "Jim Cowart (http://ifandelse.com)",
"contributors": [

@@ -13,0 +13,0 @@ {

# Postal.js
## Version 0.11.2 ([MIT](http://www.opensource.org/licenses/mit-license))
## Version 0.12.0 ([MIT](http://www.opensource.org/licenses/mit-license))
> 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.
> 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.
## What is it?
Postal.js is an in-memory message bus - very loosely inspired by [AMQP](http://www.amqp.org/) - written in JavaScript. Postal.js runs in the browser, or on the server using node.js. It takes the familiar "eventing-style" paradigm (of which most JavaScript developers are familiar) and extends it by providing "broker" and subscriber implementations which are more sophisticated than what you typically find in simple event delegation.
Postal.js is an in-memory message bus - very loosely inspired by [AMQP](http://www.amqp.org/) - written in JavaScript. Postal.js runs in the browser, or on the server using node.js. It takes the familiar "eventing-style" paradigm (of which most JavaScript developers are familiar) and extends it by providing "broker" and subscriber implementations which are more sophisticated than what you typically find in simple event emitting/aggregation.

@@ -18,4 +18,4 @@ ## Usage - at a glance

callback: function(data, envelope) {
// data is the data published by the publisher
// envelope is a wrapper around the data & contains
// `data` is the data published by the publisher.
// `envelope` is a wrapper around the data & contains
// metadata about the message like the channel, topic,

@@ -201,3 +201,3 @@ // timestamp and any other data which might have been

* run `bower install` (yep, we're using at least one thing only found on bower in the local project runner)
* run `npm run build` - then check the lib folder for the output
* run `npm run build` (this is just an alias for `gulp` at the moment, which you can also use) - then check the lib folder for the output
* To run tests & examples

@@ -204,0 +204,0 @@ * Tests are node-based: `npm test`

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