# publish-subscribe-pattern

> 发布订阅

Latest version **1.0.1** (published 2021-11-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install publish-subscribe-pattern
pnpm add publish-subscribe-pattern
yarn add publish-subscribe-pattern
bun add publish-subscribe-pattern
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-11-24 |
| First published | 2021-11-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ygy |
| Maintainers | tj_ygy |
| Keywords | 发布订阅 |

## Links

- npm: https://www.npmjs.com/package/publish-subscribe-pattern
- npm.io page: https://npm.io/package/publish-subscribe-pattern

## Recent versions

- 1.0.1 (latest) — 2021-11-24
- 1.0.0 — 2021-11-24

## README

# publish-subscribe-pattern

>  author：ygy
>
> 发布订阅模式：应用场景为前端页面记录用户操作步骤
>
> 参考：https://www.cnblogs.com/beyonds/p/13590773.html
>
> A typeScript project

## Setup

``` bash
npm i publish-subscribe-pattern
```

### use

```typescript
// 使用示例
import byEvent from 'publish-subscribe-pattern'
let event = new byEvent()
setInterval(() => {
    event.emit("name", 123) // 注册name的监听
    event.emit("name", 10, 20) 
    event.emit("post", { name: 1212 }, "post") //注册post的监听

}, 1000);
setTimeout(() => {
    event.remove("name", function () {// 移除name的监听
        console.log("remove")
    })
}, 3000)
event.once("name", function (...res: any[]) { //注册监听只进入一次的回调
    console.log("once-name1", res) //res 是注册时的参数
})
event.on("name", function (...res: any[]) { //注册监听的回调
    console.log("on-name2", res)
})
event.on("post", function (...res: any[]) {//注册监听的回调
    console.log("on-post", res)

```

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