nanoevents

Simple and tiny (72 bytes) event emitter library

Usage no npm install needed!

<script type="module">
  import nanoevents from 'https://cdn.skypack.dev/nanoevents';
</script>

README

Nano Events

Simple and tiny event emitter library for JavaScript.

  • Only 97 bytes (minified and gzipped). It uses Size Limit to control size.
  • 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 on GitHub.