Last active
August 29, 2015 14:16
-
-
Save RickEyre/ad6697be1caac1cbbaf2 to your computer and use it in GitHub Desktop.
Simple Pub Sub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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