# @appolo/events

> event-dispatcher

Latest version **8.0.2** (published 2020-11-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @appolo/events
pnpm add @appolo/events
yarn add @appolo/events
bun add @appolo/events
```

## 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 | 8.0.2 |
| Published | 2020-11-01 |
| First published | 2020-09-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 12.x.x |
| Dependencies | 0 |
| Unpacked size | 65.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Roman Svichar |
| Maintainers | shmoop207 |
| Keywords | event, events, dispatcher, event-dispatcher, appolo |

## Links

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

## 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

- 8.0.2 (latest) — 2020-11-01
- 8.0.1 — 2020-10-01
- 8.0.0 — 2020-09-01

## README

# Appolo Event Dispatcher
Fast and simple event dispatcher for node.js written in typescript.

## Installation:

```javascript
npm install @appolo/events --save
```

## Usage:

```javascript
import {EventDispatcher} from "appolo-event-dispatcher";
 
class EventHandler extends EventDispatcher {
    constructor() {
        super();
        setTimeout(() => this.fireEvent("test", "some value"), 100)
    }
}

let eventHandler = new EventHandler();

eventHandler.on("test", (value)=>{
        //do something
});

eventHandler.once("test", (value)=>{
        //do something
});

//or with promise
let value  = await eventHandler.once("test");



```



## API
#### `on(event,callback,[scope])`
add an event listener
  - `event` - event name.
  - `callback` - callback function that will triggered on event name.
  - `scope` - optional, the scope of the `callback` function default: `this`.

#### `once(event,[callback],[scope])`
add an event listener will be called only once if no callback passed a promise will be returned
  - `event` - event name.
  - `callback` - callback function that will triggered on event name.
  - `scope` - optional, the scope of the `callback` function default: `this`.


#### `un(event,callback,[scope])`
remove an event listener. All the arguments must be `===` to the onces used in the `on` method, or else it won\`t be removed.
  - `event` - event name.
  - `callback` - callback function.
  - `scope` - optional, the scope of the callback function.

#### `fireEvent(event,[arguments])`
fireEvent - triggers the callback functions of a given event name
  - `eventName` - name of the event
  - `arguments` -  all other `arguments` will be passed to the `callback` function
#### `removeAllListeners()`
removes all event listeners
#### `removeListenersByScope(scope)`
removes all event listeners by given scope

#### `hasListener(event,callback,[scope]):boolean`
return true if listener exists


## License
MIT

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