Mittss
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 mittsssh
$ pnpm add -D mittsssh
$ yarn add -D mittsssh
$ yarn add -D mittsssh
$ bun add -D mittssDifferences from mitt
Emitter is forked from mitt, with the following key differences:
- Implemented using
class, supporting inheritance and extension. - Provides
oncemethod 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