# @dojoengine/recs 中文文档

规范地址：https://npmcn.com/package/%40dojoengine/recs/

版本：2\.1\.0
npm 元数据更新时间：2026-07-11T01:48:10.002Z
中文译文更新时间：2026-11-12T15:18:43.708Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40dojoengine/recs
原文对照：https://npmcn.com/package/%40dojoengine/recs/?lang=original
项目主页：https://github.com/dojoengine/mud/tree/main/packages/recs#readme
源码仓库：https://github.com/dojoengine/mud

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

- 包体积（解压后）：273 kB，12 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- 运行依赖：4 个
- 首次发布：2023-11-07T07:49:16.328Z
- 最新版本发布：2026-04-22T08:05:15.193Z
- 近 30 天下载量：4107（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：4（近 12 个月 1 个）

## 中文简介

`recs` 以反应为心. `Components` 财务报告和审定财务报表 `Queries` 曝光一个 `update$` 溪流,该 `Systems` 可以作出反应.

## 安装

```sh
npm install @dojoengine/recs
```

也可以使用：`pnpm add @dojoengine/recs`、`yarn add @dojoengine/recs`、`bun add @dojoengine/recs`

## README

# dros - 反应实体组件系统

`recs` 以反应为心. `Components` 财务报告和审定财务报表 `Queries` 曝光一个 `update$` 溪流,该 `Systems` 可以作出反应.

要建立一些基本的直觉 关于ECS,看看 [我们的MUD ECS介绍](https://mud.dev/blog/ecs)。 。 。 .

`recs` 与其他 MUD 库无缝地融合,但可以独立使用.

详细文件请查看 [泥浆. dev/雷克](https://mud.dev/recs)。 。 。 .

# 特征

-   反应组件、查询和系统
-   强大的查询,包括高级间接关系查询
-   与其他大学和大学部图书馆和服务无缝融合
-   简单、声明性 API
-   超高性能
-   类型脚本支持

# 示例

```typescript
import {
  createWorld,
  defineComponent,
  createEntity,
  withValue,
  defineSystem,
  Has,
  getComponentValue,
  setComponent,
} from "@latticexyz/recs";

// Create a new World
const World = createWorld();

// Define a couple components
const Position = defineComponent(world, { x: Type.Number, y: Type.Number });
const Movable = defineComponent(world, { speed: Type.Number });

// Create a new entity
const entity1 = createEntity(world, [withValue(Position, { x: 0, y: 0 }), withValue(Movable, { speed: 10 })]);

// Define a system that reacts to updates of movable entities with a position
defineSystem(world, [Has(Position), Has(Movable)], (update) => {
  console.log("Entity", update.entity, "moved to", update.value);
  // ... do stuff, like rendering the entity on the screen, etc
});

// Move the entity around
setInterval(() => {
  const currentPosition = getComponentValue(Position, entity1);
  const newPosition = { x: position.x + 1, y: position.y + 1 };
  setComponent(Position, entity1, newPosition);
}, 1000);
```

# 鸣谢

-   语法原由 [位点ECS](https://github.com/NateTheGreatt/bitECS)

## 常见问题

### @dojoengine/recs 是什么？

recs 以反应为心\. Components 财务报告和审定财务报表 Queries 曝光一个 update$ 溪流,该 Systems 可以作出反应\.

### 如何安装 @dojoengine/recs？

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

### @dojoengine/recs 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/dojoengine\_\_recs 是否存在。

### @dojoengine/recs 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @dojoengine/recs 可以商用吗？

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

### @dojoengine/recs 的下载量有多少？

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

### @dojoengine/recs 还在维护吗？

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

