# nanopubsub

> Tiny message bus

Latest version **1.0.0** (published 2017-03-03) · 0 weekly downloads

## Install

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

## 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.0 |
| Published | 2017-03-03 |
| First published | 2017-03-03 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Maintainers | yoshuawuyts |
| Keywords | message, bus, event, emitter, emit, send, node, frontend |

## Links

- npm: https://www.npmjs.com/package/nanopubsub
- Repository: https://github.com/yoshuawuyts/nanopubsub
- Homepage: https://github.com/yoshuawuyts/nanopubsub#readme
- Issues: https://github.com/yoshuawuyts/nanopubsub/issues
- npm.io page: https://npm.io/package/nanopubsub

## 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.0 (latest) — 2017-03-03

## README

# nanopubsub [![stability][0]][1]
[![npm version][2]][3] [![build status][4]][5] [![test coverage][6]][7]
[![downloads][8]][9] [![js-standard-style][10]][11]

Tiny message bus.

## Usage
```js
var nanopubsub = require('nanopubsub')
var bus = nanopubsub()

bus.on('flush', function () {
  console.log('all events done!')
})

bus.sub('beep:boop', function (data, done) {
  console.log('boop was called')
  done()
})

bus.pub('beep:boop', function () {
  console.log('calling beep:boop done!')
})
```

## FAQ
### How do I handle errors?
Emit an event like you'd do with everything else. There is no need for global
error handling because it can be implemented by consumers.

### How do I publish from a subscriber?
You can call `bus.pub` from inside `bus.sub` - wait with calling `done()` until
the `bus.pub` call has resolved to guarantee the right ordering of events.

### How do I namespace events?
This is done through convention. We recommend namespacing events using the `:`
separator (e.g. `bus.sub('foo:bar')`).

## API
### `bus = nanopubsub()`
Create a new message bus.

### `bus.sub(eventName, callback(data, done))`
Create a new subscriber for an event. `done()` should be called when the
subscriber is done.

### `bus.pub(eventName, [data], callback)`
Emit a new event with optional data attacked. The callback is called once all
handlers are done.

### `bus.on(eventName, callback)`
Listen to global events on the message bus. There are a few events available:
- `bus.on('flush')`: called when all `bus.pub` calls have resolved.
- `bus.on('pub')`: called every time a `bus.pub` call is fired. `eventName`
  and `data` are passed to the callback.

## License
[MIT](https://tldrlegal.com/license/mit-license)

[0]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square
[1]: https://nodejs.org/api/documentation.html#documentation_stability_index
[2]: https://img.shields.io/npm/v/nanopubsub.svg?style=flat-square
[3]: https://npmjs.org/package/nanopubsub
[4]: https://img.shields.io/travis/yoshuawuyts/nanopubsub/master.svg?style=flat-square
[5]: https://travis-ci.org/yoshuawuyts/nanopubsub
[6]: https://img.shields.io/codecov/c/github/yoshuawuyts/nanopubsub/master.svg?style=flat-square
[7]: https://codecov.io/github/yoshuawuyts/nanopubsub
[8]: http://img.shields.io/npm/dm/nanopubsub.svg?style=flat-square
[9]: https://npmjs.org/package/nanopubsub
[10]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[11]: https://github.com/feross/standard

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