nanoevents

v9.0.0
Simple and tiny (107 bytes) event emitter library
EventEmitter Events emit emitter event pub/sub publish reactor subscribe and 1 more...

Nano Events

Simple and tiny event emitter library for JavaScript.

  • Only 107 bytes (minified and brotlied). It uses Size Limit to control size.
  • The on method returns unbind function. You don’t need to save callback to variable for removeListener.
  • TypeScript and ES modules support.
  • No aliases, just emit and on methods. No Node.js EventEmitter compatibility.
import { createNanoEvents } from 'nanoevents'

const emitter = createNanoEvents()

const unbind = emitter.on('tick', volume => {
  summary += volume
})

emitter.emit('tick', 2)
summary //=> 2

unbind()
emitter.emit('tick', 2)
summary //=> 2
Sponsored by Evil Martians

Docs

Read full docs here.

npm i nanoevents

Metadata

  • MIT
  • ^18.0.0 || >=20.0.0
  • Andrey Sitnik
  • released 11/23/2023

Downloads

Maintainers