# sky-eventbus

> A 'eventbus' tool class based on TypeScript encapsulation, which is small in size and convenient for quick use

Latest version **1.0.2** (published 2023-03-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install sky-eventbus
pnpm add sky-eventbus
yarn add sky-eventbus
bun add sky-eventbus
```

## 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.2 |
| Published | 2023-03-23 |
| First published | 2023-03-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | bluebiubiu |
| Keywords | eventBus, small |

## Links

- npm: https://www.npmjs.com/package/sky-eventbus
- npm.io page: https://npm.io/package/sky-eventbus

## 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.2 (latest) — 2023-03-23
- 1.0.1 — 2023-03-23
- 1.0.0 — 2023-03-23

## README

# EventBus
A 'eventbus' tool class based on TypeScript encapsulation, which is small in size and convenient for quick use

一个基于TypeScript封装的 `eventbus`(事件总线) 工具类，体积小，方便快速使用

## 如何使用呢？(How to use it?)

### 1、npm安装依赖(to install)

```shell
npm install sky-eventbus
```

### 2、使用(reference)

- 导入

```shell
import EventBus from 'sky-eventbus'
```

- 监听
```ts
/*
  eventName 监听事件的名称
  cb 监听的回调函数
*/
EventBus.on("eventName", cb)
EventBus.once("eventName", cb) // 只监听一次
```

- 取消监听

```ts
/*
  eventName 取消监听的事件名称
  cb 取消监听的回调函数
*/
 EventBus.off("eventName", cb)
```

- 发送事件

```ts
/*
  eventName 发送事件的名称
  args 发送事件携带的数据
*/
 const args = ['sky', 'test']
 EventBus.emit("eventName", ...args)
```

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