@fingerartur/ts-event-emitter
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Event emitter

Simple Typescript event emitter

type Events = 'valuechange' | 'timeupdate'

const emitter = new EventEmitter<Events>()

const listener = (state: string) => {
    // ...
}

emitter.addEventListener('valuechange', listener)

emitter.triggerEvent('valuechange', 'value1')
emitter.triggerEvent('valuechange', 'value2')

emitter.removeEventListener('valuechange', listener)

emitter.removeAllEventListeners('valuechange')

// Remove all listeners of all events
emitter.clear()

Readme

Keywords

Package Sidebar

Install

npm i @fingerartur/ts-event-emitter

Weekly Downloads

28

Version

1.0.3

License

ISC

Unpacked Size

5.13 kB

Total Files

10

Last publish

Collaborators

  • fingerartur