Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/subframe7536/zen-mitt
- Owner: subframe7536
- License: mit
- Created: 2023-11-01T11:30:51.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-08-26T09:30:31.000Z (4 months ago)
- Last Synced: 2024-08-26T11:53:04.565Z (4 months ago)
- Topics: mitt
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/zen-mitt
- Size: 85 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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