Simplified dependency free EventEmitter as ES6 module with ~60 well readable LOC and ~0.7kb minified footprint for the browser.
import { EventEmitter } from '@occami/events'
const observable = new EventEmitter()
observable.on('message', console.log)
observable.emit('message', 'foo', 'bar')
// => foo bar
declare type Listener = (...args: any[]) => void
addListener(eventName: string, listener: Listener): EventEmitter
on(eventName: string, listener: Listener): EventEmitter
once(eventName: string, listener: Listener): EventEmitter
emit(eventName: string, ...args: any[]): boolean
removeListener(eventName: string, listener: Listener): EventEmitter
off(eventName: string, listener: Listener): EventEmitter
removeAllListeners(eventName: string): EventEmitter
eventNames(): string[]
listenerCount(eventName: string): number
Behaviour as specified in NodeJS EventEmitter
See events if you're missing out functionality from the original spec.
A collection of modules with these characteristics:
- as simple as possible
- few dependencies (mostly none)
- easy to read & review
- small footprint
- require an ES6 compliant runtime
- not minified, assuming you're bundling anyways
- type definitions included