@neumatter/event-emitter
v1.0.0
Published
An EventEmitter for client side and server side support.
Downloads
2
Maintainers
Readme
EventEmitter
An EventEmitter for client side and server side support.
Table of Contents
Install
npm i @neumatter/event-emitter
Usage
constructor:
Args: options?: { captureRejections?: boolean, maxListeners?: number }
import EventEmitter from '@neumatter/event-emitter'
// default options when undefined:
const eventEmitter = new EventEmitter({ captureRejections: false, maxListeners: 10 })
addListener | on:
Args: eventName: string, listener: (...args) => void
import EventEmitter from '@neumatter/event-emitter'
// default options when undefined:
const eventEmitter = new EventEmitter()
const errorHandler = (err) => {
console.error(err)
}
eventEmitter.addListener('error', errorHandler)
removeListener | off:
Args: eventName: string, listener: (...args) => void
import EventEmitter from '@neumatter/event-emitter'
// default options when undefined:
const eventEmitter = new EventEmitter()
const errorHandler = (err) => {
console.error(err)
}
eventEmitter.removeListener('error', errorHandler)
emit:
Args: eventName: string, ...args: any[]
import EventEmitter from '@neumatter/event-emitter'
// default options when undefined:
const eventEmitter = new EventEmitter()
eventEmitter.emit('error', new Error('error message'))