# c-pubsub

> simple publish/subscribe mode

Latest version **1.0.0** (published 2018-02-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install c-pubsub
pnpm add c-pubsub
yarn add c-pubsub
bun add c-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 | 2018-02-01 |
| First published | 2017-07-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | pspgbhu |
| Maintainers | pspgbhu |
| Keywords | c-pubsub |

## Links

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

## 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) — 2018-02-01
- 0.1.6 — 2017-08-02
- 0.1.5 — 2017-07-28
- 0.1.4 — 2017-07-25
- 0.1.3 — 2017-07-24
- 0.1.2 — 2017-07-24
- 0.1.1 — 2017-07-24

## README

# c-pubsub

simple publish/subscribe mode. 一套发布订阅模式，可快速的订阅及发布事件。

## Insatll

```bash
npm i -S c-pubsub
```

## Usage

`pubsub.on` 订阅事件， `pubsub.emit` 发布事件

```js
import pubsub from 'c-pubsub';

// 订阅事件
pubsub.on('event', (arg) => {
  console.log(arg);
});

// 发布事件
pubsub.emit('event', 'Hello');

// Hello
```

`pubsub.one` 也可以订阅一次性事件，监听到一次事件后就会自动卸载事件。

```js
pubsub.one('event', (arg) => {
  console.log(arg);
});

pubsub.emit('event', 'Hello'); // Hello

pubsub.emit('event', 'Hello'); // 已经自动卸载过事件了，所不会有反应。
```

`pubsub.off` 可以卸载事件，会卸载该事件下的所有回调。

```js
pubsub.on('event', (arg) => {
  console.log('1', arg);
});

pubsub.on('event', (arg) => {
  console.log('2', arg);
});

pubsub.one('event', (arg) => {
  console.log('3', arg);
});

pubsub.off('event'); // 卸载了 event 事件

pubsub.emit('event', 'Hello'); // 不会有任何反应，因为所有监听 event 的回调函数都被卸载了。
```

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