@dojoengine/recs

中文文档
2.1.0发布于 2026/04/22MITES Module近 30 天下载 4107

recs is built with reactivity in mind. Components and Queries expose an update$ stream, that Systems can react to.

原始使用文档

recs - Reactive Entity Component System

recs is built with reactivity in mind. Components and Queries expose an update$ stream, that Systems can react to.

To build some fundamental intuition about ECS, have a look at our MUD ECS introduction.

recs is seamlessly integrated with the other MUD libraries, but can be used independently.

For detailed documentation, check out mud.dev/recs.

Features

  • Reactive components, queries, and systems
  • Powerful queries, including advanced indirect relationship queries
  • Seamless integration with other MUD libraries and services
  • Simple, declarative API
  • Ultra high performance
  • TypeScript support

Example

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);

Acknowledgements

  • Syntax originally inspired by bitECS

版本与发布记录

@dojoengine/recs 共发布 4 个版本,首次发布于 2023/11/07;过去 12 个月发布了 1 个版本。

版本发布日期距今
2.1.0latest2026/04/226 个月前
2.0.132024/06/202 年前
2.0.122024/06/202 年前
0.1.352023/11/073 年前

关于 @dojoengine/recs 的常见问题

@dojoengine/recs 是什么?

recs is built with reactivity in mind. Components and Queries expose an update$ stream, that Systems can react to.

如何安装 @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 和提交记录判断。