# @antfu/ts-event

> Typescript Event Emitter

Latest version **0.1.2** (published 2019-07-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @antfu/ts-event
pnpm add @antfu/ts-event
yarn add @antfu/ts-event
bun add @antfu/ts-event
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2019-07-30 |
| First published | 2019-07-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=8.9 |
| Dependencies | 0 |
| Unpacked size | 20.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | antfu |

## Links

- npm: https://www.npmjs.com/package/@antfu/ts-event
- Repository: https://github.com/antfu/tsevent
- Homepage: https://github.com/antfu/tsevent#readme
- Issues: https://github.com/antfu/tsevent/issues
- npm.io page: https://npm.io/package/@antfu/ts-event

## Recent versions

- 0.1.2 (latest) — 2019-07-30
- 0.1.1 — 2019-07-30
- 0.1.0 — 2019-07-30

## README

<h1><b>TS</b>Event</h1>

Typescript Event Emitter with the same [API of VS Code](https://code.visualstudio.com/api/references/vscode-api#EventEmitter%3CT%3E)

## Basic Usage

```ts
class Counter {
  // define the emitter
  private _onChanged = new EventEmitter<number>()
  public readonly onChanged = this._onChanged.event

  private _value = 0

  get value() {
    return this._value
  }

  set value(v) {
    this._value = v
    this._onChanged.fire(this.value)
  }
}

const counter = new Counter()

counter.onChanged(n => { // n is number here
  console.log(`The new value is ${n}`)
})

counter.value = 5 // Output: The new value is 5
```

## License

[MIT](./LICENSE) © [antfu](https://github.com/antfu) 2019

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