# xiao-you-bus

> 轻便小巧的发布订阅库，适用于框架中的任意组件通讯

Latest version **1.0.4** (published 2023-03-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install xiao-you-bus
pnpm add xiao-you-bus
yarn add xiao-you-bus
bun add xiao-you-bus
```

## 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.4 |
| Published | 2023-03-12 |
| First published | 2022-03-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | 微若蜉蝣 |
| Maintainers | fzd2383155523 |
| Keywords | xiao, xiao-you, bus, event, event-bus, 微若蜉蝣 |

## Links

- npm: https://www.npmjs.com/package/xiao-you-bus
- npm.io page: https://npm.io/package/xiao-you-bus

## Dependencies (2)

- [json-loader](https://npm.io/package/json-loader.md) ^0.5.7
- [xiao-you-bus](https://npm.io/package/xiao-you-bus.md) ^1.0.3

## 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.4 (latest) — 2023-03-12
- 1.0.3 — 2022-04-14
- 1.0.2 — 2022-03-09
- 1.0.1 — 2022-03-07
- 1.0.0 — 2022-03-07

## README

# xiao-you-bus

> 适用于任意环境进行状态传递触发响应式

## Install

```shell
npm i xiao-you-bus
```

## Use

### javascript

```javascript
//像使用 vuex 一样创建一个文件夹 然后里面创建一个文件--> eventBus/index.js
import { createEventBus } from "xiao-you-bus"

const bus = createEventBus({
  name: "微若蜉蝣",
  age: 21,
})

export default bus
```

### typescript

```typescript
//像使用 vuex 一样创建一个文件夹 然后里面创建一个文件--> eventBus/index.ts
import { createEventBus } from "xiao-you-bus"

interface State {
  name: string
  age: number
}

const bus = createEventBus<State>({
  name: "微若蜉蝣",
  age: 21,
})

export default bus
```

```javascript
import bus from "@/eventBus"
//监听数据的改变
bus.on("name", data => {
  console.log("data:", data)
})
//以下两种方式都可以改变数据
//效果是一致的，就是API风格不同，自己喜爱哪种风格就用哪个即可
bus.commit("name", "小蝣")
//----------- or ------------
bus.state.name = "小蝣"
```

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