# micro-events

> A very, very simple event emitter implementation.

Latest version **1.0.0** (published 2014-12-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install micro-events
pnpm add micro-events
yarn add micro-events
bun add micro-events
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2014-12-02 |
| First published | 2014-12-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/micro-events) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | Alexander Gugel |
| Maintainers | alexandergugel |

## Links

- npm: https://www.npmjs.com/package/micro-events
- Repository: https://github.com/alexanderGugel/micro-events
- Issues: https://github.com/alexanderGugel/micro-events/issues
- npm.io page: https://npm.io/package/micro-events

## Recent versions

- 1.0.0 (latest) — 2014-12-02

## README

# micro-events

> A very, very simple event emitter implementation.

## Features

* no dependencies
* very small (~ 80 LoC)
* smart memory leak detection
* lighting fast
* unopinionated and minimal
* works in the browser and on Node.JS
* checks arguments
* emits useful events

## How can I use this?

```javascript
    var EventEmitter = require('micro-events');
    var myEventEmitter = new EventEmitter();

    // Maximum number of listeners (used to prevent memory leaks and dumb code)
    // - defaults to 10
    myEventEmitter.maxListeners = 20;

    // Implement listener
    var onRun = function (explosion) {
        console.log(explosion);
    };

    // Register onRun event listener
    myEventEmitter.on('explosion', onRun);

    setTimeout(function () {
        // Deregister event listener after 5 seconds
        myEventEmitter.off('explosion', onRun);
    }, 5000);

    setInterval(function () {
        if (Math.random() < 0.1) {
            // Emit explosion event
            myEventEmitter.emit('explosion', {
                t: new Date().getTime()
            });
        } else {
            // Emit noExplosion event
            myEventEmitter.emit('noExplosion', {
                t: new Date().getTime()
            });
        }
    }, 100);

```

## How can I extend this?

Just like you would extend any other "class".

```javascript
    var EventEmitter = require('micro-events');

    var MyEventEmitter = function () {
        EventEmitter.call(this);
    };

    MyEventEmitter.prototype = Object.create(EventEmitter.prototype);
    MyEventEmitter.prototype.constructor = MyEventEmitter;
```

If possible, it is recommended to use/ mix in individual methods as opposed to
extending the super class.

---
_Source: https://npm.io/package/micro-events · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
