# @pdw.io/event-dispatcher

> Performant event dispatcher.

Latest version **1.0.0** (published 2022-03-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @pdw.io/event-dispatcher
pnpm add @pdw.io/event-dispatcher
yarn add @pdw.io/event-dispatcher
bun add @pdw.io/event-dispatcher
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-03-06 |
| First published | 2022-03-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Pim de Wit |
| Maintainers | pdw.io |
| Keywords | event, dispatcher, typescript |

## Links

- npm: https://www.npmjs.com/package/@pdw.io/event-dispatcher
- Repository: https://github.com/pimdewit/event-dispatcher
- Homepage: https://github.com/pimdewit/event-dispatcher#readme
- Issues: https://github.com/pimdewit/event-dispatcher/issues
- npm.io page: https://npm.io/package/@pdw.io/event-dispatcher

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2022-03-06

## README

# EventDispatcher

Performant, opinionated event dispatcher.

## Installation

`npm install @pdw.io/event-dispatcher`

## Usage

Below is a very minimal example. The main thing to note is that the "event names" are strictly numbers (Enum keys in this case), this is where the performance comes from.

```typescript
import { EventDispatcher } from '@pdw.io/eventdispatcher';

export enum DialogEventName {
  OPEN,
  CLOSE,
}

class Dialog extends EventDispatcher<DialogEventName> {
  private open = false;

  toggle() {
    this.open = !this.open;
    const eventToSend = this.open ? DialogEventName.OPEN : DialogEventName.CLOSE;
    this.dispatchEvent(eventToSend);
  }
}

const dialog = new Dialog();
dialog.addEventListener(DialogEventName.OPEN, callback);
```

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