# @perdugames/eventbus

> Event Bus API for JavaScript.

Latest version **1.0.3** (published 2019-01-03) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install @perdugames/eventbus
pnpm add @perdugames/eventbus
yarn add @perdugames/eventbus
bun add @perdugames/eventbus
```

## 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.3 |
| Published | 2019-01-03 |
| First published | 2018-12-21 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 97.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | perdugames |
| Maintainers | perdugames |
| Keywords | eventbus, event, event-emitter |

## Links

- npm: https://www.npmjs.com/package/@perdugames/eventbus
- Repository: https://github.com/perdugames/eventbus
- Homepage: https://github.com/perdugames/eventbus#readme
- Issues: https://github.com/perdugames/eventbus/issues
- npm.io page: https://npm.io/package/@perdugames/eventbus

## 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.3 (latest) — 2019-01-03
- 1.0.2 — 2018-12-23
- 1.0.1 — 2018-12-22
- 1.0.0 — 2018-12-21

## README

# EventBus
## EventBus API in JavaScript.

### How to install EventBus

For npm: 

```
npm i @perdugames/eventbus
```

For browsers: 

```
https://unpkg.com/@perdugames/eventbus@VERSION/build/eventbus-VERSION.js
```

### How to use EventBus

```javascript

// 'import EventBus from '@perdugames/eventbus.js';' only with Babel, 
// without Babel use 'const EventBus = require('@perdugames/eventbus.js');'
import EventBus from '@perdugames/eventbus.js';

const eventBus = new EventBus();

/* Use "once" for when you want to perform the listener function only once. */
eventBus.once('event1', function(text) {
    console.log(text);
});

eventBus.emit('event1', 'I exist?');
eventBus.emit('event1', 'I exist?');

// Result console: 
//      I exist?


/* Use "on" for when you want to perform the listener function multiple times. */
eventBus.on('event1', function(text) {
    console.log(text);
});

eventBus.emit('event1', 'I exist?');
eventBus.emit('event1', 'I exist?');

// Result console: 
//      I exist?
//      I exist?

```

## API

**eventBus.getListenerCountOfEvent(eventName):** Returns the number of listeners for a given event.

**eventBus.once(eventName, listenerFunction):** Adds a listener to an event that will be called only once, after the function is executed, it is removed from the listeners array of that event.

**eventBus.on(eventName, listenerFunction):** Adds a listener to an event, which will be called every time the event is issued.

**eventBus.off(eventName, listenerFunction):** Removes a listener from a given event.

**eventBus.emit(eventName, args):** Issuing an event, which causes all the listeners functions to be called from the issued event, it is possible to pass arguments so that the listener's functions can access.

**eventBus.getAllEventsName():** Returns all event names in an EventBus.

**eventBus.getAllListenersOfEvent(eventName):** Returns all listeners of a given event.

**eventBus.removeAllListenersOfEvent(eventName):** Removes all listeners from an event.

**Event “addListener” and “removeListener”:** There are two standard EventBus events, "addListener" is issued when a new listener is added to an event, while "removeListener" is called when a listener is removed from an event.

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