Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Even more decoupled than the original - pass dependencies in as args so that they can be easily changed later
document.addEventListener("DOMContentLoaded", function(event) {
Later you can easily change this to any other PubSub library you like.
var _pubSub = PubSub;
or you can even wrap it to define your own API. This way, later on
you can still continue to use _ps.sub and even if you change
out the library defining that behaviour. Let's go with the latter.
var _ps = {
pub: PubSub.publish,
sub: PubSub.subscribe
var orderModule = (function(ps) {
var orders = {},
EST_DELIVERY = 'current estimated delivery time',
ps.subscribe(EST_DELIVERY, function(msg, data) {
estimatedDeliveryTime = data;
return orders;
var deliveryModule = (function(ps) {
var deliveries = {},
EST_DELIVERY = 'current estimated delivery time';
deliveries.getEstimatedDeliveryTime = function() {
var estimatedDeliveryTime = 1; // Hard-coded to 1 hour, but likely an API call.
ps.publish(EST_DELIVERY, estimatedDeliveryTime);
return deliveries;

This comment has been minimized.

Copy link

dxnn commented Oct 17, 2014

Typo on line 41:
should be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.