Skip to content

Instantly share code, notes, and snippets.

@jyotiarora2610
Created August 29, 2019 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jyotiarora2610/af024949868554218ccd3383217d7d51 to your computer and use it in GitHub Desktop.
Save jyotiarora2610/af024949868554218ccd3383217d7d51 to your computer and use it in GitHub Desktop.
let subscribers = {};
module.exports = {
publish(event, data) {
if (!subscribers[event]) return;
subscribers.forEach(callback => {
callback(data);
})
},
subscribe(event, callback) {
if (!subscribers[event]) {
subscribers[event] = [];
}
subscribers[event].push(callback);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment