Updated publish loop to eliminate need for clone

This commit is contained in:
Jim Cowart 2013-01-15 16:17:12 -05:00
parent b0461a54b4
commit 180593a88b
4 changed files with 32 additions and 26 deletions

View file

@ -1,5 +1,5 @@
{
"anvil.uglify" : {},
"anvil.uglify" : { "all" :true },
"anvil.http": {
"paths": {
"/": "./"

View file

@ -247,19 +247,22 @@
tap( envelope.data, envelope );
} );
if ( this.subscriptions[envelope.channel] ) {
_.each( this.subscriptions[envelope.channel], function ( topic ) {
_.each( this.subscriptions[envelope.channel], function ( subscribers ) {
// TODO: research faster ways to handle this than _.clone
_.each( _.clone( topic ), 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 );
}
}
}
} );
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++]));
}
} );
}
return envelope;

2
lib/postal.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -16,19 +16,22 @@ var localBus = {
tap( envelope.data, envelope );
} );
if ( this.subscriptions[envelope.channel] ) {
_.each( this.subscriptions[envelope.channel], function ( topic ) {
_.each( this.subscriptions[envelope.channel], function ( subscribers ) {
// TODO: research faster ways to handle this than _.clone
_.each( _.clone( topic ), 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 );
}
}
}
} );
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++]));
}
} );
}
return envelope;