2012-09-23 03:43:40 +00:00
|
|
|
/*
|
|
|
|
|
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.1
|
|
|
|
|
*/
|
2012-08-28 16:06:19 +00:00
|
|
|
var classicBindingsResolver = {
|
2012-04-21 04:56:40 +00:00
|
|
|
cache : { },
|
2011-09-12 21:49:21 +00:00
|
|
|
|
2012-04-21 04:56:40 +00:00
|
|
|
compare : function ( binding, topic ) {
|
|
|
|
|
if ( this.cache[topic] && this.cache[topic][binding] ) {
|
2012-03-22 05:34:53 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// binding.replace(/\./g,"\\.") // escape actual periods
|
|
|
|
|
// .replace(/\*/g, ".*") // asterisks match any value
|
|
|
|
|
// .replace(/#/g, "[A-Z,a-z,0-9]*"); // hash matches any alpha-numeric 'word'
|
2012-04-21 04:56:40 +00:00
|
|
|
var rgx = new RegExp( "^" + binding.replace( /\./g, "\\." ).replace( /\*/g, ".*" ).replace( /#/g, "[A-Z,a-z,0-9]*" ) + "$" ),
|
|
|
|
|
result = rgx.test( topic );
|
|
|
|
|
if ( result ) {
|
|
|
|
|
if ( !this.cache[topic] ) {
|
2012-03-22 05:34:53 +00:00
|
|
|
this.cache[topic] = {};
|
|
|
|
|
}
|
|
|
|
|
this.cache[topic][binding] = true;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2012-04-20 05:53:46 +00:00
|
|
|
},
|
|
|
|
|
|
2012-04-21 04:56:40 +00:00
|
|
|
reset : function () {
|
2012-04-20 05:53:46 +00:00
|
|
|
this.cache = {};
|
2012-03-22 05:34:53 +00:00
|
|
|
}
|
2011-09-10 13:43:19 +00:00
|
|
|
};
|
2012-08-28 16:06:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
configure: function(postal) {
|
|
|
|
|
postal.configuration.resolver = classicBindingsResolver;
|
|
|
|
|
return postal;
|
|
|
|
|
}
|
|
|
|
|
};
|