diff --git a/build-all.sh b/build-all.sh new file mode 100755 index 0000000..338b9fc --- /dev/null +++ b/build-all.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +anvil -b build-browser.json +anvil -b build-browser-diags.json +anvil -b build-node.json +anvil -b build-node-diags.json \ No newline at end of file diff --git a/build-browser-diags.json b/build-browser-diags.json new file mode 100644 index 0000000..3dfc2f7 --- /dev/null +++ b/build-browser-diags.json @@ -0,0 +1,8 @@ +{ + "source": "src/diags", + "output": "build/browser", + "lint": {}, + "uglify": {}, + "gzip": {}, + "extensions": { "uglify": "min", "gzip": "gz" } +} \ No newline at end of file diff --git a/build-browser.json b/build-browser.json new file mode 100644 index 0000000..8b232cf --- /dev/null +++ b/build-browser.json @@ -0,0 +1,12 @@ +{ + "source": "src/main", + "output": "build/browser", + "lint": {}, + "uglify": {}, + "gzip": {}, + "extensions": { "uglify": "min", "gzip": "gz" }, + "wrap": { + "prefix": "(function(global, undefined) {", + "suffix": "global.postal = postal; })(window);" + } +} \ No newline at end of file diff --git a/build-node-diags.json b/build-node-diags.json new file mode 100644 index 0000000..503ca37 --- /dev/null +++ b/build-node-diags.json @@ -0,0 +1,9 @@ +{ + "source": "src/diags", + "output": "build/node", + "lint": {}, + "wrap": { + "prefix": "module.exports = function(postal) {", + "suffix": "};" + } +} \ No newline at end of file diff --git a/build-node.json b/build-node.json new file mode 100644 index 0000000..100c504 --- /dev/null +++ b/build-node.json @@ -0,0 +1,9 @@ +{ + "source": "src/main", + "output": "build/node", + "lint": {}, + "wrap": { + "prefix": "", + "suffix": "exports.postal = postal;" + } +} \ No newline at end of file diff --git a/build/boilerplate/browser_footer.txt b/build/boilerplate/browser_footer.txt deleted file mode 100644 index e4a790e..0000000 --- a/build/boilerplate/browser_footer.txt +++ /dev/null @@ -1,4 +0,0 @@ - -global.postal = postal; - -})(window); \ No newline at end of file diff --git a/build/boilerplate/browser_header.txt b/build/boilerplate/browser_header.txt deleted file mode 100644 index da1b5f5..0000000 --- a/build/boilerplate/browser_header.txt +++ /dev/null @@ -1,2 +0,0 @@ -(function(global, undefined) { - diff --git a/build/boilerplate/generic_closure_footer.txt b/build/boilerplate/generic_closure_footer.txt deleted file mode 100644 index 4da3b87..0000000 --- a/build/boilerplate/generic_closure_footer.txt +++ /dev/null @@ -1,2 +0,0 @@ - -})(window); \ No newline at end of file diff --git a/build/boilerplate/generic_closure_header.txt b/build/boilerplate/generic_closure_header.txt deleted file mode 100644 index da1b5f5..0000000 --- a/build/boilerplate/generic_closure_header.txt +++ /dev/null @@ -1,2 +0,0 @@ -(function(global, undefined) { - diff --git a/build/boilerplate/node_footer.txt b/build/boilerplate/node_footer.txt deleted file mode 100644 index 76ff0ee..0000000 --- a/build/boilerplate/node_footer.txt +++ /dev/null @@ -1,2 +0,0 @@ - -exports.postal = postal; \ No newline at end of file diff --git a/build/output/browser/postal.diagnostics.js b/build/browser/postal.diagnostics.js similarity index 100% rename from build/output/browser/postal.diagnostics.js rename to build/browser/postal.diagnostics.js diff --git a/build/browser/postal.diagnostics.min.gz.js b/build/browser/postal.diagnostics.min.gz.js new file mode 100644 index 0000000..7de6660 Binary files /dev/null and b/build/browser/postal.diagnostics.min.gz.js differ diff --git a/build/browser/postal.diagnostics.min.js b/build/browser/postal.diagnostics.min.js new file mode 100644 index 0000000..79aa9d8 --- /dev/null +++ b/build/browser/postal.diagnostics.min.js @@ -0,0 +1 @@ +postal.addWireTap(function(a){if(!JSON)throw"This browser or environment does provide JSON support";try{console.log(JSON.stringify(a))}catch(b){console.log("Unable to parse data to JSON: "+b)}}) \ No newline at end of file diff --git a/build/output/browser/postal.js b/build/browser/postal.js similarity index 98% rename from build/output/browser/postal.js rename to build/browser/postal.js index bac9bb4..84daced 100644 --- a/build/output/browser/postal.js +++ b/build/browser/postal.js @@ -1,16 +1,16 @@ +(function(global, undefined) { /* postal.js Author: Jim Cowart License: Dual licensed MIT (http://www.opensource.org/licenses/mit-license) & GPL (http://www.opensource.org/licenses/gpl-license) - Version 0.1.0 + Version 0.3.0 */ - -(function(global, undefined) { var DEFAULT_EXCHANGE = "/", DEFAULT_PRIORITY = 50, DEFAULT_DISPOSEAFTER = 0, NO_OP = function() { }; + var DistinctPredicate = function() { var previous; return function(data) { @@ -26,6 +26,7 @@ var DistinctPredicate = function() { return !eq; }; }; + var ChannelDefinition = function(exchange, topic) { this.exchange = exchange; this.topic = topic; @@ -44,9 +45,10 @@ ChannelDefinition.prototype = { topic: this.topic, data: data, timeStamp: new Date() - }) + }); } }; + var SubscriptionDefinition = function(exchange, topic, callback) { this.exchange = exchange; this.topic = topic; @@ -55,7 +57,7 @@ var SubscriptionDefinition = function(exchange, topic, callback) { this.constraints = []; this.maxCalls = DEFAULT_DISPOSEAFTER; this.onHandled = NO_OP; - this.context = null + this.context = null; }; SubscriptionDefinition.prototype = { @@ -159,6 +161,7 @@ SubscriptionDefinition.prototype = { return this; } }; + var bindingsResolver = { cache: { }, @@ -183,6 +186,7 @@ var bindingsResolver = { .replace(/#/g, "[A-Z,a-z,0-9]*"); // hash matches any alpha-numeric 'word' } }; + var localBus = { subscriptions: {}, @@ -263,6 +267,7 @@ var localBus = { }; } }; + var postal = { configuration: { bus: localBus, @@ -279,7 +284,5 @@ var postal = { this.configuration.bus.addWireTap(callback); } }; - -global.postal = postal; - -})(window); \ No newline at end of file + +global.postal = postal; })(window); \ No newline at end of file diff --git a/build/browser/postal.min.gz.js b/build/browser/postal.min.gz.js new file mode 100644 index 0000000..c773982 Binary files /dev/null and b/build/browser/postal.min.gz.js differ diff --git a/build/browser/postal.min.js b/build/browser/postal.min.js new file mode 100644 index 0000000..53989f5 --- /dev/null +++ b/build/browser/postal.min.js @@ -0,0 +1 @@ +(function(a,b){var c="/",d=50,e=0,f=function(){},g=function(){var a;return function(b){var c=!1;return _.isString(b)?(c=b===a,a=b):(c=_.isEqual(b,a),a=_.clone(b)),!c}},h=function(a,b){this.exchange=a,this.topic=b};h.prototype={subscribe:function(a){var b=new i(this.exchange,this.topic,a);return l.configuration.bus.subscribe(b),b},publish:function(a){l.configuration.bus.publish({exchange:this.exchange,topic:this.topic,data:a,timeStamp:new Date})}};var i=function(a,b,c){this.exchange=a,this.topic=b,this.callback=c,this.priority=d,this.constraints=[],this.maxCalls=e,this.onHandled=f,this.context=null};i.prototype={unsubscribe:function(){l.configuration.bus.unsubscribe(this)},defer:function(){var a=this.callback;return this.callback=function(b){setTimeout(a,0,b)},this},disposeAfter:function(a){if(_.isNaN(a)||a<=0)throw"The value provided to disposeAfter (maxCalls) must be a number greater than zero.";var b=this.onHandled,c=_.after(a,_.bind(function(){this.unsubscribe(this)},this));return this.onHandled=function(){b.apply(this.context,arguments),c()},this},ignoreDuplicates:function(){return this.withConstraint(new g),this},whenHandledThenExecute:function(a){if(!_.isFunction(a))throw"Value provided to 'whenHandledThenExecute' must be a function";return this.onHandled=a,this},withConstraint:function(a){if(!_.isFunction(a))throw"Predicate constraint must be a function";return this.constraints.push(a),this},withConstraints:function(a){var b=this;return _.isArray(a)&&_.each(a,function(a){b.withConstraint(a)}),b},withContext:function(a){return this.context=a,this},withDebounce:function(a){if(_.isNaN(a))throw"Milliseconds must be a number";var b=this.callback;return this.callback=_.debounce(b,a),this},withDelay:function(a){if(_.isNaN(a))throw"Milliseconds must be a number";var b=this.callback;return this.callback=function(c){setTimeout(b,a,c)},this},withPriority:function(a){if(_.isNaN(a))throw"Priority must be a number";return this.priority=a,this},withThrottle:function(a){if(_.isNaN(a))throw"Milliseconds must be a number";var b=this.callback;return this.callback=_.throttle(b,a),this}};var j={cache:{},compare:function(a,b){if(this.cache[b]&&this.cache[b][a])return!0;var c=new RegExp("^"+this.regexify(a)+"$"),d=c.test(b);return d&&(this.cache[b]||(this.cache[b]={}),this.cache[b][a]=!0),d},regexify:function(a){return a.replace(/\./g,"\\.").replace(/\*/g,".*").replace(/#/g,"[A-Z,a-z,0-9]*")}},k={subscriptions:{},wireTaps:[],publish:function(a){_.each(this.wireTaps,function(b){b({exchange:a.exchange,topic:a.topic,data:a.data,timeStamp:a.timeStamp})}),_.each(this.subscriptions[a.exchange],function(b){_.each(b,function(b){l.configuration.resolver.compare(b.topic,a.topic)&&_.all(b.constraints,function(b){return b(a.data)})&&typeof b.callback=="function"&&(b.callback.apply(b.context,[a.data]),b.onHandled())})})},subscribe:function(a){var b,c,d;this.subscriptions[a.exchange]||(this.subscriptions[a.exchange]={}),this.subscriptions[a.exchange][a.topic]||(this.subscriptions[a.exchange][a.topic]=[]),b=this.subscriptions[a.exchange][a.topic].length-1;if(!_.any(this.subscriptions[a.exchange][a.topic],function(b){return b===a})){for(;b>=0;b--)if(this.subscriptions[a.exchange][a.topic][b].priority<=a.priority){this.subscriptions[a.exchange][a.topic].splice(b+1,0,a),c=!0;break}c||this.subscriptions[a.exchange][a.topic].unshift(a)}return _.bind(function(){this.unsubscribe(a)},this)},unsubscribe:function(a){if(this.subscriptions[a.exchange][a.topic]){var b=this.subscriptions[a.exchange][a.topic].length,c=0;for(;c> $OutFile - -# Combine the source files -while read line; do - cat ../../$line >> $OutFile -done < source-browser-postal.txt - -cat ../boilerplate/browser_footer.txt >> $OutFile - -DiagOutFile='../output/browser/postal.diagnostics.js' -cat ../../src/Diagnostics.js >> $DiagOutFile \ No newline at end of file diff --git a/build/scripts/linux-build-node.sh b/build/scripts/linux-build-node.sh deleted file mode 100755 index d0bc25a..0000000 --- a/build/scripts/linux-build-node.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -OutFile='../output/nodejs/postal.js' - -cp version-header.js $OutFile - -# Combine the source files -while read line; do - cat ../../$line >> $OutFile -done < SourceManifest-node.txt - -cat ../boilerplate/node_footer.txt >> $OutFile \ No newline at end of file diff --git a/build/scripts/source-browser-postal.txt b/build/scripts/source-browser-postal.txt deleted file mode 100644 index 6c1f320..0000000 --- a/build/scripts/source-browser-postal.txt +++ /dev/null @@ -1,7 +0,0 @@ -src/Constants.js -src/DistinctPredicate.js -src/ChannelDefinition.js -src/SubscriptionDefinition.js -src/BindingsResolver.js -src/LocalBus.js -src/Postal.js diff --git a/build/tools/curl.exe b/build/tools/curl.exe deleted file mode 100644 index 5770c1f..0000000 Binary files a/build/tools/curl.exe and /dev/null differ diff --git a/spec/runner.html b/spec/runner.html index aff1380..7c07aba 100644 --- a/spec/runner.html +++ b/spec/runner.html @@ -7,13 +7,13 @@ - - - - - - - + + + + + + + diff --git a/src/Diagnostics.js b/src/diags/postal.diagnostics.js similarity index 100% rename from src/Diagnostics.js rename to src/diags/postal.diagnostics.js diff --git a/src/Postal.js b/src/main/Api.js similarity index 100% rename from src/Postal.js rename to src/main/Api.js diff --git a/src/BindingsResolver.js b/src/main/BindingsResolver.js similarity index 100% rename from src/BindingsResolver.js rename to src/main/BindingsResolver.js diff --git a/src/ChannelDefinition.js b/src/main/ChannelDefinition.js similarity index 97% rename from src/ChannelDefinition.js rename to src/main/ChannelDefinition.js index 48f2a2c..86112ac 100644 --- a/src/ChannelDefinition.js +++ b/src/main/ChannelDefinition.js @@ -16,6 +16,6 @@ ChannelDefinition.prototype = { topic: this.topic, data: data, timeStamp: new Date() - }) + }); } }; diff --git a/src/Constants.js b/src/main/Constants.js similarity index 100% rename from src/Constants.js rename to src/main/Constants.js diff --git a/src/DistinctPredicate.js b/src/main/DistinctPredicate.js similarity index 100% rename from src/DistinctPredicate.js rename to src/main/DistinctPredicate.js diff --git a/src/LocalBus.js b/src/main/LocalBus.js similarity index 100% rename from src/LocalBus.js rename to src/main/LocalBus.js diff --git a/src/SubscriptionDefinition.js b/src/main/SubscriptionDefinition.js similarity index 99% rename from src/SubscriptionDefinition.js rename to src/main/SubscriptionDefinition.js index aac7748..9f55dd7 100644 --- a/src/SubscriptionDefinition.js +++ b/src/main/SubscriptionDefinition.js @@ -6,7 +6,7 @@ var SubscriptionDefinition = function(exchange, topic, callback) { this.constraints = []; this.maxCalls = DEFAULT_DISPOSEAFTER; this.onHandled = NO_OP; - this.context = null + this.context = null; }; SubscriptionDefinition.prototype = { diff --git a/build/scripts/version-header.js b/src/main/VersionHeader.js similarity index 87% rename from build/scripts/version-header.js rename to src/main/VersionHeader.js index 0d5e29d..bf18127 100644 --- a/build/scripts/version-header.js +++ b/src/main/VersionHeader.js @@ -2,6 +2,5 @@ postal.js Author: Jim Cowart License: Dual licensed MIT (http://www.opensource.org/licenses/mit-license) & GPL (http://www.opensource.org/licenses/gpl-license) - Version 0.1.0 + Version 0.3.0 */ - diff --git a/src/main/postal.js b/src/main/postal.js new file mode 100644 index 0000000..c0d0562 --- /dev/null +++ b/src/main/postal.js @@ -0,0 +1,8 @@ +//import("VersionHeader.js"); +//import("Constants.js"); +//import("DistinctPredicate.js"); +//import("ChannelDefinition.js"); +//import("SubscriptionDefinition.js"); +//import("BindingsResolver.js"); +//import("LocalBus.js"); +//import("Api.js"); \ No newline at end of file