mirror of
https://github.com/Hopiu/postal.js.git
synced 2026-03-16 22:20:23 +00:00
Merge pull request #33 from dcneiner/slash-in-topic
Slash in topic prevents the topic from resolving.
This commit is contained in:
commit
3f7d51e55c
11 changed files with 60 additions and 34 deletions
|
|
@ -1,6 +1,6 @@
|
|||
# Postal.js
|
||||
|
||||
## Version 0.8.3 (Dual Licensed [MIT](http://www.opensource.org/licenses/mit-license) & [GPL](http://www.opensource.org/licenses/gpl-license))
|
||||
## Version 0.8.4 (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.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "postal.js",
|
||||
"version": "0.8.3",
|
||||
"version": "0.8.4",
|
||||
"main": ["lib/postal.min.js", "lib/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.8.3
|
||||
Version 0.8.4
|
||||
*/
|
||||
(function ( root, factory ) {
|
||||
if ( typeof module === "object" && module.exports ) {
|
||||
|
|
@ -108,7 +108,9 @@
|
|||
defer : function () {
|
||||
var fn = this.callback;
|
||||
this.callback = function ( data ) {
|
||||
setTimeout( fn, 0, data );
|
||||
setTimeout( function () {
|
||||
fn( data );
|
||||
}, 0 );
|
||||
};
|
||||
return this;
|
||||
},
|
||||
|
|
@ -207,21 +209,24 @@
|
|||
regex : {},
|
||||
|
||||
compare : function ( binding, topic ) {
|
||||
var pattern, rgx, prev, result = (this.cache[topic] && this.cache[topic][binding]);
|
||||
var pattern, rgx, prevSegment, result = (this.cache[topic] && this.cache[topic][binding]);
|
||||
if(typeof result !== "undefined") {
|
||||
return result;
|
||||
}
|
||||
if(!(rgx = this.regex[binding])) {
|
||||
pattern = "^" + _.map(binding.split('.'), function(segment) {
|
||||
var res = !!prev && prev !== "#" ? "\\.\\b" : "\\b";
|
||||
var res = "";
|
||||
if (!!prevSegment) {
|
||||
res = prevSegment !== "#" ? "\\.\\b" : "\\b";
|
||||
}
|
||||
if(segment === "#") {
|
||||
res += "[A-Z,a-z,0-9,\\.]*"
|
||||
res += "[\\s\\S]*"
|
||||
} else if (segment === "*") {
|
||||
res += "[A-Z,a-z,0-9]+"
|
||||
res += "[^.]+"
|
||||
} else {
|
||||
res += segment;
|
||||
}
|
||||
prev = segment;
|
||||
prevSegment = segment;
|
||||
return res;
|
||||
} ).join('') + "$";
|
||||
rgx = this.regex[binding] = new RegExp( pattern );
|
||||
|
|
|
|||
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.8.3
|
||||
Version 0.8.4
|
||||
*/
|
||||
(function ( root, factory ) {
|
||||
if ( typeof module === "object" && module.exports ) {
|
||||
|
|
@ -108,7 +108,9 @@
|
|||
defer : function () {
|
||||
var fn = this.callback;
|
||||
this.callback = function ( data ) {
|
||||
setTimeout( fn, 0, data );
|
||||
setTimeout( function () {
|
||||
fn( data );
|
||||
}, 0 );
|
||||
};
|
||||
return this;
|
||||
},
|
||||
|
|
@ -207,21 +209,24 @@
|
|||
regex : {},
|
||||
|
||||
compare : function ( binding, topic ) {
|
||||
var pattern, rgx, prev, result = (this.cache[topic] && this.cache[topic][binding]);
|
||||
var pattern, rgx, prevSegment, result = (this.cache[topic] && this.cache[topic][binding]);
|
||||
if(typeof result !== "undefined") {
|
||||
return result;
|
||||
}
|
||||
if(!(rgx = this.regex[binding])) {
|
||||
pattern = "^" + _.map(binding.split('.'), function(segment) {
|
||||
var res = !!prev && prev !== "#" ? "\\.\\b" : "\\b";
|
||||
var res = "";
|
||||
if (!!prevSegment) {
|
||||
res = prevSegment !== "#" ? "\\.\\b" : "\\b";
|
||||
}
|
||||
if(segment === "#") {
|
||||
res += "[A-Z,a-z,0-9,\\.]*"
|
||||
res += "[\\s\\S]*"
|
||||
} else if (segment === "*") {
|
||||
res += "[A-Z,a-z,0-9]+"
|
||||
res += "[^.]+"
|
||||
} else {
|
||||
res += segment;
|
||||
}
|
||||
prev = segment;
|
||||
prevSegment = segment;
|
||||
return res;
|
||||
} ).join('') + "$";
|
||||
rgx = this.regex[binding] = new RegExp( pattern );
|
||||
|
|
|
|||
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.8.3
|
||||
Version 0.8.4
|
||||
*/
|
||||
(function ( root, factory ) {
|
||||
if ( typeof module === "object" && module.exports ) {
|
||||
|
|
@ -209,21 +209,24 @@
|
|||
regex : {},
|
||||
|
||||
compare : function ( binding, topic ) {
|
||||
var pattern, rgx, prev, result = (this.cache[topic] && this.cache[topic][binding]);
|
||||
var pattern, rgx, prevSegment, result = (this.cache[topic] && this.cache[topic][binding]);
|
||||
if(typeof result !== "undefined") {
|
||||
return result;
|
||||
}
|
||||
if(!(rgx = this.regex[binding])) {
|
||||
pattern = "^" + _.map(binding.split('.'), function(segment) {
|
||||
var res = !!prev && prev !== "#" ? "\\.\\b" : "\\b";
|
||||
var res = "";
|
||||
if (!!prevSegment) {
|
||||
res = prevSegment !== "#" ? "\\.\\b" : "\\b";
|
||||
}
|
||||
if(segment === "#") {
|
||||
res += "[A-Z,a-z,0-9,\\.]*"
|
||||
res += "[\\s\\S]*"
|
||||
} else if (segment === "*") {
|
||||
res += "[A-Z,a-z,0-9]+"
|
||||
res += "[^.]+"
|
||||
} else {
|
||||
res += segment;
|
||||
}
|
||||
prev = segment;
|
||||
prevSegment = segment;
|
||||
return res;
|
||||
} ).join('') + "$";
|
||||
rgx = this.regex[binding] = new RegExp( pattern );
|
||||
|
|
|
|||
4
lib/postal.min.js
vendored
4
lib/postal.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -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.3",
|
||||
"version" : "0.8.4",
|
||||
"homepage" : "http://github.com/postaljs/postal.js",
|
||||
"repository" : {
|
||||
"type" : "git",
|
||||
|
|
|
|||
|
|
@ -454,6 +454,16 @@ describe( "amqpBindingsResolver", function () {
|
|||
expect( cached ).to.be.ok();
|
||||
} );
|
||||
} );
|
||||
describe( "With topic '/sample/topic' and binding '/sample/topic'", function () {
|
||||
var result = bindingsResolver.compare( "/sample/topic", "/sample/topic" ),
|
||||
cached = bindingsResolver.cache["/sample/topic"] ? bindingsResolver.cache["/sample/topic"]["/sample/topic"] : null;
|
||||
it( "Result should be true", function () {
|
||||
expect( result ).to.be.ok();
|
||||
} );
|
||||
it( "Should create a resolver cache entry", function () {
|
||||
expect( cached ).to.be.ok();
|
||||
} );
|
||||
} );
|
||||
});
|
||||
} );
|
||||
} );
|
||||
|
|
@ -3,21 +3,24 @@ var bindingsResolver = {
|
|||
regex : {},
|
||||
|
||||
compare : function ( binding, topic ) {
|
||||
var pattern, rgx, prev, result = (this.cache[topic] && this.cache[topic][binding]);
|
||||
var pattern, rgx, prevSegment, result = (this.cache[topic] && this.cache[topic][binding]);
|
||||
if(typeof result !== "undefined") {
|
||||
return result;
|
||||
}
|
||||
if(!(rgx = this.regex[binding])) {
|
||||
pattern = "^" + _.map(binding.split('.'), function(segment) {
|
||||
var res = !!prev && prev !== "#" ? "\\.\\b" : "\\b";
|
||||
var res = "";
|
||||
if (!!prevSegment) {
|
||||
res = prevSegment !== "#" ? "\\.\\b" : "\\b";
|
||||
}
|
||||
if(segment === "#") {
|
||||
res += "[A-Z,a-z,0-9,\\.]*"
|
||||
res += "[\\s\\S]*"
|
||||
} else if (segment === "*") {
|
||||
res += "[A-Z,a-z,0-9]+"
|
||||
res += "[^.]+"
|
||||
} else {
|
||||
res += segment;
|
||||
}
|
||||
prev = segment;
|
||||
prevSegment = segment;
|
||||
return res;
|
||||
} ).join('') + "$";
|
||||
rgx = this.regex[binding] = new RegExp( pattern );
|
||||
|
|
|
|||
Loading…
Reference in a new issue