# singleton-pubsub

> A performant pub/sub interface wrapped in a singleton

Latest version **1.0.0** (published 2017-11-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install singleton-pubsub
pnpm add singleton-pubsub
yarn add singleton-pubsub
bun add singleton-pubsub
```

## 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-11-19 |
| First published | 2017-11-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | john.n.sylvain@gmail.com |
| Maintainers | johnsylvain |

## Links

- npm: https://www.npmjs.com/package/singleton-pubsub
- Repository: https://github.com/johnsylvain/singleton-pubsub
- Homepage: https://github.com/johnsylvain/singleton-pubsub#readme
- Issues: https://github.com/johnsylvain/singleton-pubsub/issues
- npm.io page: https://npm.io/package/singleton-pubsub

## Recent versions

- 1.0.0 (latest) — 2017-11-19
- 0.0.4 — 2017-11-11
- 0.0.3 — 2017-11-11
- 0.0.2 — 2017-11-11
- 0.0.1 — 2017-11-11

## README

# Singleton Pubsub
[![Travis](https://img.shields.io/travis/johnsylvain/singleton-pubsub.svg)](https://travis-ci.org/johnsylvain/singleton-pubsub)
[![npm](https://img.shields.io/npm/v/singleton-pubsub.svg)](https://npmjs.org/package/singleton-pubsub)
![dependancies](https://img.shields.io/badge/dependencies-zero-brightgreen.svg)
> A performant Pub/Sub interface wrapped in a singleton

## Features
- Super tiny (~210b g-zipped)
- No dependencies
- Small API with method chaining
- Singleton impletation for usage in large applications
- Create multiple functions for a single event

## Installation
```bash
# via yarn
yarn add singleton-pubsub

# via npm
npm install singleton-pubsub --save
```
#### or via [download](https://raw.githubusercontent.com/johnsylvain/singleton-pubsub/master/index.js)
```html
<script src="path/to/singleton-pubsub.js"></script>
```

## Usage
```js
import SingletonPubsub from 'singleton-pubsub'

// Instantiate a default instance
const pubsub = new SingletonPubsub();

// Instantiate a named instance
const altPubsub = new SingletonPubsub('alternate');

// Subscribe to events via handlers
pubsub
  .on('load', ({ message }) => {
    console.log(message) // => 'loaded!'
  })
  .on('event', (data) => {
    console.log(data)
  })

// Emit (publish) events
pubsub
  .emit('load', {
    message: 'loaded!'
  })

// Unsubscribe from an event
const onEvent = (data) => console.log(data)

pubsub
  .on('event', onEvent)
  .off('event', onEvent)

// Creating a new instance will give access to the same events
const pubsub2 = new SingletonPubsub()

pubsub2
  .emit('load', {
    message: 'pubsub2 works!'
  })


// Create a new clean instance in the same application
const cleanPubsub = new SingletonPubsub('instance', {
  reinstantiate: true
})
```


## Contributing
You can request a new feature by submitting an issue. If you would like to implement a new feature feel free to issue a Pull Request.

## License
singleton-pubsub is protected under the [MIT License](https://github.com/johnsylvain/singleton-pubsub/blob/master/LICENSE)

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