@occami/events
TypeScript icon, indicating that this package has built-in type declarations

0.1.16 • Public • Published

Events

Simplified dependency free EventEmitter as ES6 module with ~60 well readable LOC and ~0.7kb minified footprint for the browser.

Usage

import { EventEmitter } from '@occami/events'

const observable = new EventEmitter()

observable.on('message', console.log)
observable.emit('message', 'foo', 'bar')
// => foo bar

API - supported methods

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.


What is Occami?

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

Readme

Keywords

Package Sidebar

Install

npm i @occami/events

Weekly Downloads

1

Version

0.1.16

License

ISC

Unpacked Size

5.55 kB

Total Files

4

Last publish

Collaborators

  • ablay