yaemit
v2.0.0
Published
Microscopic event emitter.
Downloads
23
Maintainers
Readme
yaemit
Install
npm --save install yaemit
Example
Direct usage of Emitter:
import Emitter from 'yaemit'
const e = new Emitter()
const fn = (input) => console.log('hello', input)
e.on('event', fn)
e.emit('event', 'world')
Context binding for the event handler:
e.on('event', handler.bind(context))
Emitter can be extended:
class Hello extends Emitter {
constructor() {
this.on('event', this.hello)
}
hello(input) {
console.log('hello', input)
}
}
(new Hello()).emit('event', 'world')