Skip to content

Instantly share code, notes, and snippets.

@RickEyre
Last active August 29, 2015 14:16
Show Gist options
  • Save RickEyre/ad6697be1caac1cbbaf2 to your computer and use it in GitHub Desktop.
Save RickEyre/ad6697be1caac1cbbaf2 to your computer and use it in GitHub Desktop.
Simple Pub Sub
var events = {}
function publish(e, message) {
var subscribers = events[e];
subscribers.map(function(sub) {
sub(message);
});
}
function on(e, cb) {
if (e in events) {
return events[e].push(cb);
}
events[e] = [cb];
}
module.exports.publish = publish;
module.exports.on = on;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment