# callback-registry

> Registry for callbacks

Latest version **2.7.2** (published 2021-06-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install callback-registry
pnpm add callback-registry
yarn add callback-registry
bun add callback-registry
```

## 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 | 2.7.2 |
| Published | 2021-06-15 |
| First published | 2016-07-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Kiril Popov |
| Maintainers | kiril.popov, misho-t42 |
| Keywords | callbacks, registry, store, dispatcher |

## Links

- npm: https://www.npmjs.com/package/callback-registry
- Repository: https://github.com/kirilpopov/callback-registry
- Homepage: https://github.com/kirilpopov/callback-registry#readme
- Issues: https://github.com/kirilpopov/callback-registry/issues
- npm.io page: https://npm.io/package/callback-registry

## Recent versions

- 2.7.2 (latest) — 2021-06-15
- 2.7.1 — 2020-11-06
- 2.6.0 — 2020-07-08
- 2.5.2 — 2019-10-19
- 2.5.1 — 2019-05-22
- 2.4.0 — 2018-12-12
- 2.3.3 — 2018-08-24
- 2.3.2 — 2018-08-15
- 2.3.1 — 2017-08-14
- 2.3.0 — 2017-08-14
- 2.2.7 — 2017-06-17
- 2.2.6 — 2017-06-17
- 2.2.5 — 2017-04-25
- 2.2.4 — 2017-04-25
- 2.2.3 — 2017-04-25
- … 7 more at https://npm.io/package/callback-registry/versions

## README

# Intro

A simple registry for callbacks that allows you to add one or more callbacks
under some key and then execute all callbacks under some key.

Example:

```javascript
const registryFactory = require('callback-registry');

const registry = registryFactory();

// add a new callback for that event key
registry.add('event-key', function(){
    console.log('the event occurred')
});

// execute all callbacks that were registred for that key
registry.execute('event-key');
```

# Passing arguments
You can pass any arguments to the callbacks when you execute them

```javascript
// execute all callbacks that were registred for that key
registry.execute('event-key', arg1, arg2, arg3);
```

# Returning results
The _execute_ method returns an array with the results returned from the callbacks.

# Removing a callback
When you add a new callback a function is returned that can be used to unsubscribe

```javascript

// A callback that will be called just the first time
var unsubscribe = registry.add('event-key', function(){
    console.log('the event occurred');
    unsubscribe();
});

```
# Change log
* 2.7.2
    dependencies update
* 2.7.1
	fixed potentional memory leak
* 2.6.0
    added replayArgumentsArr that allows you to replay arguments to a new callback
* 2.5.0
    added clearKey method that removes a key from the registry
* 2.3.2
  * fix case where unsubscribe function removes all subscriptions with the same callback reference
* 2.1.1
  * return empty array as result if no subscribers
  * catch errors in user callbacks (returns undefined in the result if error)

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