Skip to content

Mittss

MITNPM VersionGitHub Repo starsGitHub Actions Workflow Statusnpm package minimized gzipped size

forked from mitt

What is Mittss?

Mittss is an lightweight and simple event emitter / pubsub, rewrite the mitt using a class.

  • Lightweight: sizes less than 300 bytes gzipped
  • Useful: a wildcard "*" event type listens to all events
  • Familiar: same names & ideas as Node's EventEmitter
  • Extendable: easily extendable with inheritance.
  • Zero Dependencies: works out of the box without additional dependencies.

Installation

sh
$ npm add -D mittss
sh
$ pnpm add -D mittss
sh
$ yarn add -D mittss
sh
$ yarn add -D mittss
sh
$ bun add -D mittss

Differences from mitt

Emitter is forked from mitt, with the following key differences:

  • Implemented using class, supporting inheritance and extension.
  • Provides once method for one-time event listeners.

Usage

javascript
import { Emitter } from 'mittss'

// Create a Emitter instance
const emitter = new Emitter()

// listen to an event
emitter.on('foo', e => console.log('foo', e))

// listen to all events
emitter.on('*', (type, e) => console.log(type, e))

// fire an event
emitter.emit('foo', { a: 'b' })

// console.log
// { a: 'b' }
// foo { a: 'b' }

Acknowledgments

Thanks to mitt again for the inspiration.

License

MIT © nnecec

MIT License.