Refactored postal to use anvil.js for builds

This commit is contained in:
Jim Cowart 2011-09-20 15:35:36 -04:00
parent 4673a864a0
commit d9fa989611
35 changed files with 100 additions and 84 deletions

6
build-all.sh Executable file
View file

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

8
build-browser-diags.json Normal file
View file

@ -0,0 +1,8 @@
{
"source": "src/diags",
"output": "build/browser",
"lint": {},
"uglify": {},
"gzip": {},
"extensions": { "uglify": "min", "gzip": "gz" }
}

12
build-browser.json Normal file
View file

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

9
build-node-diags.json Normal file
View file

@ -0,0 +1,9 @@
{
"source": "src/diags",
"output": "build/node",
"lint": {},
"wrap": {
"prefix": "module.exports = function(postal) {",
"suffix": "};"
}
}

9
build-node.json Normal file
View file

@ -0,0 +1,9 @@
{
"source": "src/main",
"output": "build/node",
"lint": {},
"wrap": {
"prefix": "",
"suffix": "exports.postal = postal;"
}
}

View file

@ -1,4 +0,0 @@
global.postal = postal;
})(window);

View file

@ -1,2 +0,0 @@
(function(global, undefined) {

View file

@ -1,2 +0,0 @@
})(window);

View file

@ -1,2 +0,0 @@
(function(global, undefined) {

View file

@ -1,2 +0,0 @@
exports.postal = postal;

Binary file not shown.

View file

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

View file

@ -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);
global.postal = postal; })(window);

Binary file not shown.

1
build/browser/postal.min.js vendored Normal file
View file

@ -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<b;c++)if(this.subscriptions[a.exchange][a.topic][c]===a){this.subscriptions[a.exchange][a.topic].splice(c,1);break}}},addWireTap:function(a){return this.wireTaps.push(a),function(){var b=this.wireTaps.indexOf(a);b!==-1&&this.wireTaps.splice(b,1)}}},l={configuration:{bus:k,resolver:j},channel:function(a,b){var d=arguments.length===2?a:c,e=arguments.length===2?b:a;return new h(d,e)},addWireTap:function(a){this.configuration.bus.addWireTap(a)}};a.postal=l})(window)

View file

@ -0,0 +1,13 @@
module.exports = function(postal) {
postal.addWireTap(function(data) {
if(!JSON) {
throw "This browser or environment does provide JSON support";
}
try {
console.log(JSON.stringify(data));
}
catch(exception) {
console.log("Unable to parse data to JSON: " + exception);
}
});
};

View file

@ -2,13 +2,14 @@
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
*/
var DEFAULT_EXCHANGE = "/",
DEFAULT_PRIORITY = 50,
DEFAULT_DISPOSEAFTER = 0,
NO_OP = function() { };
var DistinctPredicate = function() {
var previous;
return function(data) {
@ -24,6 +25,7 @@ var DistinctPredicate = function() {
return !eq;
};
};
var ChannelDefinition = function(exchange, topic) {
this.exchange = exchange;
this.topic = topic;
@ -42,9 +44,10 @@ ChannelDefinition.prototype = {
topic: this.topic,
data: data,
timeStamp: new Date()
})
});
}
};
var SubscriptionDefinition = function(exchange, topic, callback) {
this.exchange = exchange;
this.topic = topic;
@ -53,7 +56,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 = {
@ -157,6 +160,7 @@ SubscriptionDefinition.prototype = {
return this;
}
};
var bindingsResolver = {
cache: { },
@ -181,6 +185,7 @@ var bindingsResolver = {
.replace(/#/g, "[A-Z,a-z,0-9]*"); // hash matches any alpha-numeric 'word'
}
};
var localBus = {
subscriptions: {},
@ -261,6 +266,7 @@ var localBus = {
};
}
};
var postal = {
configuration: {
bus: localBus,
@ -277,5 +283,5 @@ var postal = {
this.configuration.bus.addWireTap(callback);
}
};
exports.postal = postal;

View file

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

View file

@ -1,4 +0,0 @@
#!/bin/sh
./linux-build-node.sh
./linux-build-browser-core.sh

View file

@ -1,17 +0,0 @@
#!/bin/sh
OutFile='../output/browser/postal.js'
cp ./version-header.js $OutFile
cat ../boilerplate/browser_header.txt >> $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

View file

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

View file

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

Binary file not shown.

View file

@ -7,13 +7,13 @@
<script type="text/javascript" src="../lib/amplify.core.js"></script>
<script type="text/javascript" src="../lib/amplify.store.js"></script>
<script type="text/javascript" src="../lib/underscore.js"></script>
<script type="text/javascript" src="../src/Constants.js"></script>
<script type="text/javascript" src="../src/DistinctPredicate.js"></script>
<script type="text/javascript" src="../src/ChannelDefinition.js"></script>
<script type="text/javascript" src="../src/SubscriptionDefinition.js"></script>
<script type="text/javascript" src="../src/BindingsResolver.js"></script>
<script type="text/javascript" src="../src/LocalBus.js"></script>
<script type="text/javascript" src="../src/Postal.js"></script>
<script type="text/javascript" src="../src/main/Constants.js"></script>
<script type="text/javascript" src="../src/main/DistinctPredicate.js"></script>
<script type="text/javascript" src="../src/main/ChannelDefinition.js"></script>
<script type="text/javascript" src="../src/main/SubscriptionDefinition.js"></script>
<script type="text/javascript" src="../src/main/BindingsResolver.js"></script>
<script type="text/javascript" src="../src/main/LocalBus.js"></script>
<script type="text/javascript" src="../src/main/Api.js"></script>
<script type="text/javascript" src="DistinctPredicate.spec.js"></script>
<script type="text/javascript" src="ChannelDefinition.spec.js"></script>
<script type="text/javascript" src="SubscriptionDefinition.spec.js"></script>

View file

@ -16,6 +16,6 @@ ChannelDefinition.prototype = {
topic: this.topic,
data: data,
timeStamp: new Date()
})
});
}
};

View file

@ -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 = {

View file

@ -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
*/

8
src/main/postal.js Normal file
View file

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