# @arction/eventer 中文文档

规范地址：https://npmcn.com/package/%40arction/eventer/

版本：1\.0\.2
npm 元数据更新时间：2024-02-09T09:46:14.930Z
中文译文更新时间：2026-11-06T18:00:57.540Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40arction/eventer
原文对照：https://npmcn.com/package/%40arction/eventer/?lang=original
项目主页：https://github.com/Arction/Eventer#README
源码仓库：https://github.com/Arction/Eventer

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：70.6 kB，11 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2019-07-04T12:43:09.841Z
- 最新版本发布：2022-09-21T06:18:44.495Z
- 近 30 天下载量：10224（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：3（近 12 个月 0 个）

## 中文简介

简单而快的事件发射器.

## 安装

```sh
npm install @arction/eventer
```

也可以使用：`pnpm add @arction/eventer`、`yarn add @arction/eventer`、`bun add @arction/eventer`

## README

# 偶数

简单快活事件发送库. 订阅基于一个独特的Token,可用于不订阅这个话题.

Eventer 用于闪电图® 联合来文图书馆. [https://www.arction.com/ (中文(简体) )](https://www.arction.com/)

## 安装

`npm install --save @arction/eventer`

## 文档

在线文件可上网查阅 [arction.github.io/eventer (英语)](https://arction.github.io/Eventer/)

## 开始

```ts
import { Eventer } from '@arction/eventer'

const eventer = new Eventer()

// new topic is created, handler is added as the first subscriber to the topic
const token1 = eventer.on('topic1', () => console.log('I am called from topic1'))
// 'topic1' already exists, so new listener is simply added to existing collection of handlers
const token2 = eventer.on('topic1', () => console.log('I am also called from topic1'))
// new collection of handlers is created for the second topic
// the function is added to it
eventer.on('topic2', () => console.log('I am called from topic2'))

eventer.emit('topic1')
// calls two functions which listen to the event
//
// outputs:
//    I am called from topic1
//    I am also called from topic1

eventer.emit('topic2')
// calls single functions which listen to the event
//
// outputs:
//    I am called from topic2

// remove the second listener from the first topic by token 
eventer.off(token2)

eventer.emit('topic1')
// calls single functions which listen to the event
//
// outputs:
//    I am called from topic1

// remove all listeners from all topics
eventer.allOff()

eventer.emit('topic2')
// nothing happened, since all subscriptions were terminated
```

### 订阅主题

订阅一个主题很容易.

```ts
eventer.on('topic', ()=>{ console.log('Topic handler') })
```

单个话题的多订阅可以存在.

```ts
eventer.on('topic', ()=>{ console.log('Topic handler') })
eventer.on('topic2', ()=>{ console.log('Topic 2 handler') })
eventer.on('topic3', ()=>{ console.log('Topic 3 handler') })
```

### 从主题取消订阅

您可以使用 _脚本_ 当您订阅话题时, 由事件器返回 .

```ts
const token = eventer.on('topic', ()=>{ console.log('Topic handler') })

eventer.off(token)
```

您也可以从话题中解密所有听众 .

```ts
eventer.topicOff('topic')
```

还有可能取消所有话题和所有听众的订阅.

```ts
eventer.allOff()
```

### 发生事件

事件可以针对一个话题发布. 发音可以包含0个或更多个会提供给话题听众的参数.

```ts
eventer.emit('topic')

eventer.on('topic2', ( arg1, arg2 ) => console.log( arg1, arg2 ))

eventer.emit('topic2', 'Hello ', 'World')
```

## 发展指示

该项目使用TypeScript开发. 项目的构建系统严重依赖于Node.js. 依赖性由 _无_因此,记住运行 **npm 安装** 在开始其他事情之前.

有几个 _npm 脚本_,用于发展进程:

| 名称 | 命令 | 说明 |
| --- | --- | --- |
| 构建 | npm 运行构建 | 运行构建系统 |
| 测试 | npm 测试 | 运行测试和监视 |
| 线性 | npm 运行 lint | 运行静态分析器和监视 |
| 文档 | npm 运行文件 | 生成类型文档 |
| ci:测试 | npm 运行 ci: test | 运行一次测试 |
| 坐标:lint | npm 运行 ci:lint | 运行一次静态分析器 |
| ci:观察 | npm 运行 ci: watch | 运行 CI 圆并监视 |

## 常见问题

### @arction/eventer 是什么？

简单而快的事件发射器\.

### 如何安装 @arction/eventer？

在项目目录运行 npm install @arction/eventer，或使用 pnpm add / yarn add / bun add。

### @arction/eventer 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @arction/eventer 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @arction/eventer 可以商用吗？

@arction/eventer 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @arction/eventer 的下载量有多少？

根据 npm 官方下载统计，@arction/eventer 在 2026/10/07 – 2026/11/05 这 30 天内被下载 10,224 次，日均约 341 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @arction/eventer 还在维护吗？

最新版本 1\.0\.2 发布于 2022/09/21（4 年前）；至今共发布 3 个版本，其中过去 12 个月发布了 0 个；首次发布于 2019/07/04。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

