Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/subframe7536/zen-mitt

light-weight(187B min+gzip) typesafe event emitter
https://github.com/subframe7536/zen-mitt

mitt

Last synced: 27 days ago
JSON representation

light-weight(187B min+gzip) typesafe event emitter

Awesome Lists containing this project

README

        

# zen-mitt

light-weight(187B min+gzip) typesafe event emitter

## Install

```sh
npm install zen-mitt
```
```sh
yarn add zen-mitt
```
```sh
pnpm add zen-mitt
```

## Usage

```ts
import { mitt } from 'zen-mitt'

const events = mitt<{
foo: [data: number]
arr: [data: string[]]
param: [name: string, age?: number]
}>()
events.on('foo', console.log)
events.emit('foo', 1)

events.on('arr', console.log)
events.emit('arr', ['test'])
events.off('arr')

events.once('param', console.log)
events.emit('param', 'test', 1)

events.off() // clear all listeners
```

### Class version

```ts
import { Mitt } from 'zen-mitt/class'

const events = new Mitt()
```

## License

MIT