Skip to content

jcoreio/typed-event-emitter

Repository files navigation

@jcoreio/typed-event-emitter

CircleCI Coverage Status semantic-release Commitizen friendly npm version

fully type-safe EventEmitter flow declaration

Usage

npm install --save @jcoreio/typed-event-emitter
// @flow

import EventEmitter from '@jcoreio/typed-event-emitter'

function createEmitter(): EventEmitter<{
  eventA: [string],
  eventB: [string, number],
}>

const emitter = createEmitter()

emitter.on('eventA', (foo: string) => {...})
emitter.on('eventB', (foo: string, bar: number) => {...})

emitter.emit('eventA', 'foo')
emitter.emit('eventB', 'foo', 1)