Created
August 29, 2019 18:04
-
-
Save jyotiarora2610/af024949868554218ccd3383217d7d51 to your computer and use it in GitHub Desktop.
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
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