Skip to content

Instantly share code, notes, and snippets.

Embed
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 _ps.pub 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',
estimatedDeliveryTime;
ps.subscribe(EST_DELIVERY, function(msg, data) {
console.log(msg);
estimatedDeliveryTime = data;
});
return orders;
})(_ps);
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;
})(_ps;
deliveryModule.getEstimatedDeliveryTime();
});
@dxnn

This comment has been minimized.

Copy link

commented Oct 17, 2014

Typo on line 41:
})(_ps;
should be
})(_ps);

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.