2.3.2 • Published 6 years ago

emitus v2.3.2

Weekly downloads
7
License
MIT
Repository
github
Last release
6 years ago

Emitus npm npm Build Status JavaScript Style Guide

Small Typescript Event Emitter. :zap:

Some differences with Mitt

Mitt is a pretty cool and very small event emitter library out there, but Emitus differs with it in some aspects such as:

  • Emitus has been written and tested entirely in Typescript.
  • It uses an array of events instead of a hash.
  • It uses a simple for() iteration loop with if() controls, no map functions or coercion.
  • It doesn't support 'emit-all' or some wildcard feature.
  • Its size is just 285bytes minimized + gzipped (UMD) and 844bytes (CommonJS).

Install

Yarn

yarn add emitus --dev

NPM

npm install emitus --save-dev

UMD file is also available on unpkg:

<script src="https://unpkg.com/emitus/dist/emitus.umd.min.js"></script>

You can also use the library via window.emitus.

Usage

import { emitus, EmitusListener } from 'emitus'

interface Args { a: number, b: string }

const myArgs: Args = { a: 1, b: '2' }
const myEvent: EmitusListener<Args> = (name, args) => console.log(name, args)

const e = emitus()
e.on('MY_EVENT', myEvent)
e.emit('MY_EVENT', myArgs)

API

on

Register a custom event listener.

e.on (eventName: string, listener: EmitusListener): void

off

Unregister a custom event listener.

e.off (eventName: string, listener?: EmitusListener): void

emit

Calls listener registered for the event named eventName passing the supplied (optional) arguments.

e.emit (eventName: string, args?: any): void

Contributions

Feel free to send some pull request or issues.

License

MIT license

© 2018 José Luis Quintana

2.3.2

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.0

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago