teemitter
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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

Package Sidebar

Install

npm i teemitter

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

28.2 kB

Total Files

21

Last publish

Collaborators

  • noelheesen