emitter20
An event emitter in 20 lines of code.
Install
$ npm install --save emitter20
Usage
var Emitter = require('emitter20')
var emitter = new Emitter()
emitter.on('karate-chop', function() {
console.log('Haiaaaaaa!')
})
emitter.trigger('karate-chop')
Pass arbitrary data to the event handler:
var emitter = new Emitter()
emitter.on('welcome', function(name) {
console.log(`Welcome {name}!`)
})
emitter.trigger('welcome', 'bob')
Can be used as a mixin:
var assign = require('lodash.assign')
var obj = { a: 1, b: 2 }
assign(obj, new Emitter())
obj.on('karate-chop', function() {
console.log('Haiaaaaaa!')
})
obj.trigger('karate-chop')
License
ISC © Raine Lourie