# public-event-emitter

> A wrapper around eventemitter3 exposing only event handler addition and removal methods

Latest version **1.0.0** (published 2020-11-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install public-event-emitter
pnpm add public-event-emitter
yarn add public-event-emitter
bun add public-event-emitter
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-11-19 |
| First published | 2020-11-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Frédérique Mittelstaedt |
| Maintainers | gfmio |

## Links

- npm: https://www.npmjs.com/package/public-event-emitter
- Repository: https://github.com/gfmio/public-event-emitter
- npm.io page: https://npm.io/package/public-event-emitter

## Dependencies (1)

- [eventemitter3](https://npm.io/package/eventemitter3.md) ^4.0.7

## Recent versions

- 1.0.0 (latest) — 2020-11-19

## README

# public-event-emitter

This package provides a wrapper around [eventemitter3](https://www.npmjs.com/package/eventemitter3) that only exposes event handler addition and removal methods.

## Install

```sh
# If you use npm
npm install --save-dev public-event-emitter

# If you use yarn
yarn add public-event-emitter
```

## Usage

The main use case for `PublicEventEmitter` is to hide the `emit()` and other internal methods from the public interface of your class.

You can either inject an `EventEmitter` object manually if you want to use the `PublicEventEmitter` object directly or extend `PublicEventEmitter` in one of your own classes. In this case, the protected `eventEmitter` object will be available in your subclass.

```ts
import { EventEmitter } from "eventemitter3";
import { PublicEventEmitter } from "public-event-emitter";

interface MyEventMap {
  event1: (n: number) => void;
  event2: (s: string) => void;
  error: (error: Error) => void;
}

// Option 1: Manually create an event emitter object

const eventEmitter = new EventEmitter<MyEventMap>();
const publicEventEmitter = new PublicEventEmitter<MyEventMap>(eventEmitter);

publicEventEmitter.on("event1", (n) => console.log(n));
eventEmitter.emit("event1", 42);

// Option 2: Inherit from PublicEventEmitter

class MyClass extends PublicEventEmitter<MyEventMap> {
  public someMethod() {
    this.eventEmitter.emit("event1", 42);
  }
}

const o = new MyClass();

o.on("event1", (n) => console.log(n));
o.someMethod();
```

## License

[MIT](LICENSE)

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