# @aster-js/events

> Aster events library part of Aster js library

Latest version **1.3.0** (published 2024-01-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install @aster-js/events
pnpm add @aster-js/events
yarn add @aster-js/events
bun add @aster-js/events
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2024-01-14 |
| First published | 2021-01-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 39 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | sebdoucet |
| Maintainers | aster-js |

## Links

- npm: https://www.npmjs.com/package/@aster-js/events
- Repository: https://github.com/asterlibraryjs/aster-js-events
- Homepage: https://github.com/asterlibraryjs/aster-js-events#readme
- Issues: https://github.com/asterlibraryjs/aster-js-events/issues
- npm.io page: https://npm.io/package/@aster-js/events

## Dependencies (3)

- [tslib](https://npm.io/package/tslib.md) ^2.6.2
- [@aster-js/core](https://npm.io/package/@aster-js/core.md) ^1.3.0
- [@aster-js/decorators](https://npm.io/package/@aster-js/decorators.md) ^1.1.0

## Recent versions

- 1.3.0 (latest) — 2024-01-14
- 1.2.0 — 2022-01-22
- 1.0.2 — 2021-03-09
- 1.0.1 — 2021-02-07
- 1.0.0 — 2021-02-01
- 1.0.0-beta.1 — 2021-01-17

## README

# @aster-js/events

Provides proper separation between the emitter and the event.

## Declaration

```ts
import { EventEmitter, IEvent } from "@aster-js/events";

class DataLoader<T> {
    private readonly _onDataLoaded = new EventEmitter<T>();

    get onDataLoaded(): IEvent<[T]> { return this._onDataLoaded.event; }

    fetchData(): Promise<void> {
        fetch("https://myapi.io/data")
            .then(r => r.json())
            .then(data => this._onDataLoaded.trigger(data));
    }
}
```

## Usage

```ts
type DataItem = { id: number, name: string };

const loader = new DataLoader<DataItem[]>();

loader.onDataLoaded((items: DataItem[])=> {
    // Do stuff
});
```

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