# events-pool

> Accumulate multiple events (and their data) from different sources into a single pool.

Latest version **0.2.3** (published 2017-08-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install events-pool
pnpm add events-pool
yarn add events-pool
bun add events-pool
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2017-08-27 |
| First published | 2017-08-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Artem Zakharchenko |
| Maintainers | kettanaito |
| Keywords | event, events, pool, event pool, events pool |

## Links

- npm: https://www.npmjs.com/package/events-pool
- Repository: https://github.com/kettanaito/events-pool
- Homepage: https://github.com/kettanaito/events-pool#readme
- Issues: https://github.com/kettanaito/events-pool/issues
- npm.io page: https://npm.io/package/events-pool

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

- 0.2.3 (latest) — 2017-08-27
- 0.2.2 — 2017-08-25
- 0.2.1 — 2017-08-18
- 0.2.0 — 2017-08-18
- 0.1.0 — 2017-08-18

## README

<p align="center">
  <a href="https://www.npmjs.com/package/events-pool" title="NPM version">
    <img src="https://img.shields.io/npm/v/events-pool.svg" />
  </a>
  <a href="https://www.npmjs.com/package/events-pool" title="Dependency status">
    <img src="https://david-dm.org/kettanaito/events-pool.svg" />
  </a>
  <img src="https://travis-ci.org/kettanaito/events-pool.svg?branch=master" title="Build Status">
  <a href="https://coveralls.io/github/kettanaito/events-pool?branch=master">
    <img src="https://coveralls.io/repos/github/kettanaito/events-pool/badge.svg?branch=master" alt="Coverage Status" />
  </a>
</p>

<p align="center">
  <a href="https://github.com/kettanaito/events-pool">
    <img src="./icon.png" />
  </a>
</p>

# Events pool
Accumulate multiple events from different sources into a single pool and dispatch a callback function afterward. Supports data aggregation as well!

## Getting started
### Installation
Install `events-pool` using NPM:
```
npm install events-pool --save
```

### Usage
```js
import EventsPool from 'events-pool';

/* Create a new event pool */
new EventsPool({
  events: 'promotionView',
  target: carouselDOMElement,
  callback(events, data) {
    dataLayer.push(data);
  }
});

/* Dispatch a custom event with data */
const promoViewEvent = new CustomEvent('promotionView', {
  /* Accumulated data is accessible from callback's "data" argument */
  detail: { ... }
});

carouselDOMElement.dispatchEvent(promoViewEvent);
```

### Options
#### `events: Array<string> | string`
A single event or a list of event names to listen to.

#### `eventTarget: EventTarget`
**Default:** `document`

Target (DOMElement) which is expected to dispatch the event(s).

#### `timeout: number`
A duration (ms) of the timeout. When `aggregate: true`, stands for a time limit within which a new event is expected after catching the previous one.

#### `callback: Function(events: Array<CustomEvent | Event>, data: Array<mixed>)`
A callback function executed once the timeout is reached. An instance of each caught event (`Event` or `CustomEvent`) is being accumulated into a single pool available under the `events` argument.

Each data provided through `CustomEvent.detail` is accumulated and accessible under the `data` argument.

#### `aggregate: boolean`
**Default:** `false`
Enable/disable aggregation mode. When the latter is enabled, each caught event prolongs the time within which the pool expects to receive a new event by the amount of `timeout`. Once no events are received within this time period, a `callback` function is called.

## Contribution
Please see the [Contribution guide](./CONTRIBUTING.md) if you would like to contribute to this repository. Thank you.

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