Created
September 13, 2017 12:42
-
-
Save mariano-aguero/cb5a11a1102fad3bac8932a285dc9cd2 to your computer and use it in GitHub Desktop.
Event bus
This file contains hidden or 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
// Definition | |
const EventEmitter = require('events'); | |
const emitter = new EventEmitter(); | |
emitter.on('uncaughtException', function (err) { | |
console.error(err); | |
}); | |
module.exports = emitter; | |
// Usage | |
let bus = require('../path/to/eventBus'); | |
// Register event listener | |
bus.on('eventName', function () { | |
console.log('triggered!'); | |
}); | |
// Trigger the event somewhere else | |
bus.emit('eventName'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment