# cobu-eventbus

> cobu-eventbus is a simple, lightweight and flexible JavaScript library to manage events.

Latest version **1.0.1** (published 2018-11-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install cobu-eventbus
pnpm add cobu-eventbus
yarn add cobu-eventbus
bun add cobu-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.1 |
| Published | 2018-11-17 |
| First published | 2014-08-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 29.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Christian Schuller |
| Maintainers | cschuller |

## Links

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

## Recent versions

- 1.0.1 (latest) — 2018-11-17
- 1.0.0 — 2018-11-17
- 0.14.0 — 2018-02-13
- 0.13.0 — 2014-10-19
- 0.12.0 — 2014-10-13
- 0.11.4 — 2014-09-05
- 0.11.3 — 2014-09-05
- 0.11.2 — 2014-09-04
- 0.11.1 — 2014-08-31
- 0.11.0 — 2014-08-31

## README

**[INACTIVE]** This library is no longer active. For an alternative take a look at [RxJs](https://github.com/Reactive-Extensions/RxJS).

# cobu-eventbus
[![Build Status](https://api.travis-ci.org/cschuller/cobu-eventbus.svg?branch=master)](http://travis-ci.org/cschuller/cobu-eventbus)
[![GitHub version](https://badge.fury.io/gh/cschuller%2Fcobu-eventbus.svg)](http://badge.fury.io/gh/cschuller%2Fcobu-eventbus)
[![NPM version](https://badge.fury.io/js/cobu-eventbus.svg)](http://badge.fury.io/js/cobu-eventbus)

cobu-eventbus is a simple, lightweight and flexible JavaScript library to manage events.
It works using strings or objects (even 'strong typed') as events.
You define what an event is, cobu-eventbus will support it.

The purpose of an event bus is to decouple components. This pattern is very
important for large scale JavaScript applications to be maintainable.

## Getting started

```npm install cobu-eventbus```

## Examples

### Simple scenario using a string as an event.

```js
// Create the EventBus instance.
var eventBus = new cobu.EventBus();

// Create an callback function that can handle the specific event.
function handleFooEvent(event) {
   console.log('Handling a foo event');
}

// Register the callback function to an event type.
eventBus.on('foo', handleFooEvent);

// Post an event
eventBus.post('foo');
```

### Using an object as an event

```js
// Create the EventBus instance.
var eventBus = new cobu.EventBus();

// Define a constructor function to create the helloEvent object later.
function HelloEvent(name) {
    this.type = 'helloEvent';
    this.name = name;
}

// Create an callback function that can handle the specific event type.
function handleHelloEvent(event) {
    console.log('Hello ' + event.name);
};

// Register the callback function to an event type.
eventBus.on(HelloEvent, handleAlertEvent);

// Post a new event.
eventBus.post(new HelloEvent('foo'));
```

## API

## Statistics for nerds

Performance difference between version 0.14.0 and 1.0.0

| Performance       | Scenario |
| --- 				| --- |
| 10x - 100x faster | posting an event when using a lot of context and handlers |
| 50% smaller       | file size |
| 25% slower        | when adding / removing an event handler |

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