# hoki

> Lightweight observer and dispatcher. No bloat.

Latest version **2.1.0** (published 2017-09-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install hoki
pnpm add hoki
yarn add hoki
bun add hoki
```

## 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 | 2.1.0 |
| Published | 2017-09-22 |
| First published | 2016-03-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Bjarne Oeverli |
| Maintainers | bjarneo |
| Keywords | observer, dispatcher, dispatch, observer, event, events, trigger, emit, emitter, listen, lightweight |

## Links

- npm: https://www.npmjs.com/package/hoki
- Repository: https://github.com/bjarneo/hoki
- Issues: https://github.com/bjarneo/hoki/issues
- npm.io page: https://npm.io/package/hoki

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

- 2.1.0 (latest) — 2017-09-22
- 2.0.1 — 2016-04-03
- 2.0.0 — 2016-04-01
- 1.2.3 — 2016-03-13
- 1.2.2 — 2016-03-13
- 1.2.1 — 2016-03-13
- 1.2.0 — 2016-03-12
- 1.1.2 — 2016-03-12
- 1.1.1 — 2016-03-12
- 1.1.0 — 2016-03-12
- 1.0.4 — 2016-03-12
- 1.0.3 — 2016-03-12
- 1.0.2 — 2016-03-11
- 1.0.1 — 2016-03-11
- 1.0.0 — 2016-03-11

## README

hoki
======
![Travis](https://travis-ci.org/bjarneo/hoki.svg?branch=master)

Lightweight observer and dispatcher.

Should cover basic use cases.

No bloat.

Clean code.

Installation
------
It's available on npm.
```
npm install --save hoki
```

How can I use this library?
------

Usage
------
API
```js
const {register, unregister, observer, dispatcher, events} = require('hoki');

// Can register an event or array of events
register(string || []);

// Can unregister an event or array of events
unregister(string || []);

// Can observe for an event, and fire a callback if the event occurs
observe(string, function);

// Dispatch an event with data. Can also dispatch an empty event
dispatch(string, function/object/string/number/etc);

// List all events
events();
```

Example
```js
const {register, dispatcher, observer} = require('hoki');

// Register your event
register('cat-names');

// Observe for an event
observer('cat-names', name => {
    console.log(name);
});
// output in correct order:
// furguson
// mittens
// boots

dispatcher('cat-names', 'furguson');
dispatcher('cat-names', 'mittens');
dispatcher('cat-names', 'boots');
```

You can also add multiple observers for the same event
```js
const {register, observer, dispatcher} = require('hoki');

register('cat-names');

observer('cat-names', console.log);
// output in correct order:
// furguson
// mittens
// boots

observer('cat-names', console.log);
// output in correct order:
// furguson
// mittens
// boots

dispatcher('cat-names', 'furguson');
dispatcher('cat-names', 'mittens');
dispatcher('cat-names', 'boots');
```

Listen once?
```js
const {register, unregister, observer, dispatcher} = require('hoki');

register('listenOnce');

observer('listenOnce', data => {
    unregister('listenOnce');
    
    console.log(data);
});

dispatcher('listenOnce', 'should run only once');
dispatcher('listenOnce', 'should run only once');

```

List all events available
```js
const {events} = require('hoki');

console.log(events());
// [ 'cat-names' ]
```

Unregister
```js
const {events, unregister} = require('hoki');

unregister('cat-names');
console.log(events());
// [ ]
```

Tests
------
```bash
$ npm test
```

Contribution
------
Contributions are appreciated.

License
------
MIT-licensed. See LICENSE.

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