Updated publish implementation to remove the need for cloning the array

This commit is contained in:
Jim Cowart 2013-01-15 18:01:26 -05:00
parent 180593a88b
commit f935902df7
6 changed files with 44 additions and 38 deletions

View file

@ -1,6 +1,6 @@
# Postal.js
## Version 0.8.0 (Dual Licensed [MIT](http://www.opensource.org/licenses/mit-license) & [GPL](http://www.opensource.org/licenses/gpl-license))
## Version 0.8.1 (Dual Licensed [MIT](http://www.opensource.org/licenses/mit-license) & [GPL](http://www.opensource.org/licenses/gpl-license))
## 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-side 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.

View file

@ -1,6 +1,6 @@
{
"name": "postal.js",
"version": "0.8.0",
"version": "0.8.1",
"main": ["lib/postal.min.js", "lib/postal.js"],
"dependencies": {
"underscore": "~1.3.0"

View file

@ -2,7 +2,7 @@
postal
Author: Jim Cowart (http://freshbrewedcode.com/jimcowart)
License: Dual licensed MIT (http://www.opensource.org/licenses/mit-license) & GPL (http://www.opensource.org/licenses/gpl-license)
Version 0.8.0
Version 0.8.1
*/
(function ( root, factory ) {
if ( typeof module === "object" && module.exports ) {
@ -229,6 +229,18 @@
this.cache = {};
}
};
var fireSub = function(subDef, envelope) {
if ( postal.configuration.resolver.compare( subDef.topic, envelope.topic ) ) {
if ( _.all( subDef.constraints, function ( constraint ) {
return constraint.call( subDef.context, envelope.data, envelope );
} ) ) {
if ( typeof subDef.callback === 'function' ) {
subDef.callback.call( subDef.context, envelope.data, envelope );
}
}
}
};
var localBus = {
addWireTap : function ( callback ) {
var self = this;
@ -247,23 +259,14 @@
tap( envelope.data, envelope );
} );
if ( this.subscriptions[envelope.channel] ) {
_.each( this.subscriptions[envelope.channel], function ( subscribers ) {
// TODO: research faster ways to handle this than _.clone
var idx = 0;
while(idx < subscribers.length) {
(function(subDef){
if ( postal.configuration.resolver.compare( subDef.topic, envelope.topic ) ) {
if ( _.all( subDef.constraints, function ( constraint ) {
return constraint.call( subDef.context, envelope.data, envelope );
} ) ) {
if ( typeof subDef.callback === 'function' ) {
subDef.callback.call( subDef.context, envelope.data, envelope );
}
}
}
}(subscribers[idx++]));
_.each( this.subscriptions[envelope.channel], function ( subscribers ) {
var idx = 0, len = subscribers.length, subDef;
while(idx < len) {
if( subDef = subscribers[idx++] ){
fireSub(subDef, envelope);
}
}
} );
} );
}
return envelope;
},

4
lib/postal.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
{
"name" : "postal",
"description" : "Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side.",
"version" : "0.8.0",
"version" : "0.8.1",
"homepage" : "http://github.com/postaljs/postal.js",
"repository" : {
"type" : "git",

View file

@ -1,3 +1,15 @@
var fireSub = function(subDef, envelope) {
if ( postal.configuration.resolver.compare( subDef.topic, envelope.topic ) ) {
if ( _.all( subDef.constraints, function ( constraint ) {
return constraint.call( subDef.context, envelope.data, envelope );
} ) ) {
if ( typeof subDef.callback === 'function' ) {
subDef.callback.call( subDef.context, envelope.data, envelope );
}
}
}
};
var localBus = {
addWireTap : function ( callback ) {
var self = this;
@ -16,23 +28,14 @@ var localBus = {
tap( envelope.data, envelope );
} );
if ( this.subscriptions[envelope.channel] ) {
_.each( this.subscriptions[envelope.channel], function ( subscribers ) {
// TODO: research faster ways to handle this than _.clone
var idx = 0;
while(idx < subscribers.length) {
(function(subDef){
if ( postal.configuration.resolver.compare( subDef.topic, envelope.topic ) ) {
if ( _.all( subDef.constraints, function ( constraint ) {
return constraint.call( subDef.context, envelope.data, envelope );
} ) ) {
if ( typeof subDef.callback === 'function' ) {
subDef.callback.call( subDef.context, envelope.data, envelope );
}
}
}
}(subscribers[idx++]));
_.each( this.subscriptions[envelope.channel], function ( subscribers ) {
var idx = 0, len = subscribers.length, subDef;
while(idx < len) {
if( subDef = subscribers[idx++] ){
fireSub(subDef, envelope);
}
}
} );
} );
}
return envelope;
},