# scoped-pubsub

> > Small publish & subscribe class

Latest version **1.0.3** (published 2023-07-08) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2023-07-08 |
| First published | 2023-05-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | vandeurenglenn |

## Links

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

## Dependencies (1)

- [@vandeurenglenn/little-pubsub](https://npm.io/package/@vandeurenglenn/little-pubsub.md) ^1.4.4

## Recent versions

- 1.0.3 (latest) — 2023-07-08
- 1.0.2 — 2023-05-10
- 1.0.1 — 2023-05-10

## README

# scoped-pubsub
> Small publish & subscribe class

## INSTALL

#### npm
```sh
npm i --save scoped-pubsub
```

## USAGE

```js
import PubSub from 'scoped-pubsub';
const pubsub = new PubSub();
```

## Example

```js
import PubSub from 'scoped-pubsub';
const pubsub = new PubSub();

pubsub.subscribe('event', value => { console.log(value) })

pubsub.publish('event', 'hello')

pubsub.unsubscribe('event', value => { console.log(value) })

pubsub.hasSubscribers('event')

await pubsub.once('event')
```

## API
### pubsub([options])
`verbose`: when false only fires after value change<br>
```js
pubsub = new PubSub({
  verbose: false // default: true
})
```

#### subscribe
`name`: name of the channel to subscribe to<br>
`handler`: method<br>
`context`: context<br>
```js
pubsub.subscribe('event-name', data => {
  console.log(data);
})
```
#### unsubscribe
`name`: name of the channel to unsubscribe<br>
`handler`: method<br>
`context`: context<br>
```js
pubsub.unsubscribe('event-name', data => {
  console.log(data);
})
```

#### publish
`name`: name of the channel to publish to<br>
`handler`: method<br>
`context`: context<br>
```js
pubsub.publish('event-name', 'data')
```

#### once
`name`: name of the channel to publish to<br>
```js
await pubsub.once('event-name')
```

#### hasSubscribers
`name`: name of the channel to publish to<br>
```js
pubsub.hasSubscribers('event-name')
```

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