zen-mitt
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

zen-mitt

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

Install

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

Usage

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

import { Mitt } from 'zen-mitt'

const events = new Mitt()

License

MIT

/zen-mitt/

    Package Sidebar

    Install

    npm i zen-mitt

    Weekly Downloads

    59

    Version

    3.0.0

    License

    MIT

    Unpacked Size

    12.1 kB

    Total Files

    12

    Last publish

    Collaborators

    • subframe7536