mirror of
https://github.com/Hopiu/postal.js.git
synced 2026-03-16 22:20:23 +00:00
Changed build process to produce separate amd and standard lib output for browser
This commit is contained in:
parent
e5d08bac53
commit
57410d175a
41 changed files with 554 additions and 150 deletions
27
build-all.sh
27
build-all.sh
|
|
@ -3,13 +3,24 @@
|
|||
anvil -b build-browser.json
|
||||
anvil -b build-browser-diags.json
|
||||
|
||||
cp ./lib/browser/postal.js ./example/amd/js/libs/postal/
|
||||
cp ./lib/browser/postal.diagnostics.js ./example/amd/js/libs/postal/
|
||||
cp ./lib/browser/postal.js ./example/standard/js/
|
||||
cp ./lib/browser/postal.diagnostics.js ./example/standard/js/
|
||||
mv ./lib/standard/postal.amd.js ./lib/amd/postal.js
|
||||
mv ./lib/standard/postal.amd.min.js ./lib/amd/postal.min.js
|
||||
mv ./lib/standard/postal.amd.min.gz.js ./lib/amd/postal.min.gz.js
|
||||
mv ./lib/standard/postal.diagnostics.amd.js ./lib/amd/postal.diagnostics.js
|
||||
mv ./lib/standard/postal.diagnostics.amd.min.js ./lib/amd/postal.diagnostics.min.js
|
||||
mv ./lib/standard/postal.diagnostics.amd.min.gz.js ./lib/amd/postal.diagnostics.min.gz.js
|
||||
|
||||
mv ./lib/browser/postal.node.js ./lib/node/postal.js
|
||||
rm ./lib/browser/postal.node*
|
||||
mv ./lib/standard/postal.diagnostics.node.js ./lib/node/postal.diagnostics.js
|
||||
mv ./lib/standard/postal.node.js ./lib/node/postal.js
|
||||
rm ./lib/standard/postal.diagnostics.node*
|
||||
rm ./lib/standard/postal.node*
|
||||
|
||||
mv ./lib/browser/postal.diagnostics.node.js ./lib/node/postal.diagnostics.js
|
||||
rm ./lib/browser/postal.diagnostics.node*
|
||||
mv ./lib/standard/postal.standard.js ./lib/standard/postal.js
|
||||
mv ./lib/standard/postal.standard.min.js ./lib/standard/postal.min.js
|
||||
mv ./lib/standard/postal.standard.min.gz.js ./lib/standard/postal.min.gz.js
|
||||
mv ./lib/standard/postal.diagnostics.standard.js ./lib/standard/postal.diagnostics.js
|
||||
mv ./lib/standard/postal.diagnostics.standard.min.js ./lib/standard/postal.diagnostics.min.js
|
||||
mv ./lib/standard/postal.diagnostics.standard.min.gz.js ./lib/standard/postal.diagnostics.min.gz.js
|
||||
|
||||
cp ./lib/standard/postal.* ./example/standard/js
|
||||
cp ./lib/amd/postal.* ./example/amd/js/libs/postal
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"source": "src/diags",
|
||||
"output": "lib/browser",
|
||||
"output": "lib/standard",
|
||||
"lint": {},
|
||||
"uglify": {},
|
||||
"gzip": {},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"source": "src/main",
|
||||
"output": "lib/browser",
|
||||
"output": "lib/standard",
|
||||
"lint": {},
|
||||
"uglify": {},
|
||||
"gzip": {},
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
define(['postal', 'postaldiags'], function(postal, diags){
|
||||
|
||||
// The world's simplest subscription
|
||||
var channel = postal.channel("Name.Changed");
|
||||
// subscribe
|
||||
|
|
|
|||
|
|
@ -1,17 +1,10 @@
|
|||
(function(root, doc, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(["postal", "underscore"], function(postal, _) {
|
||||
return factory(postal, _, root, doc);
|
||||
});
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(root.postal, root._, root, doc);
|
||||
}
|
||||
}(this, document, function(postal, _, global, document, undefined) {
|
||||
// This is the amd module version of postal.diagnostics.js
|
||||
// If you need the standard lib version, go to http://github.com/ifandelse/postal.js
|
||||
define(["postal", "underscore"], function(postal, _, undefined) {
|
||||
|
||||
|
||||
// this returns a callback that, if invoked, removes the wireTap
|
||||
return postal.addWireTap(function(data, envelope) {
|
||||
postal.diagnostics = postal.addWireTap(function(data, envelope) {
|
||||
var all = _.extend(envelope, { data: data });
|
||||
if(!JSON) {
|
||||
throw "This browser or environment does not provide JSON support";
|
||||
|
|
@ -30,4 +23,5 @@
|
|||
}
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
});
|
||||
BIN
example/amd/js/libs/postal/postal.diagnostics.min.gz.js
Normal file
BIN
example/amd/js/libs/postal/postal.diagnostics.min.gz.js
Normal file
Binary file not shown.
1
example/amd/js/libs/postal/postal.diagnostics.min.js
vendored
Normal file
1
example/amd/js/libs/postal/postal.diagnostics.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
define(["postal","underscore"],function(a,b,c){a.diagnostics=a.addWireTap(function(a,c){var d=b.extend(c,{data:a});if(!JSON)throw"This browser or environment does not provide JSON support";try{console.log(JSON.stringify(d))}catch(e){try{d.data="ERROR: "+e.message,console.log(JSON.stringify(d))}catch(f){console.log("Unable to parse data to JSON: "+e)}}})})
|
||||
|
|
@ -5,17 +5,9 @@
|
|||
Version 0.6.0
|
||||
*/
|
||||
|
||||
(function(root, doc, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(["underscore"], function(_) {
|
||||
return factory(_, root, doc);
|
||||
});
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(root._, root, doc);
|
||||
}
|
||||
}(this, document, function(_, global, document, undefined) {
|
||||
// This is the amd-module version of postal.js
|
||||
// If you need the standard lib style version, go to http://github.com/ifandelse/postal.js
|
||||
define(["underscore"], function(_, undefined) {
|
||||
|
||||
var DEFAULT_CHANNEL = "/",
|
||||
DEFAULT_PRIORITY = 50,
|
||||
|
|
@ -414,6 +406,5 @@ var postal = {
|
|||
};
|
||||
|
||||
|
||||
global.postal = postal;
|
||||
return postal;
|
||||
}));
|
||||
});
|
||||
BIN
example/amd/js/libs/postal/postal.min.gz.js
Normal file
BIN
example/amd/js/libs/postal/postal.min.gz.js
Normal file
Binary file not shown.
1
example/amd/js/libs/postal/postal.min.js
vendored
Normal file
1
example/amd/js/libs/postal/postal.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -7,8 +7,8 @@ require.config({
|
|||
}
|
||||
});
|
||||
|
||||
require(['jquery'], function($){
|
||||
require( [ 'jquery' ], function( $ ){
|
||||
$(function(){
|
||||
require(['examples']);
|
||||
require( [ 'examples' ] );
|
||||
});
|
||||
});
|
||||
|
|
@ -1,17 +1,10 @@
|
|||
(function(root, doc, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(["postal", "underscore"], function(postal, _) {
|
||||
return factory(postal, _, root, doc);
|
||||
});
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(root.postal, root._, root, doc);
|
||||
}
|
||||
}(this, document, function(postal, _, global, document, undefined) {
|
||||
// This is the standard lib version of postal.diagnostics.js
|
||||
// If you need the amd-module style version, go to http://github.com/ifandelse/postal.js
|
||||
(function(postal, _, undefined) {
|
||||
|
||||
|
||||
// this returns a callback that, if invoked, removes the wireTap
|
||||
return postal.addWireTap(function(data, envelope) {
|
||||
postal.diagnostics = postal.addWireTap(function(data, envelope) {
|
||||
var all = _.extend(envelope, { data: data });
|
||||
if(!JSON) {
|
||||
throw "This browser or environment does not provide JSON support";
|
||||
|
|
@ -30,4 +23,5 @@
|
|||
}
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
})( postal, _ );
|
||||
BIN
example/standard/js/postal.diagnostics.min.gz.js
Normal file
BIN
example/standard/js/postal.diagnostics.min.gz.js
Normal file
Binary file not shown.
1
example/standard/js/postal.diagnostics.min.js
vendored
Normal file
1
example/standard/js/postal.diagnostics.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
(function(a,b,c){a.diagnostics=a.addWireTap(function(a,c){var d=b.extend(c,{data:a});if(!JSON)throw"This browser or environment does not provide JSON support";try{console.log(JSON.stringify(d))}catch(e){try{d.data="ERROR: "+e.message,console.log(JSON.stringify(d))}catch(f){console.log("Unable to parse data to JSON: "+e)}}})})(postal,_)
|
||||
|
|
@ -5,17 +5,9 @@
|
|||
Version 0.6.0
|
||||
*/
|
||||
|
||||
(function(root, doc, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(["underscore"], function(_) {
|
||||
return factory(_, root, doc);
|
||||
});
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(root._, root, doc);
|
||||
}
|
||||
}(this, document, function(_, global, document, undefined) {
|
||||
// This is the standard lib version of postal.js
|
||||
// If you need the amd-module style version, go to http://github.com/ifandelse/postal.js
|
||||
(function(_, global, undefined) {
|
||||
|
||||
var DEFAULT_CHANNEL = "/",
|
||||
DEFAULT_PRIORITY = 50,
|
||||
|
|
@ -415,5 +407,5 @@ var postal = {
|
|||
|
||||
|
||||
global.postal = postal;
|
||||
return postal;
|
||||
}));
|
||||
|
||||
})(_, window);
|
||||
BIN
example/standard/js/postal.min.gz.js
Normal file
BIN
example/standard/js/postal.min.gz.js
Normal file
Binary file not shown.
1
example/standard/js/postal.min.js
vendored
Normal file
1
example/standard/js/postal.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -1,17 +1,10 @@
|
|||
(function(root, doc, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(["postal", "underscore"], function(postal, _) {
|
||||
return factory(postal, _, root, doc);
|
||||
});
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(root.postal, root._, root, doc);
|
||||
}
|
||||
}(this, document, function(postal, _, global, document, undefined) {
|
||||
// This is the amd module version of postal.diagnostics.js
|
||||
// If you need the standard lib version, go to http://github.com/ifandelse/postal.js
|
||||
define(["postal", "underscore"], function(postal, _, undefined) {
|
||||
|
||||
|
||||
// this returns a callback that, if invoked, removes the wireTap
|
||||
return postal.addWireTap(function(data, envelope) {
|
||||
postal.diagnostics = postal.addWireTap(function(data, envelope) {
|
||||
var all = _.extend(envelope, { data: data });
|
||||
if(!JSON) {
|
||||
throw "This browser or environment does not provide JSON support";
|
||||
|
|
@ -30,4 +23,5 @@
|
|||
}
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
});
|
||||
BIN
lib/amd/postal.diagnostics.min.gz.js
Normal file
BIN
lib/amd/postal.diagnostics.min.gz.js
Normal file
Binary file not shown.
1
lib/amd/postal.diagnostics.min.js
vendored
Normal file
1
lib/amd/postal.diagnostics.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
define(["postal","underscore"],function(a,b,c){a.diagnostics=a.addWireTap(function(a,c){var d=b.extend(c,{data:a});if(!JSON)throw"This browser or environment does not provide JSON support";try{console.log(JSON.stringify(d))}catch(e){try{d.data="ERROR: "+e.message,console.log(JSON.stringify(d))}catch(f){console.log("Unable to parse data to JSON: "+e)}}})})
|
||||
410
lib/amd/postal.js
Normal file
410
lib/amd/postal.js
Normal file
|
|
@ -0,0 +1,410 @@
|
|||
/*
|
||||
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.6.0
|
||||
*/
|
||||
|
||||
// This is the amd-module version of postal.js
|
||||
// If you need the standard lib style version, go to http://github.com/ifandelse/postal.js
|
||||
define(["underscore"], function(_, undefined) {
|
||||
|
||||
var DEFAULT_CHANNEL = "/",
|
||||
DEFAULT_PRIORITY = 50,
|
||||
DEFAULT_DISPOSEAFTER = 0,
|
||||
SYSTEM_CHANNEL = "postal",
|
||||
NO_OP = function() { };
|
||||
|
||||
var DistinctPredicate = function() {
|
||||
var previous;
|
||||
return function(data) {
|
||||
var eq = false;
|
||||
if(_.isString(data)) {
|
||||
eq = data === previous;
|
||||
previous = data;
|
||||
}
|
||||
else {
|
||||
eq = _.isEqual(data, previous);
|
||||
previous = _.clone(data);
|
||||
}
|
||||
return !eq;
|
||||
};
|
||||
};
|
||||
|
||||
var ChannelDefinition = function(channelName, defaultTopic) {
|
||||
this.channel = channelName || DEFAULT_CHANNEL;
|
||||
this._topic = defaultTopic || "";
|
||||
};
|
||||
|
||||
ChannelDefinition.prototype = {
|
||||
subscribe: function() {
|
||||
var len = arguments.length;
|
||||
if(len === 1) {
|
||||
return new SubscriptionDefinition(this.channel, this._topic, arguments[0]);
|
||||
}
|
||||
else if (len === 2) {
|
||||
return new SubscriptionDefinition(this.channel, arguments[0], arguments[1]);
|
||||
}
|
||||
},
|
||||
|
||||
publish: function(obj) {
|
||||
var envelope = {
|
||||
channel: this.channel,
|
||||
topic: this._topic,
|
||||
data: obj
|
||||
};
|
||||
// If this is an envelope....
|
||||
if( obj.topic && obj.data ) {
|
||||
envelope = obj;
|
||||
envelope.channel = envelope.channel || this.channel;
|
||||
}
|
||||
envelope.timeStamp = new Date();
|
||||
postal.configuration.bus.publish(envelope);
|
||||
},
|
||||
|
||||
topic: function(topic) {
|
||||
if(topic === this._topic) {
|
||||
return this;
|
||||
}
|
||||
return new ChannelDefinition(this.channel, topic);
|
||||
}
|
||||
};
|
||||
|
||||
var SubscriptionDefinition = function(channel, topic, callback) {
|
||||
this.channel = channel;
|
||||
this.topic = topic;
|
||||
this.callback = callback;
|
||||
this.priority = DEFAULT_PRIORITY;
|
||||
this.constraints = new Array(0);
|
||||
this.maxCalls = DEFAULT_DISPOSEAFTER;
|
||||
this.onHandled = NO_OP;
|
||||
this.context = null;
|
||||
postal.configuration.bus.publish({
|
||||
channel: SYSTEM_CHANNEL,
|
||||
topic: "subscription.created",
|
||||
timeStamp: new Date(),
|
||||
data: {
|
||||
event: "subscription.created",
|
||||
channel: channel,
|
||||
topic: topic
|
||||
}
|
||||
});
|
||||
|
||||
postal.configuration.bus.subscribe(this);
|
||||
|
||||
};
|
||||
|
||||
SubscriptionDefinition.prototype = {
|
||||
unsubscribe: function() {
|
||||
postal.configuration.bus.unsubscribe(this);
|
||||
postal.configuration.bus.publish({
|
||||
channel: SYSTEM_CHANNEL,
|
||||
topic: "subscription.removed",
|
||||
timeStamp: new Date(),
|
||||
data: {
|
||||
event: "subscription.removed",
|
||||
channel: this.channel,
|
||||
topic: this.topic
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
defer: function() {
|
||||
var fn = this.callback;
|
||||
this.callback = function(data) {
|
||||
setTimeout(fn,0,data);
|
||||
};
|
||||
return this;
|
||||
},
|
||||
|
||||
disposeAfter: function(maxCalls) {
|
||||
if(_.isNaN(maxCalls) || maxCalls <= 0) {
|
||||
throw "The value provided to disposeAfter (maxCalls) must be a number greater than zero.";
|
||||
}
|
||||
|
||||
var fn = this.onHandled;
|
||||
var dispose = _.after(maxCalls, _.bind(function() {
|
||||
this.unsubscribe(this);
|
||||
}, this));
|
||||
|
||||
this.onHandled = function() {
|
||||
fn.apply(this.context, arguments);
|
||||
dispose();
|
||||
};
|
||||
return this;
|
||||
},
|
||||
|
||||
ignoreDuplicates: function() {
|
||||
this.withConstraint(new DistinctPredicate());
|
||||
return this;
|
||||
},
|
||||
|
||||
withConstraint: function(predicate) {
|
||||
if(! _.isFunction(predicate)) {
|
||||
throw "Predicate constraint must be a function";
|
||||
}
|
||||
this.constraints.push(predicate);
|
||||
return this;
|
||||
},
|
||||
|
||||
withConstraints: function(predicates) {
|
||||
var self = this;
|
||||
if(_.isArray(predicates)) {
|
||||
_.each(predicates, function(predicate) { self.withConstraint(predicate); } );
|
||||
}
|
||||
return self;
|
||||
},
|
||||
|
||||
withContext: function(context) {
|
||||
this.context = context;
|
||||
return this;
|
||||
},
|
||||
|
||||
withDebounce: function(milliseconds) {
|
||||
if(_.isNaN(milliseconds)) {
|
||||
throw "Milliseconds must be a number";
|
||||
}
|
||||
var fn = this.callback;
|
||||
this.callback = _.debounce(fn, milliseconds);
|
||||
return this;
|
||||
},
|
||||
|
||||
withDelay: function(milliseconds) {
|
||||
if(_.isNaN(milliseconds)) {
|
||||
throw "Milliseconds must be a number";
|
||||
}
|
||||
var fn = this.callback;
|
||||
this.callback = function(data) {
|
||||
setTimeout(function(){
|
||||
fn(data);
|
||||
}, milliseconds);
|
||||
};
|
||||
return this;
|
||||
},
|
||||
|
||||
withPriority: function(priority) {
|
||||
if(_.isNaN(priority)) {
|
||||
throw "Priority must be a number";
|
||||
}
|
||||
this.priority = priority;
|
||||
return this;
|
||||
},
|
||||
|
||||
withThrottle: function(milliseconds) {
|
||||
if(_.isNaN(milliseconds)) {
|
||||
throw "Milliseconds must be a number";
|
||||
}
|
||||
var fn = this.callback;
|
||||
this.callback = _.throttle(fn, milliseconds);
|
||||
return this;
|
||||
},
|
||||
|
||||
subscribe: function(callback) {
|
||||
this.callback = callback;
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
var bindingsResolver = {
|
||||
cache: { },
|
||||
|
||||
compare: function(binding, topic) {
|
||||
if(this.cache[topic] && this.cache[topic][binding]) {
|
||||
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'
|
||||
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]) {
|
||||
this.cache[topic] = {};
|
||||
}
|
||||
this.cache[topic][binding] = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
var localBus = {
|
||||
|
||||
subscriptions: {},
|
||||
|
||||
wireTaps: new Array(0),
|
||||
|
||||
publish: function(envelope) {
|
||||
_.each(this.wireTaps,function(tap) {
|
||||
tap(envelope.data, envelope);
|
||||
});
|
||||
|
||||
_.each(this.subscriptions[envelope.channel], function(topic) {
|
||||
_.each(topic, function(subDef){
|
||||
if(postal.configuration.resolver.compare(subDef.topic, envelope.topic)) {
|
||||
if(_.all(subDef.constraints, function(constraint) { return constraint(envelope.data); })) {
|
||||
if(typeof subDef.callback === 'function') {
|
||||
subDef.callback.apply(subDef.context, [envelope.data, envelope]);
|
||||
subDef.onHandled();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
subscribe: function(subDef) {
|
||||
var idx, found, fn, channel = this.subscriptions[subDef.channel], subs;
|
||||
|
||||
if(!channel) {
|
||||
channel = this.subscriptions[subDef.channel] = {};
|
||||
}
|
||||
subs = this.subscriptions[subDef.channel][subDef.topic];
|
||||
if(!subs) {
|
||||
subs = this.subscriptions[subDef.channel][subDef.topic] = new Array(0);
|
||||
}
|
||||
|
||||
idx = subs.length - 1;
|
||||
for(; idx >= 0; idx--) {
|
||||
if(subs[idx].priority <= subDef.priority) {
|
||||
subs.splice(idx + 1, 0, subDef);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!found) {
|
||||
subs.unshift(subDef);
|
||||
}
|
||||
return subDef;
|
||||
},
|
||||
|
||||
unsubscribe: function(config) {
|
||||
if(this.subscriptions[config.channel][config.topic]) {
|
||||
var len = this.subscriptions[config.channel][config.topic].length,
|
||||
idx = 0;
|
||||
for ( ; idx < len; idx++ ) {
|
||||
if (this.subscriptions[config.channel][config.topic][idx] === config) {
|
||||
this.subscriptions[config.channel][config.topic].splice( idx, 1 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
addWireTap: function(callback) {
|
||||
var self = this;
|
||||
self.wireTaps.push(callback);
|
||||
return function() {
|
||||
var idx = self.wireTaps.indexOf(callback);
|
||||
if(idx !== -1) {
|
||||
self.wireTaps.splice(idx,1);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
var publishPicker = {
|
||||
"1" : function(envelope) {
|
||||
if(!envelope) {
|
||||
throw new Error("publishing from the 'global' postal.publish call requires a valid envelope.");
|
||||
}
|
||||
envelope.channel = envelope.channel || DEFAULT_CHANNEL;
|
||||
envelope.timeStamp = new Date();
|
||||
postal.configuration.bus.publish(envelope);
|
||||
},
|
||||
"2" : function(topic, data) {
|
||||
postal.configuration.bus.publish({ channel: DEFAULT_CHANNEL, topic: topic, timeStamp: new Date(), data: data });
|
||||
},
|
||||
"3" : function(channel, topic, data) {
|
||||
postal.configuration.bus.publish({ channel: channel, topic: topic, timeStamp: new Date(), data: data });
|
||||
}
|
||||
};
|
||||
|
||||
// save some setup time, albeit tiny
|
||||
localBus.subscriptions[SYSTEM_CHANNEL] = {};
|
||||
|
||||
var postal = {
|
||||
configuration: {
|
||||
bus: localBus,
|
||||
resolver: bindingsResolver
|
||||
},
|
||||
|
||||
channel: function() {
|
||||
var len = arguments.length,
|
||||
channel = arguments[0],
|
||||
tpc = arguments[1];
|
||||
if(len === 1) {
|
||||
if(Object.prototype.toString.call(channel) === "[object String]") {
|
||||
channel = DEFAULT_CHANNEL;
|
||||
tpc = arguments[0];
|
||||
}
|
||||
else {
|
||||
channel = arguments[0].channel || DEFAULT_CHANNEL;
|
||||
tpc = arguments[0].topic;
|
||||
}
|
||||
}
|
||||
return new ChannelDefinition(channel, tpc);
|
||||
},
|
||||
|
||||
subscribe: function(options) {
|
||||
var callback = options.callback,
|
||||
topic = options.topic,
|
||||
channel = options.channel || DEFAULT_CHANNEL;
|
||||
return new SubscriptionDefinition(channel, topic, callback);
|
||||
},
|
||||
|
||||
publish: function() {
|
||||
var len = arguments.length;
|
||||
if(publishPicker[len]) {
|
||||
publishPicker[len].apply(this, arguments);
|
||||
}
|
||||
},
|
||||
|
||||
addWireTap: function(callback) {
|
||||
return this.configuration.bus.addWireTap(callback);
|
||||
},
|
||||
|
||||
linkChannels: function(sources, destinations) {
|
||||
var result = [];
|
||||
if(!_.isArray(sources)) {
|
||||
sources = [sources];
|
||||
}
|
||||
if(!_.isArray(destinations)) {
|
||||
destinations = [destinations];
|
||||
}
|
||||
_.each(sources, function(source){
|
||||
var sourceTopic = source.topic || "*";
|
||||
_.each(destinations, function(destination) {
|
||||
var destChannel = destination.channel || DEFAULT_CHANNEL;
|
||||
result.push(
|
||||
postal.subscribe({
|
||||
channel: source.channel || DEFAULT_CHANNEL,
|
||||
topic: source.topic || "*",
|
||||
callback : function(data, env) {
|
||||
var newEnv = env;
|
||||
newEnv.topic = _.isFunction(destination.topic) ? destination.topic(env.topic) : destination.topic || env.topic;
|
||||
newEnv.channel = destChannel;
|
||||
newEnv.data = data;
|
||||
postal.publish(newEnv);
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
return result;
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
// we check first in case a custom bus or resolver
|
||||
// doesn't expose subscriptions or a resolver cache
|
||||
if(postal.configuration.bus.subscriptions) {
|
||||
postal.configuration.bus.subscriptions = {};
|
||||
}
|
||||
if(postal.configuration.resolver.cache) {
|
||||
postal.configuration.resolver.cache = {};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return postal;
|
||||
});
|
||||
BIN
lib/amd/postal.min.gz.js
Normal file
BIN
lib/amd/postal.min.gz.js
Normal file
Binary file not shown.
1
lib/amd/postal.min.js
vendored
Normal file
1
lib/amd/postal.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Binary file not shown.
1
lib/browser/postal.diagnostics.min.js
vendored
1
lib/browser/postal.diagnostics.min.js
vendored
|
|
@ -1 +0,0 @@
|
|||
(function(a,b,c){typeof define=="function"&&define.amd?define(["postal","underscore"],function(d,e){return c(d,e,a,b)}):c(a.postal,a._,a,b)})(this,document,function(a,b,c,d,e){return a.addWireTap(function(a,c){var d=b.extend(c,{data:a});if(!JSON)throw"This browser or environment does not provide JSON support";try{console.log(JSON.stringify(d))}catch(e){try{d.data="ERROR: "+e.message,console.log(JSON.stringify(d))}catch(f){console.log("Unable to parse data to JSON: "+e)}}})})
|
||||
Binary file not shown.
1
lib/browser/postal.min.js
vendored
1
lib/browser/postal.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -1,6 +1,7 @@
|
|||
module.exports = function(postal) {
|
||||
|
||||
// this returns a callback that, if invoked, removes the wireTap
|
||||
return postal.addWireTap(function(data, envelope) {
|
||||
postal.diagnostics = postal.addWireTap(function(data, envelope) {
|
||||
var all = _.extend(envelope, { data: data });
|
||||
if(!JSON) {
|
||||
throw "This browser or environment does not provide JSON support";
|
||||
|
|
@ -18,4 +19,5 @@ module.exports = function(postal) {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
27
lib/standard/postal.diagnostics.js
Normal file
27
lib/standard/postal.diagnostics.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// This is the standard lib version of postal.diagnostics.js
|
||||
// If you need the amd-module style version, go to http://github.com/ifandelse/postal.js
|
||||
(function(postal, _, undefined) {
|
||||
|
||||
|
||||
// this returns a callback that, if invoked, removes the wireTap
|
||||
postal.diagnostics = postal.addWireTap(function(data, envelope) {
|
||||
var all = _.extend(envelope, { data: data });
|
||||
if(!JSON) {
|
||||
throw "This browser or environment does not provide JSON support";
|
||||
}
|
||||
try {
|
||||
console.log(JSON.stringify(all));
|
||||
}
|
||||
catch(exception) {
|
||||
try {
|
||||
all.data = "ERROR: " + exception.message;
|
||||
console.log(JSON.stringify(all));
|
||||
}
|
||||
catch(ex) {
|
||||
console.log("Unable to parse data to JSON: " + exception);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
})( postal, _ );
|
||||
BIN
lib/standard/postal.diagnostics.min.gz.js
Normal file
BIN
lib/standard/postal.diagnostics.min.gz.js
Normal file
Binary file not shown.
1
lib/standard/postal.diagnostics.min.js
vendored
Normal file
1
lib/standard/postal.diagnostics.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
(function(a,b,c){a.diagnostics=a.addWireTap(function(a,c){var d=b.extend(c,{data:a});if(!JSON)throw"This browser or environment does not provide JSON support";try{console.log(JSON.stringify(d))}catch(e){try{d.data="ERROR: "+e.message,console.log(JSON.stringify(d))}catch(f){console.log("Unable to parse data to JSON: "+e)}}})})(postal,_)
|
||||
|
|
@ -5,17 +5,9 @@
|
|||
Version 0.6.0
|
||||
*/
|
||||
|
||||
(function(root, doc, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(["underscore"], function(_) {
|
||||
return factory(_, root, doc);
|
||||
});
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(root._, root, doc);
|
||||
}
|
||||
}(this, document, function(_, global, document, undefined) {
|
||||
// This is the standard lib version of postal.js
|
||||
// If you need the amd-module style version, go to http://github.com/ifandelse/postal.js
|
||||
(function(_, global, undefined) {
|
||||
|
||||
var DEFAULT_CHANNEL = "/",
|
||||
DEFAULT_PRIORITY = 50,
|
||||
|
|
@ -415,5 +407,5 @@ var postal = {
|
|||
|
||||
|
||||
global.postal = postal;
|
||||
return postal;
|
||||
}));
|
||||
|
||||
})(_, window);
|
||||
BIN
lib/standard/postal.min.gz.js
Normal file
BIN
lib/standard/postal.min.gz.js
Normal file
Binary file not shown.
1
lib/standard/postal.min.js
vendored
Normal file
1
lib/standard/postal.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
7
src/diags/postal.diagnostics.amd.js
Normal file
7
src/diags/postal.diagnostics.amd.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// This is the amd module version of postal.diagnostics.js
|
||||
// If you need the standard lib version, go to http://github.com/ifandelse/postal.js
|
||||
define(["postal", "underscore"], function(postal, _, undefined) {
|
||||
|
||||
//import("postal.diagnostics.js");
|
||||
|
||||
});
|
||||
|
|
@ -1,17 +1,6 @@
|
|||
(function(root, doc, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(["postal", "underscore"], function(postal, _) {
|
||||
return factory(postal, _, root, doc);
|
||||
});
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(root.postal, root._, root, doc);
|
||||
}
|
||||
}(this, document, function(postal, _, global, document, undefined) {
|
||||
|
||||
// this returns a callback that, if invoked, removes the wireTap
|
||||
return postal.addWireTap(function(data, envelope) {
|
||||
postal.diagnostics = postal.addWireTap(function(data, envelope) {
|
||||
var all = _.extend(envelope, { data: data });
|
||||
if(!JSON) {
|
||||
throw "This browser or environment does not provide JSON support";
|
||||
|
|
@ -29,5 +18,3 @@
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
}));
|
||||
|
|
@ -1,21 +1,3 @@
|
|||
module.exports = function(postal) {
|
||||
// this returns a callback that, if invoked, removes the wireTap
|
||||
return postal.addWireTap(function(data, envelope) {
|
||||
var all = _.extend(envelope, { data: data });
|
||||
if(!JSON) {
|
||||
throw "This browser or environment does not provide JSON support";
|
||||
}
|
||||
try {
|
||||
console.log(JSON.stringify(all));
|
||||
}
|
||||
catch(exception) {
|
||||
try {
|
||||
all.data = "ERROR: " + exception.message;
|
||||
console.log(JSON.stringify(all));
|
||||
}
|
||||
catch(ex) {
|
||||
console.log("Unable to parse data to JSON: " + exception);
|
||||
}
|
||||
}
|
||||
});
|
||||
//import("postal.diagnostics.js");
|
||||
};
|
||||
7
src/diags/postal.diagnostics.standard.js
Normal file
7
src/diags/postal.diagnostics.standard.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// This is the standard lib version of postal.diagnostics.js
|
||||
// If you need the amd-module style version, go to http://github.com/ifandelse/postal.js
|
||||
(function(postal, _, undefined) {
|
||||
|
||||
//import("postal.diagnostics.js");
|
||||
|
||||
})( postal, _ );
|
||||
15
src/main/postal.amd.js
Normal file
15
src/main/postal.amd.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
//import("VersionHeader.js");
|
||||
// This is the amd-module version of postal.js
|
||||
// If you need the standard lib style version, go to http://github.com/ifandelse/postal.js
|
||||
define(["underscore"], function(_, undefined) {
|
||||
|
||||
//import("Constants.js");
|
||||
//import("DistinctPredicate.js");
|
||||
//import("ChannelDefinition.js");
|
||||
//import("SubscriptionDefinition.js");
|
||||
//import("BindingsResolver.js");
|
||||
//import("LocalBus.js");
|
||||
//import("Api.js");
|
||||
|
||||
return postal;
|
||||
});
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
//import("VersionHeader.js");
|
||||
(function(root, doc, factory) {
|
||||
if (typeof define === "function" && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(["underscore"], function(_) {
|
||||
return factory(_, root, doc);
|
||||
});
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(root._, root, doc);
|
||||
}
|
||||
}(this, document, function(_, global, document, undefined) {
|
||||
|
||||
//import("Constants.js");
|
||||
//import("DistinctPredicate.js");
|
||||
//import("ChannelDefinition.js");
|
||||
//import("SubscriptionDefinition.js");
|
||||
//import("BindingsResolver.js");
|
||||
//import("LocalBus.js");
|
||||
//import("Api.js");
|
||||
|
||||
global.postal = postal;
|
||||
return postal;
|
||||
}));
|
||||
16
src/main/postal.standard.js
Normal file
16
src/main/postal.standard.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
//import("VersionHeader.js");
|
||||
// This is the standard lib version of postal.js
|
||||
// If you need the amd-module style version, go to http://github.com/ifandelse/postal.js
|
||||
(function(_, global, undefined) {
|
||||
|
||||
//import("Constants.js");
|
||||
//import("DistinctPredicate.js");
|
||||
//import("ChannelDefinition.js");
|
||||
//import("SubscriptionDefinition.js");
|
||||
//import("BindingsResolver.js");
|
||||
//import("LocalBus.js");
|
||||
//import("Api.js");
|
||||
|
||||
global.postal = postal;
|
||||
|
||||
})(_, window);
|
||||
Loading…
Reference in a new issue