Made the resolver more permissive. Fixed issue where topics starting with a / would never resolve.

This commit is contained in:
Doug Neiner 2013-04-30 21:26:48 -05:00
parent 2e1bb06735
commit f46f153982
10 changed files with 50 additions and 34 deletions

View file

@ -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.

View file

@ -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"

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.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 );

File diff suppressed because one or more lines are too long

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.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 );

File diff suppressed because one or more lines are too long

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.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

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.3",
"version" : "0.8.4",
"homepage" : "http://github.com/postaljs/postal.js",
"repository" : {
"type" : "git",

View file

@ -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 );