teemitter
v1.0.1
Published
a simple typed event emitter
Downloads
2
Maintainers
Readme
Teemitter
A simple typed event emitter. That helps by pre-defining the events and event types.
Install
yarn add teemitter
npm install --save teemitter
Usage
import EventEmitter from 'teemitter'
type AllowedEvents = {
foo: string,
}
let tracker
// stand alone
tracker = new EventEmitter<AllowedEvents>()
class Tracker<T> extends EventEmitter<T> {}
// extending
tracker = new Tracker<AllowedEvents>()
tracker.on('foo', (x: string) => { /*do something with foo */ })
tracker.emit('foo', 'hi') // good
tracker.emit('foo', 1) // doesn't compile
tracker.emit('bar') // doesn't compile