# ray-eventpool

> event pool

Latest version **1.0.3** (published 2024-10-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install ray-eventpool
pnpm add ray-eventpool
yarn add ray-eventpool
bun add ray-eventpool
```

## 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.3 |
| Published | 2024-10-21 |
| First published | 2021-06-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ilex |
| Maintainers | ilex.h |

## Links

- npm: https://www.npmjs.com/package/ray-eventpool
- npm.io page: https://npm.io/package/ray-eventpool

## Recent versions

- 1.0.3 (latest) — 2024-10-21
- 1.0.2 — 2021-06-13
- 1.0.1 — 2021-06-13
- 1.0.0 — 2021-06-13

## README

# eventpool

  事件总线处理器

## basic eventpool

```js

import { EventPool } from 'ray-eventpool';

// 监听事件
EventPool.bind('myEvent5', function(event, args, fn) {
  alert('Publish Message 4th Times with args : ' + args);
  fn(args);
});

// 触发事件
function pubshMsg(){
  EventPool.trigger("myEvent5", [ "hello", function(args){
    alert(args);
  }]);
}

```

## basic EventPubSub

* `subscribe 同 bind` 监听事件
* `unsubscribe 同 unbind` 取消监听
* `one` 绑定一次事件
* `publish 同 trigger` 触发事件
* `publishHandler 同 triggerHandler` 触发事件名称

```js

import { EventPubSub } from 'ray-eventpool';

// 监听事件
EventPubSub.bind('myEvent5', function(event, args, fn) {
  alert('Publish Message 4th Times with args : ' + args);
  fn(args);
});

// 触发事件
function pubshMsg(){
  EventPubSub.trigger("myEvent5", [ "hello", function(args){
    alert(args);
  }]);
}

```

## PubSub

```js
import { PubSub } from 'ray-eventpool';

// 监听
PubSub.subscribe('HELLO', function(topic, data){
  // data
  console.log(data);
});

PubSub.publish('HELLO', '你好!')

// name space
PubSub.publish('HELLO.ray', 'ray 你好!');
PubSub.publish('HELLO.ilex', 'ilex 你好!');

PubSub.subscribe('HELLO', function(topic, data){
  // ray 你好！
  // ilex 你好!
  console.log(data);//
});
```

## EventEjector

```js
import { EventEjector } from 'ray-eventpool';

const ee = new EventEjector();
ee.on('message', function (text) {
  console.log(text)
});
ee.emit('message', 'hello world');
```

> 也可以直接使用 nodejs 内置的 `events` 模块、`eventemitter or event-emitter` 模块

## IHub

通过 `new IHub()` 创建一个 hub 实例，其中：

hub 提供 hub.event 和 hub.events。

hub.events 是将参数规范话处理，比如 handle的唯一性处理, args 的统一化处理。

建议只使用 `hub.events` 进行事件分发

```js
import { IHub } from 'ray-eventpool';

// or
import { IHub } from 'ray-eventpool/lib/eventHub';

const hub = new IHub();



hub.events.on('message', function (text) {
  console.log(text)
});

hub.events.emit('message', 'hello world');
```

> 也可以直接使用 nodejs 内置的 `events` 模块、`eventemitter or event-emitter` 模块

## changelog

### 2024-10-21 v1.0.3

fix `IHub` bugs

### 2021-05-10 v1.0.2

add `event hub`

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