mirror of
https://github.com/Hopiu/postal.js.git
synced 2026-05-19 04:21:06 +00:00
Fixed minor bug on node.js when publishing + no subscribers
This commit is contained in:
parent
314136cf4a
commit
354a3187bd
18 changed files with 157 additions and 126 deletions
|
|
@ -1,6 +1,6 @@
|
|||
# Postal.js
|
||||
|
||||
## Version 0.7.2 (Dual Licensed [MIT](http://www.opensource.org/licenses/mit-license) & [GPL](http://www.opensource.org/licenses/gpl-license))
|
||||
## Version 0.7.3 (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 a familiar "eventing-style" paradigm most JavaScript developers are already used to and extends it by providing "broker" and subscriber implementations which are more sophisticated than what you typically find in simple event delegation.
|
||||
|
|
@ -22,7 +22,7 @@ Postal.js is in good company - there are many options for <airquotes>pub/s
|
|||
|
||||
## Recent Updates (IMPORTANT)
|
||||
|
||||
Version 0.7.2 of postal has implemented a bindings resolver that aligns with how AMQP handles wildcards in topical bindings. ***Please note that this effectively inverts how postal has handled wildcards up to now***. You can still use the old version of the bindings resolve by including the `classic-resolver.js` file in your project. If you want to use the new resolver, just use postal as-is and know that "#" matches 0 or more "words" (words are period-delimited segments of topics) and "*" matches exactly one word.
|
||||
Version 0.7.3 of postal has implemented a bindings resolver that aligns with how AMQP handles wildcards in topical bindings. ***Please note that this effectively inverts how postal has handled wildcards up to now***. You can still use the old version of the bindings resolve by including the `classic-resolver.js` file in your project. If you want to use the new resolver, just use postal as-is and know that "#" matches 0 or more "words" (words are period-delimited segments of topics) and "*" matches exactly one word.
|
||||
|
||||
### Channels? WAT?
|
||||
A channel is a logical partition of topics. Conceptually, it's like a dedicated highway for a specific set of communication. At first glance it might seem like that's overkill for an environment that runs in an event loop, but it actually proves to be quite useful. Every library has architectural opinions that it either imposes or nudges you toward. Channel-oriented messaging nudges you to separate your communication by bounded context, and enables the kind of fine-tuned visibility you need into the interactions between components as your application grows.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "postal.js",
|
||||
"version": "0.7.2",
|
||||
"version": "0.7.3",
|
||||
"main": ["lib/standard/postal.min.js", "lib/standard/postal.js"],
|
||||
"dependencies": {
|
||||
"underscore": "~1.3.0"
|
||||
|
|
|
|||
|
|
@ -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.7.2
|
||||
Version 0.7.3
|
||||
*/
|
||||
(function ( root, doc, factory ) {
|
||||
if ( typeof define === "function" && define.amd ) {
|
||||
|
|
@ -279,10 +279,10 @@
|
|||
};
|
||||
},
|
||||
|
||||
changePriority: function ( subDef ) {
|
||||
changePriority : function ( subDef ) {
|
||||
var idx, found;
|
||||
if(this.subscriptions[subDef.channel] && this.subscriptions[subDef.channel][subDef.topic]) {
|
||||
this.subscriptions[subDef.channel][subDef.topic] = _.without(this.subscriptions[subDef.channel][subDef.topic], subDef);
|
||||
if ( this.subscriptions[subDef.channel] && this.subscriptions[subDef.channel][subDef.topic] ) {
|
||||
this.subscriptions[subDef.channel][subDef.topic] = _.without( this.subscriptions[subDef.channel][subDef.topic], subDef );
|
||||
idx = this.subscriptions[subDef.channel][subDef.topic].length - 1;
|
||||
for ( ; idx >= 0; idx-- ) {
|
||||
if ( this.subscriptions[subDef.channel][subDef.topic][idx].priority <= subDef.priority ) {
|
||||
|
|
@ -302,21 +302,24 @@
|
|||
tap( envelope.data, envelope );
|
||||
} );
|
||||
|
||||
_.each( this.subscriptions[envelope.channel], function ( topic ) {
|
||||
// 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( envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.onHandled();
|
||||
if ( this.subscriptions[envelope.channel] ) {
|
||||
_.each( this.subscriptions[envelope.channel], function ( topic ) {
|
||||
// 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( envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.onHandled();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
reset : function () {
|
||||
|
|
|
|||
4
example/amd/js/libs/postal/postal.min.js
vendored
4
example/amd/js/libs/postal/postal.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -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.7.2
|
||||
Version 0.7.3
|
||||
*/
|
||||
(function ( root, doc, factory ) {
|
||||
if ( typeof define === "function" && define.amd ) {
|
||||
|
|
@ -279,10 +279,10 @@
|
|||
};
|
||||
},
|
||||
|
||||
changePriority: function ( subDef ) {
|
||||
changePriority : function ( subDef ) {
|
||||
var idx, found;
|
||||
if(this.subscriptions[subDef.channel] && this.subscriptions[subDef.channel][subDef.topic]) {
|
||||
this.subscriptions[subDef.channel][subDef.topic] = _.without(this.subscriptions[subDef.channel][subDef.topic], subDef);
|
||||
if ( this.subscriptions[subDef.channel] && this.subscriptions[subDef.channel][subDef.topic] ) {
|
||||
this.subscriptions[subDef.channel][subDef.topic] = _.without( this.subscriptions[subDef.channel][subDef.topic], subDef );
|
||||
idx = this.subscriptions[subDef.channel][subDef.topic].length - 1;
|
||||
for ( ; idx >= 0; idx-- ) {
|
||||
if ( this.subscriptions[subDef.channel][subDef.topic][idx].priority <= subDef.priority ) {
|
||||
|
|
@ -302,21 +302,24 @@
|
|||
tap( envelope.data, envelope );
|
||||
} );
|
||||
|
||||
_.each( this.subscriptions[envelope.channel], function ( topic ) {
|
||||
// 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( envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.onHandled();
|
||||
if ( this.subscriptions[envelope.channel] ) {
|
||||
_.each( this.subscriptions[envelope.channel], function ( topic ) {
|
||||
// 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( envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.onHandled();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
reset : function () {
|
||||
|
|
|
|||
4
example/node/client/js/lib/postal.min.js
vendored
4
example/node/client/js/lib/postal.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -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.7.2
|
||||
Version 0.7.3
|
||||
*/
|
||||
// This is the node.js version of postal.js
|
||||
// If you need the web client lib version, go to http://github.com/ifandelse/postal.js
|
||||
|
|
@ -271,10 +271,10 @@ var localBus = {
|
|||
};
|
||||
},
|
||||
|
||||
changePriority: function ( subDef ) {
|
||||
changePriority : function ( subDef ) {
|
||||
var idx, found;
|
||||
if(this.subscriptions[subDef.channel] && this.subscriptions[subDef.channel][subDef.topic]) {
|
||||
this.subscriptions[subDef.channel][subDef.topic] = _.without(this.subscriptions[subDef.channel][subDef.topic], subDef);
|
||||
if ( this.subscriptions[subDef.channel] && this.subscriptions[subDef.channel][subDef.topic] ) {
|
||||
this.subscriptions[subDef.channel][subDef.topic] = _.without( this.subscriptions[subDef.channel][subDef.topic], subDef );
|
||||
idx = this.subscriptions[subDef.channel][subDef.topic].length - 1;
|
||||
for ( ; idx >= 0; idx-- ) {
|
||||
if ( this.subscriptions[subDef.channel][subDef.topic][idx].priority <= subDef.priority ) {
|
||||
|
|
@ -294,21 +294,24 @@ var localBus = {
|
|||
tap( envelope.data, envelope );
|
||||
} );
|
||||
|
||||
_.each( this.subscriptions[envelope.channel], function ( topic ) {
|
||||
// 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( envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.onHandled();
|
||||
if ( this.subscriptions[envelope.channel] ) {
|
||||
_.each( this.subscriptions[envelope.channel], function ( topic ) {
|
||||
// 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( envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.onHandled();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
reset : function () {
|
||||
|
|
|
|||
|
|
@ -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.7.2
|
||||
Version 0.7.3
|
||||
*/
|
||||
(function ( root, doc, factory ) {
|
||||
if ( typeof define === "function" && define.amd ) {
|
||||
|
|
@ -279,10 +279,10 @@
|
|||
};
|
||||
},
|
||||
|
||||
changePriority: function ( subDef ) {
|
||||
changePriority : function ( subDef ) {
|
||||
var idx, found;
|
||||
if(this.subscriptions[subDef.channel] && this.subscriptions[subDef.channel][subDef.topic]) {
|
||||
this.subscriptions[subDef.channel][subDef.topic] = _.without(this.subscriptions[subDef.channel][subDef.topic], subDef);
|
||||
if ( this.subscriptions[subDef.channel] && this.subscriptions[subDef.channel][subDef.topic] ) {
|
||||
this.subscriptions[subDef.channel][subDef.topic] = _.without( this.subscriptions[subDef.channel][subDef.topic], subDef );
|
||||
idx = this.subscriptions[subDef.channel][subDef.topic].length - 1;
|
||||
for ( ; idx >= 0; idx-- ) {
|
||||
if ( this.subscriptions[subDef.channel][subDef.topic][idx].priority <= subDef.priority ) {
|
||||
|
|
@ -302,21 +302,24 @@
|
|||
tap( envelope.data, envelope );
|
||||
} );
|
||||
|
||||
_.each( this.subscriptions[envelope.channel], function ( topic ) {
|
||||
// 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( envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.onHandled();
|
||||
if ( this.subscriptions[envelope.channel] ) {
|
||||
_.each( this.subscriptions[envelope.channel], function ( topic ) {
|
||||
// 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( envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.onHandled();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
reset : function () {
|
||||
|
|
|
|||
4
example/standard/js/postal.min.js
vendored
4
example/standard/js/postal.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -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.7.2
|
||||
Version 0.7.3
|
||||
*/
|
||||
(function ( root, doc, factory ) {
|
||||
if ( typeof define === "function" && define.amd ) {
|
||||
|
|
|
|||
2
lib/browser/classic-resolver.min.js
vendored
2
lib/browser/classic-resolver.min.js
vendored
|
|
@ -2,6 +2,6 @@
|
|||
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.7.2
|
||||
Version 0.7.3
|
||||
*/
|
||||
(function(e,t,n){typeof define=="function"&&define.amd?define(["postal"],function(r){return n(r,e,t)}):n(e.postal,e,t)})(this,document,function(e,t,n,r){var i={cache:{},compare:function(e,t){if(this.cache[t]&&this.cache[t][e])return!0;var n=new RegExp("^"+e.replace(/\./g,"\\.").replace(/\*/g,".*").replace(/#/g,"[A-Z,a-z,0-9]*")+"$"),r=n.test(t);return r&&(this.cache[t]||(this.cache[t]={}),this.cache[t][e]=!0),r},reset:function(){this.cache={}}};e.configuration.resolver=i})
|
||||
|
|
@ -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.7.2
|
||||
Version 0.7.3
|
||||
*/
|
||||
(function ( root, doc, factory ) {
|
||||
if ( typeof define === "function" && define.amd ) {
|
||||
|
|
@ -279,10 +279,10 @@
|
|||
};
|
||||
},
|
||||
|
||||
changePriority: function ( subDef ) {
|
||||
changePriority : function ( subDef ) {
|
||||
var idx, found;
|
||||
if(this.subscriptions[subDef.channel] && this.subscriptions[subDef.channel][subDef.topic]) {
|
||||
this.subscriptions[subDef.channel][subDef.topic] = _.without(this.subscriptions[subDef.channel][subDef.topic], subDef);
|
||||
if ( this.subscriptions[subDef.channel] && this.subscriptions[subDef.channel][subDef.topic] ) {
|
||||
this.subscriptions[subDef.channel][subDef.topic] = _.without( this.subscriptions[subDef.channel][subDef.topic], subDef );
|
||||
idx = this.subscriptions[subDef.channel][subDef.topic].length - 1;
|
||||
for ( ; idx >= 0; idx-- ) {
|
||||
if ( this.subscriptions[subDef.channel][subDef.topic][idx].priority <= subDef.priority ) {
|
||||
|
|
@ -302,21 +302,24 @@
|
|||
tap( envelope.data, envelope );
|
||||
} );
|
||||
|
||||
_.each( this.subscriptions[envelope.channel], function ( topic ) {
|
||||
// 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( envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.onHandled();
|
||||
if ( this.subscriptions[envelope.channel] ) {
|
||||
_.each( this.subscriptions[envelope.channel], function ( topic ) {
|
||||
// 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( envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.onHandled();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
reset : function () {
|
||||
|
|
|
|||
4
lib/browser/postal.min.js
vendored
4
lib/browser/postal.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -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.7.2
|
||||
Version 0.7.3
|
||||
*/
|
||||
var classicBindingsResolver = {
|
||||
cache : { },
|
||||
|
|
|
|||
|
|
@ -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.7.2
|
||||
Version 0.7.3
|
||||
*/
|
||||
// This is the node.js version of postal.js
|
||||
// If you need the web client lib version, go to http://github.com/ifandelse/postal.js
|
||||
|
|
@ -271,10 +271,10 @@ var localBus = {
|
|||
};
|
||||
},
|
||||
|
||||
changePriority: function ( subDef ) {
|
||||
changePriority : function ( subDef ) {
|
||||
var idx, found;
|
||||
if(this.subscriptions[subDef.channel] && this.subscriptions[subDef.channel][subDef.topic]) {
|
||||
this.subscriptions[subDef.channel][subDef.topic] = _.without(this.subscriptions[subDef.channel][subDef.topic], subDef);
|
||||
if ( this.subscriptions[subDef.channel] && this.subscriptions[subDef.channel][subDef.topic] ) {
|
||||
this.subscriptions[subDef.channel][subDef.topic] = _.without( this.subscriptions[subDef.channel][subDef.topic], subDef );
|
||||
idx = this.subscriptions[subDef.channel][subDef.topic].length - 1;
|
||||
for ( ; idx >= 0; idx-- ) {
|
||||
if ( this.subscriptions[subDef.channel][subDef.topic][idx].priority <= subDef.priority ) {
|
||||
|
|
@ -294,21 +294,24 @@ var localBus = {
|
|||
tap( envelope.data, envelope );
|
||||
} );
|
||||
|
||||
_.each( this.subscriptions[envelope.channel], function ( topic ) {
|
||||
// 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( envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.onHandled();
|
||||
if ( this.subscriptions[envelope.channel] ) {
|
||||
_.each( this.subscriptions[envelope.channel], function ( topic ) {
|
||||
// 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( envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.onHandled();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
reset : function () {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name" : "postal",
|
||||
"description" : "Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side.",
|
||||
"version" : "0.7.2",
|
||||
"version" : "0.7.3",
|
||||
"homepage" : "http://github.com/ifandelse/postal.js",
|
||||
"repository" : {
|
||||
"type" : "git",
|
||||
|
|
|
|||
|
|
@ -864,5 +864,15 @@ QUnit.specify( "postal.js", function () {
|
|||
assert( results.length ).equals( 10 );
|
||||
} );
|
||||
} );
|
||||
describe( "When publishing on a channel where no subscribers exist", function () {
|
||||
it( "should return expected results for MyChannel/MyTopic", function () {
|
||||
var env = postal.publish({
|
||||
channel: "NoOneIsUsingThisOne",
|
||||
topic: "This.Is.A.Lonely.Topic",
|
||||
data: "Y U NO SUBSCRIBE TO ME?"
|
||||
});
|
||||
assert( !_.isEmpty(env) ).equals( true );
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
|
@ -11,10 +11,10 @@ var localBus = {
|
|||
};
|
||||
},
|
||||
|
||||
changePriority: function ( subDef ) {
|
||||
changePriority : function ( subDef ) {
|
||||
var idx, found;
|
||||
if(this.subscriptions[subDef.channel] && this.subscriptions[subDef.channel][subDef.topic]) {
|
||||
this.subscriptions[subDef.channel][subDef.topic] = _.without(this.subscriptions[subDef.channel][subDef.topic], subDef);
|
||||
if ( this.subscriptions[subDef.channel] && this.subscriptions[subDef.channel][subDef.topic] ) {
|
||||
this.subscriptions[subDef.channel][subDef.topic] = _.without( this.subscriptions[subDef.channel][subDef.topic], subDef );
|
||||
idx = this.subscriptions[subDef.channel][subDef.topic].length - 1;
|
||||
for ( ; idx >= 0; idx-- ) {
|
||||
if ( this.subscriptions[subDef.channel][subDef.topic][idx].priority <= subDef.priority ) {
|
||||
|
|
@ -34,21 +34,24 @@ var localBus = {
|
|||
tap( envelope.data, envelope );
|
||||
} );
|
||||
|
||||
_.each( this.subscriptions[envelope.channel], function ( topic ) {
|
||||
// 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( envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.onHandled();
|
||||
if ( this.subscriptions[envelope.channel] ) {
|
||||
_.each( this.subscriptions[envelope.channel], function ( topic ) {
|
||||
// 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( envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.onHandled();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
reset : function () {
|
||||
|
|
|
|||
Loading…
Reference in a new issue